[xiph-commits] r9077 - trunk/mgm/modules/linux

xiphmont at motherfish-iii.xiph.org xiphmont at motherfish-iii.xiph.org
Tue Mar 15 11:59:58 PST 2005


Author: xiphmont
Date: 2005-03-15 11:59:56 -0800 (Tue, 15 Mar 2005)
New Revision: 9077

Modified:
   trunk/mgm/modules/linux/00helper
   trunk/mgm/modules/linux/diskstat
   trunk/mgm/modules/linux/pagestat
   trunk/mgm/modules/linux/swapstat
Log:
Retool the stat helper with 2.6 in mind; most of the centralized
information in /proc/stat has been broken out into other files.

Should not break anything in 2.2/2.4, but I won't be able to test that
until getting home.

All the Linux plugins should work properly in 2.6 now.



Modified: trunk/mgm/modules/linux/00helper
===================================================================
--- trunk/mgm/modules/linux/00helper	2005-03-15 05:18:02 UTC (rev 9076)
+++ trunk/mgm/modules/linux/00helper	2005-03-15 19:59:56 UTC (rev 9077)
@@ -12,7 +12,7 @@
 
 
 package MGMmodule::helperST;
-use vars qw(%proc %net %wi $lastmod $active $active_if $wi_count $wi_active);
+use vars qw(%disk26 %vm26 %proc %net %wi $lastmod $stat_active $net_active $active_if $wi_count $wi_active $vm_active $disk26_active);
 use IO::Seekable;
 
 sub module_init{
@@ -25,18 +25,33 @@
     my$refresh=$widget->optionGet("scalerefresh","");
     
     $lastmod=0;
-    $active=0;
+    $stat_active=0;
+    $net_active=0;
+    $vm_active=0;
+    $disk26_active=0;
     $wi_active=0;
     if(open(PROC,"/proc/stat")){
-	if(open(WI,"/proc/net/wireless")){
-	    $wi_active=1;
-	}
-	if(open(NET,"/proc/net/dev")){
-	    $active=1;
-	    $this->module_update;
-	    $toplevel->repeat($refresh,\&module_update)if(defined(%proc));
-	}
+	$stat_active=1;
     }
+    if(open(WI,"/proc/net/wireless")){
+	$wi_active=1;
+    }
+    if(open(NET,"/proc/net/dev")){
+	$net_active=1;
+    }
+    if(open(VM,"/proc/vmstat")){
+	$vm_active=1;
+    }
+    if(open(DISK,"/proc/diskstats")){
+	# ...2.6 moves these out of /proc/stat
+	$disk26_active=1;
+    }
+
+    if($stat_active || $wi_active || $net_active || $disk26_active || $vm_active){
+	$this->module_update;
+	$toplevel->repeat($refresh,\&module_update)if(defined(%proc));
+    }
+
     $toplevel->optionAdd("$xclass.active",0,21);
     $this;
 }
@@ -47,15 +62,27 @@
 
 sub module_update{
     my$data;
-    my$netd;
-    my$wid;
-    sysseek PROC, 0, SEEK_SET;
-    sysseek NET, 0, SEEK_SET;
-    sysread NET,$netd,1024;
-    sysread PROC,$data,4096;
+
+    if($net_active){
+	$active_if=0;
+	undef%net;
+	sysseek NET, 0, SEEK_SET;
+	sysread NET,$data,1024;
+
+	map{
+	    my$pos=rindex $_, ":";
+	    if($pos>0){
+		my$key=substr $_,0,$pos;
+		$key=~s/^\s*(\S+)\s*/$1/;
+		$net{$key}=substr $_, $pos+1;
+		$active_if++;
+	    }
+	} split "\n", $data;
+    }
+
     if($wi_active){
 	sysseek WI, 0, SEEK_SET;
-	sysread WI,$wid,4096;
+	sysread WI,$data,4096;
 	$wi_count=0;
 	undef %wi;
 	map{
@@ -66,26 +93,41 @@
 		$wi{$key}=substr $_, $pos+1;
 		$wi_count++;
 	    }
-	} split "\n", $wid;
+	} split "\n", $data;
     }
 	
