Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / system / memory_by_process @ d0216f00

Historique | Voir | Annoter | Télécharger (1,81 ko)

1
#!/bin/sh
2
#
3
# Copyright (C) 2006 Holger Levsen
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; version 2 dated June,
8
# 1991.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
#
19

    
20
if [ "$1" = "config" ]; then
21
	echo "graph_title VM by Process"
22
	echo 'graph_args --base 1024k'
23
	echo 'graph_vlabel VM size'
24
	echo 'graph_category system'
25
	echo "graph_info Shows contribution of each process to VM size"
26

    
27
	ps auxww | perl -e '
28
		$junk = <>;
29
		while (<>)
30
		{
31
			@a = split;
32
			$proc = $a[10];
33
			$label = $proc;
34
			$proc =~ s/ .*//;
35
			if($proc =~ /^\[/) { $proc =~ s|/.*||; } else { $proc =~ s|.*/||; }
36
			$proc =~ s/:.*//;
37
			$proc =~ tr/[]//d;
38
			$proc =~ tr/A-Za-z0-9/_/c;
39
			$vsz = $a[4];
40
			$total{$proc} += $vsz;
41
			$labels{$proc} = $label;
42
		}
43
		my $stack = 0;
44
		sub draw() { return $stack++ ? "STACK" : "AREA" }
45
		print map
46
		{
47
			"$_.label " . $labels{$_} . "\n" .
48
			"$_.min 0\n" .
49
			"$_.draw " . draw() . "\n" .
50
			"$_.cdef $_,1024,*\n"
51
		}
52
		sort keys %total;
53
		'
54
	exit 0
55
else
56
	ps auxww | perl -e '
57
		$junk = <>;
58
		while (<>)
59
		{
60
			@a = split;
61
			$proc = $a[10];
62
			if($proc =~ /^\[/) { $proc =~ s|/.*||; } else { $proc =~ s|.*/||; }
63
			$proc =~ s/:.*//;
64
			$proc =~ tr/[]//d;
65
			$proc =~ tr/A-Za-z0-9/_/c;
66
			$vsz = $a[4];
67
			$total{$proc} += $vsz;
68
		}
69
		print map {"$_.value $total{$_}\n"} sort keys %total'
70
fi