1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
# -*-Perl-*-
# instances allowed: one
# (single instance modules would be silly to use more than one of
# anyway, so we use package local storage. This is faster and places
# less artificial load on the machine than doing everything through
# the object hash)
# Cargo-cult coded from memuse
package MGMmodule::mgmrss;
use IO::Seekable;
use vars qw($xpath $widget $graph $mgmuse $memtotal $memuse $swapuse $bars);
sub module_init{
my$this=shift;
my$toplevel=$this->{"toplevel"};
my$xclass=$this->{"xclass"};
$this->get_mgmuse;
$this->get_memtotal;
unless ($memtotal && $mgmuse){
$toplevel->optionAdd("$xclass*active",'false',21);
}
$toplevel->optionAdd("$xclass.order", 101,21);
$this;
}
sub module_instance{
my$this=shift;
my$toplevel=$this->{"toplevel"};
return undef if(defined($xpath));
$xpath=$this->{"xpath"};
$toplevel->optionAdd("$xpath.bar.0.label", "mgm RSS",21);
$bars=1;
my($minx,$miny)=&MGM::Graph::calcxysize($this,100,'% used',$bars);
$toplevel->optionAdd("$xpath.minx", $minx,21);
$toplevel->optionAdd("$xpath.miny", $miny,21);
$toplevel->optionAdd("$xpath.scalewidadj", 80*$bars,21); # narrower, like memuse
$this;
}
sub module_run{
my$this=shift;
$graph=MGM::Graph->new($this,num=>$bars,prompt=>'%',fixed=>1,
rangesetting=>100,rangecurrent=>100);
$widget=$graph->{"widget"}; # must return the widget
}
sub module_update{
my$this=shift;
$this->get_mgmuse;
$graph->set(100 * ($mgmuse/$memtotal));
}
sub get_mgmuse{
if(open(PROC,"/proc/self/status")){
while(<PROC>) {
if (m/VmRSS:\s+(\d+) kB/) {
$mgmuse = 1024 * $1;
}
}
close PROC;
}
}
sub get_memtotal{
if(open(PROC,"/proc/meminfo")){
<PROC>;
$_=<PROC>;
if(m/^Mem:\s+(\d+)\s+(\d+)\s+\d+\s+\d+\s+(\d+)\s+(\d+)/){
$memtotal=$1;
$memuse=$2-$3-$4;
}else{
$memtotal=0;
$memuse=0;
}
close PROC;
}
}
sub destroy{
undef $xpath;
}
bless {};
|