# HG changeset patch # User Peter Gervai # Date 1237813703 -3600 # Node ID 068d0e1deb08d5f79e280004f0f3856353ea82dc # Parent efb595e3b0a2be8556892e53a43e0f0b72f2cf35 ovz_statshow: almost works now :) diff -r efb595e3b0a2 -r 068d0e1deb08 ovz_statshow.pl --- a/ovz_statshow.pl Mon Mar 23 13:26:48 2009 +0100 +++ b/ovz_statshow.pl Mon Mar 23 14:08:23 2009 +0100 @@ -11,19 +11,26 @@ my $f_stat = "/proc/vz/vestat"; my $stat_ver = "2.2"; +# jiffie per second ( zgrep ^CONFIG_HZ /proc/config.gz ) +my $jiffies = 100; -my $f = new IO::File "< $f_stat" or die $!; -my $l = <$f>; -if( $l !~ /Version: $stat_ver/ ) { - die "Unknown file version $l, required $stat_ver"; -} - -$l = <$f>; # headers my @fields = (1,2,3,4,5,7,8); -my %ve, %ve1; +my (%ve, %ve1); + +my $cpu_mhz = qx( egrep '^cpu MHz' /proc/cpuinfo | head -n1 | awk '{print \$4}' ); +chomp $cpu_mhz; +print "Running on $cpu_mhz MHz CPU(s)\n"; + while(1) { + my $f = new IO::File "< $f_stat" or die $!; + my $l = <$f>; + if( $l !~ /Version: $stat_ver/ ) { + die "Unknown file version $l, required $stat_ver"; + } + $l = <$f>; # headers + while( <$f> ) { chomp; my @d = split; @@ -36,12 +43,34 @@ if( defined( $ve1{$veid} ) ) { print "$veid: "; for my $field ( @fields ) { - print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field]; + #print "[$field,", $ve{$veid}, ",", $ve1{$veid} ,",", $ve{$veid}->[$field],",", $ve1{$veid}->[$field], "] "; + my $val = $ve{$veid}->[$field] - $ve1{$veid}->[$field]; + print "field="; + if( $field <6 ) { + print &jiffie2ms( $val ); + } else { + print &clock2ms( $val ); + } + print "; "; + if( $field == 7 ) { + print "<", &clock2ms( $val - ($ve{$veid}->[5] - $ve1{$veid}->[5]) ), "> "; + } } print "\n"; } - $ve1{$veid}->[$field] = $ve{$veid}->[$field]; + $ve1{$veid} = $ve{$veid}; } - + print "\n"; sleep(1); } + + +sub clock2ms ($) { + return int( (shift) / ( $cpu_mhz * $jiffies * $jiffies ) * 1000 ); +} + + +sub jiffie2ms ($) { + return int( (shift) / $jiffies * 1000 ); +} +