-    $active_if=0;
-    undef%net;
-    map{
-	my$pos=rindex $_, ":";
-	if($pos>0){
-	    my$key=substr $_,0,$pos;
-	    $key=~s/^\s*(\S+)\s*/$1/;
-	    $net{$key}=substr $_, $pos+1;
-	    $active_if++;
-	}
-    } split "\n", $netd;
+    if($stat_active){
+	sysseek PROC, 0, SEEK_SET;
+	sysread PROC,$data,4096;
+	
+	map{
+	    m/^(\S+)\s+(.*)/;
+	    $proc{$1}=$2;
+	} split "\n", $data;
+	
+    }
 
-    map{
-	m/^(\S+)\s+(.*)/;
-	$proc{$1}=$2;
-    } split "\n", $data;
+    if($disk26_active){
+	sysseek DISK, 0, SEEK_SET;
+	sysread DISK,$data,4096;
+	undef %disk26;
+	map{
+	    m/\d+\s+\d+\s+(\S+)\s+(.*)/;
+	    $disk26{$1}=$2;
+	} split "\n", $data;
+	
+    }
 
+    if($vm_active){
+	sysseek VM, 0, SEEK_SET;
+	sysread VM,$data,4096;
+	map{
+	    m/^(\S+)\s+(.*)/;
+	    $vm26{$1}=$2;
+	} split "\n", $data;
+    }
+
+
     # what a great hack
     $proc{"cpu"}=~m/(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
     $lastmod=$1+$2+$3+$4; # 100ths of a second, even with 'broken' 2.0 SMP proc

Modified: trunk/mgm/modules/linux/diskstat
===================================================================
--- trunk/mgm/modules/linux/diskstat	2005-03-15 05:18:02 UTC (rev 9076)
+++ trunk/mgm/modules/linux/diskstat	2005-03-15 19:59:56 UTC (rev 9077)
@@ -13,7 +13,8 @@
 
 package MGMmodule::diskstat;
 use vars qw($xpath @rsectors @wsectors @prevr @prevw $widget $graph 
-	    $numdisks $lastmod $kernel);
+	    $numdisks $lastdisks $lastmod $kernel @disknames);
+use IO::Seekable;
 
 # class init
 sub module_init{
@@ -34,12 +35,16 @@
 	$kernel=4;$this->read_proc;
     } 
 
-    map{$numdisks++ if ($rsectors[$_] || $wsectors[$_])}(0..$#rsectors);
+    # 2.6
+    if(defined(%MGMmodule::helperST::disk26)){
+	$kernel=6;$this->read_proc;
+    } 
 
     if(!$numdisks){
 	$toplevel->optionAdd("$xclass.active",'false',21);   
     } 
     $toplevel->optionAdd("$xclass.order",10,21);   
+    $lastdisks=$numdisks;
     $this;
 }
 
@@ -53,14 +58,15 @@
     # modify defaults
     for(my$i=0;$i<$numdisks;$i++){
 	$toplevel->optionAdd("$xpath.bar.".($i*2).".label", 
-			     "disk$i read",21);
+			     "$disknames[$i] read",21);
 	$toplevel->optionAdd("$xpath.bar.".($i*2+1).".label", 
-			     "disk$i write",21);
+			     "$disknames[$i] write",21);
 	$toplevel->optionAdd("$xpath.bar.".($i*2).".litbackground", 
 			     '#e7ad74',21);
 	$toplevel->optionAdd("$xpath.bar.".($i*2+1).".litbackground", 
 			     '#ade774',21);
     }
+
     $toplevel->optionAdd("$xpath.scalewidadj", 160*$numdisks,21);  # narrower
     $toplevel->optionAdd("$xpath.scalereturn", 120,21);
     # this relies on the above defaults
