# -*-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) package MGMmodule::swapstat; use vars qw($xpath $swapi $swapo $previ $prevo $widget $graph $lastmod $kernel $active); # class init sub module_init{ my$this=shift; my$toplevel=$this->{"toplevel"}; my$xclass=$this->{"xclass"}; my$active=0; # 2.6-ish if(defined(%MGMmodule::helperST::vm26)){ $active=1; }else{ # else use the helper (2.4-ish) if(defined($MGMmodule::helperST::proc{"swap"})){ $active=1; } } if(!$active){ $toplevel->optionAdd("$xclass.active",'false',21); $MGMmodule::helperST::vm_active=0; } $toplevel->optionAdd("$xclass.order",12,21); $this; } # instance init sub module_instance{ my$this=shift; my$toplevel=$this->{"toplevel"}; return undef if(defined($xpath)); $xpath=$this->{"xpath"}; # modify defaults $toplevel->optionAdd("$xpath.bar.0.label", "swap in",21); $toplevel->optionAdd("$xpath.bar.1.label", "swap out",21); $toplevel->optionAdd("$xpath.bar.0.litbackground", '#e7ad74',21); $toplevel->optionAdd("$xpath.bar.1.litbackground", '#ade774',21); $toplevel->optionAdd("$xpath.scalewidadj", 160,21); # narrower $toplevel->optionAdd("$xpath.scalelenadj", 60,21); # shorter $toplevel->optionAdd("$xpath.scalereturn", 120,21); # this relies on the above defaults my($minx,$miny)=MGM::Graph::calcxysize($this,1024*1024*512, 'pages/s',2); $toplevel->optionAdd("$xpath.minx", $minx,21); $toplevel->optionAdd("$xpath.miny", $miny,21); $this; } # instance widget build sub module_run{ my$this=shift; $graph=MGM::Graph->new($this,num=>2, prompt=>' pages/s', minscale=>128); $lastmod=-1; $widget=$graph->{"widget"}; # must return the widget } sub read_proc{ if(defined($MGMmodule::helperST::proc{"swap"})){ # now uses the 00helper to save on opens ($swapi,$swapo)=split ' ',$MGMmodule::helperST::proc{"swap"}; }else{ $swapi=$MGMmodule::helperST::vm26{"pswpin"}; $swapo=$MGMmodule::helperST::vm26{"pswpout"}; } } sub module_update{ my$this=shift; # don't update unless the helper has if($lastmod!=$MGMmodule::helperST::lastmod){ my$time=$MGMmodule::helperST::lastmod; $this->read_proc; if(defined($previ)){ my$r=($swapi-$previ)/($time-$lastmod)*100*1024; my$w=($swapo-$prevo)/($time-$lastmod)*100*1024; # don't be clever and only call set if values change; set must # be called each refresh period or the graph will get # confused. $graph->set($r,$w); } $previ=$swapi; $prevo=$swapo; $lastmod=$time; } } sub destroy{ undef $xpath; } bless {};