[xiph-cvs] cvs commit: mgm/modules/linux cpustat
Monty
xiphmont at xiph.org
Tue Feb 19 16:50:32 PST 2002
xiphmont 02/02/19 16:50:32
Modified: modules/linux cpustat
Log:
/proc/cpuinfo changed format gratuitously under PPC sometime after
2.4.10 (why eliminate the processor number field for no good fucking
reason on non-SMP machines?) Fix the parsing in cpustat.
Monty
Revision Changes Path
1.7 +18 -2 mgm/modules/linux/cpustat
Index: cpustat
===================================================================
RCS file: /usr/local/cvsroot/mgm/modules/linux/cpustat,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- cpustat 1999/09/28 20:23:19 1.6
+++ cpustat 2002/02/20 00:50:31 1.7
@@ -21,15 +21,27 @@
# at least want to mark the single bar as SMP under 2.0
$lastmod=-1;
- $numcpus=0;
+ $numcpus=1;
$statcpus=1;
+ my $countedcpus=0;
+
if(defined($MGMmodule::helperST::proc{"cpu"}) &&
open(PROC,"</proc/cpuinfo")){
+
+ # in the middle of stable &*@%^@ 2.4, the format of /proc/cpu
+ # changed for NO GOOD FUCKING REASON, at least on PPC. Take a
+ # reasonable stab at reading both.
+
while(<PROC>){
if(m/processor\s*:\s*(\d*)/){
$numcpus=$1+1 if ($numcpus<$1+1);
}
+ if(m/cpu\S*\s*:/){
+ $countedcpus++;
+ }
}
+ $numcpus=$countedcpus if ($numcpus<$countedcpus);
+
close PROC;
# now check /proc/stat to see how many cpus it reports
$this->read_proc;
@@ -99,6 +111,7 @@
if($statcpus==1){
my$tot=$total[0]-$prevtotal[0];
+
if($tot>0){
$vals[0]=100*($load[0]-$prevload[0])/$tot;
$vals[0]=100*$numcpus if $vals[0]>100*$numcpus;
@@ -116,6 +129,7 @@
}
}
}
+
$graph->set(@vals);
}
@@ -132,9 +146,10 @@
# collective cpu entry
$MGMmodule::helperST::proc{"cpu"}=~m/^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
+
$load[0]=$1+$2+$3;
$total[0]=$load[0]+$4;
-
+
for(my$i=0;defined(my$line=$MGMmodule::helperST::proc{"cpu$i"});$i++){
$line=~m/^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
# per-cpu entry
@@ -148,4 +163,5 @@
}
bless {};
+
<p><p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list