@@ -86,22 +92,59 @@
 }
 
 sub read_proc{
-    # now uses the 00helper to save on opens 
-    if($kernel==4){
-	my $disk;
-	my at disks=split ' ',$MGMmodule::helperST::proc{"disk_io:"};
-	my$i=0;
+    if($kernel==6){ #2.6-ish
 	undef @rsectors;
 	undef @wsectors;
-	foreach $disk (@disks){
-	    $disk=~m/\(\d+,\d+\):\(\d+,\d+,(\d+),\d+,(\d+)\)/;
-	    $rsectors[$i]=$1;
-	    $wsectors[$i]=$2;
-	    $i++;
+	$numdisks=0;
+	foreach my $key (sort(keys %MGMmodule::helperST::disk26)){
+	    
+	    # if there are per-parition stats available, skip the whole-disk entries
+	    if($key=~m/^[^0-9]+$/){
+		if(defined($MGMmodule::helperST::disk26{"$key"."1"})){
+		    next;
+		}
+	    }
+	    
+	    if($MGMmodule::helperST::disk26{$key}=~m/\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+(\d+)/ ||
+	       $MGMmodule::helperST::disk26{$key}=~m/\d+\s+(\d+)\s+\d+\s+(\d+)/){
+	    
+		# if this entry is as-yet unused, ignore it
+		next if($1==0 && $2==0);
+		
+		$rsectors[$numdisks]=$1;
+		$wsectors[$numdisks]=$2;
+		$disknames[$numdisks]=$key;
+		$numdisks++;
+	    }
 	}
+
     }else{
-	@rsectors=split ' ',$MGMmodule::helperST::proc{"disk_rblk"};
-	@wsectors=split ' ',$MGMmodule::helperST::proc{"disk_wblk"};
+	# now uses the 00helper to save on opens
+	if($kernel==4){ #2.4-ish
+	    my $disk;
+	    my at disks=split ' ',$MGMmodule::helperST::proc{"disk_io:"};
+	    
+	    $numdisks=0;
+	    undef @rsectors;
+	    undef @wsectors;
+	    foreach $disk (@disks){
+		$disk=~m/\(\d+,\d+\):\(\d+,\d+,(\d+),\d+,(\d+)\)/;
+		if ($1 || $2){
+		    $rsectors[$numdisks]=$1;
+		    $wsectors[$numdisks]=$2;
+		    $disknames[$numdisks]="disk$numdisks";
+		    $numdisks++;
+		}
+	    }
+	}else{ #2.0/2.2-ish
+	    my at A=split ' ',$MGMmodule::helperST::proc{"disk_rblk"};
+	    my at B=split ' ',$MGMmodule::helperST::proc{"disk_wblk"};
+	    $numdisks=0;
+	    map{if ($A[$_] || $B[$_]){$rsectors[$numdisks]=$A[$_];
+				      $wsectors[$numdisks]=$B[$_];
+				      $disknames[$numdisks]="disk$numdisks";
+				  }}(0..$#A);
+	}
     }
 }
 
@@ -113,7 +156,8 @@
 	my$time=$MGMmodule::helperST::lastmod;
 	$this->read_proc;
 
-	return &reconfig if($numdisks-1 != $#rsectors);
+	return &reconfig if($numdisks != $lastdisks);
+	$lastdisks=$numdisks;
 
 	if(defined(@prevr)){
 	    my @vals;
@@ -140,7 +184,7 @@
 }
 
 sub reconfig{
-    $numdisks= $#rsectors+1;
+    $lastdisks=$numdisks;
     @prevr=@rsectors;
     @prevw=@wsectors;
     &main::reinstance() if($widget->optionGet("reconfig","") eq 'true');

Modified: trunk/mgm/modules/linux/pagestat
===================================================================
--- trunk/mgm/modules/linux/pagestat	2005-03-15 05:18:02 UTC (rev 9076)
+++ trunk/mgm/modules/linux/pagestat	2005-03-15 19:59:56 UTC (rev 9077)
@@ -8,7 +8,7 @@
 # the object hash)
 
 package MGMmodule::pagestat;
-use vars qw($xpath $pagei $pageo $previ $prevo $widget $graph $lastmod);
+use vars qw($xpath $pagei $pageo $previ $prevo $widget $graph $lastmod $kernel $active);
 
 # class init
 sub module_init{
@@ -16,10 +16,23 @@
     my$toplevel=$this->{"toplevel"};
     my$xclass=$this->{"xclass"};
 
-    # is the helper up and running?
-    if(!defined($MGMmodule::helperST::proc{"swap"})){
+    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{"page"})){
+	    $active=1;
+	}
+    }
+
+    if(!$active){
 	$toplevel->optionAdd("$xclass.active",'false',21);   
+	$MGMmodule::helperST::vm_active=0;
     } 
+
     $toplevel->optionAdd("$xclass.order",12,21);   
     $this;
 }
@@ -47,7 +60,7 @@
     # this relies on the above defaults
 
     my($minx,$miny)=MGM::Graph::calcxysize($this,1024*1024*512,
-					   ' pages/s',2);
+					   'b/s',2);
     
     $toplevel->optionAdd("$xpath.minx",        $minx,21);      
     $toplevel->optionAdd("$xpath.miny",        $miny,21);      
@@ -59,7 +72,7 @@
     my$this=shift;
     
     $graph=MGM::Graph->new($this,num=>2,
-			   prompt=>' pages/s',
+			   prompt=>'b/s',
 			   minscale=>128);
 
     $lastmod=-1;
@@ -67,8 +80,14 @@
 }
 
 sub read_proc{
-    # now uses the 00helper to save on opens 
-    ($pagei,$pageo)=split ' ',$MGMmodule::helperST::proc{"page"};
+    
+    if(defined($MGMmodule::helperST::proc{"page"})){
+	# now uses the 00helper to save on opens 
+	($pagei,$pageo)=split ' ',$MGMmodule::helperST::proc{"page"};
+    }else{	
+	$pagei=$MGMmodule::helperST::vm26{"pgpgin"};
+	$pageo=$MGMmodule::helperST::vm26{"pgpgout"};
+    }
 }
 
 sub module_update{ 
@@ -80,8 +99,8 @@
 
 	$this->read_proc;
 	if(defined($previ)){
-	    my$r=($pagei-$previ)/($time-$lastmod)*100;
-	    my$w=($pageo-$prevo)/($time-$lastmod)*100;
+	    my$r=($pagei-$previ)/($time-$lastmod)*100*1024;
+	    my$w=($pageo-$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

Modified: trunk/mgm/modules/linux/swapstat
===================================================================
--- trunk/mgm/modules/linux/swapstat	2005-03-15 05:18:02 UTC (rev 9076)
+++ trunk/mgm/modules/linux/swapstat	2005-03-15 19:59:56 UTC (rev 9077)
@@ -8,7 +8,7 @@
 # the object hash)
 
 package MGMmodule::swapstat;
-use vars qw($xpath $pagei $pageo $previ $prevo $widget $graph $lastmod);
+use vars qw($xpath $swapi $swapo $previ $prevo $widget $graph $lastmod $kernel $active);
 
 # class init
 sub module_init{
@@ -16,11 +16,24 @@
     my$toplevel=$this->{"toplevel"};
     my$xclass=$this->{"xclass"};
 
-    # is the helper up and running?
-    if(!defined($MGMmodule::helperST::proc{"swap"})){
+    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",11,21);   
+
+    $toplevel->optionAdd("$xclass.order",12,21);   
     $this;
 }
 
@@ -47,7 +60,7 @@
     # this relies on the above defaults
 
     my($minx,$miny)=MGM::Graph::calcxysize($this,1024*1024*512,
-					   ' pages/s',2);
+					   'pages/s',2);
     
     $toplevel->optionAdd("$xpath.minx",        $minx,21);      
     $toplevel->optionAdd("$xpath.miny",        $miny,21);      
@@ -67,8 +80,14 @@
 }
 
 sub read_proc{
-    # now uses the 00helper to save on opens 
-    ($pagei,$pageo)=split ' ',$MGMmodule::helperST::proc{"swap"};
+    
+    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{ 
@@ -80,8 +99,8 @@
 
 	$this->read_proc;
 	if(defined($previ)){
-	    my$r=($pagei-$previ)/($time-$lastmod)*100;
-	    my$w=($pageo-$prevo)/($time-$lastmod)*100;
+	    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
@@ -90,8 +109,8 @@
 	    $graph->set($r,$w);
 	}
 	
-	$previ=$pagei;
-	$prevo=$pageo;
+	$previ=$swapi;
+	$prevo=$swapo;
 	$lastmod=$time;
     }
 }



More information about the commits mailing list