Created
December 1, 2010 22:52
-
-
Save orimanabu/724396 to your computer and use it in GitHub Desktop.
get how much physical CPU resources really used from ppc64 Linux running on LPAR of Power Systems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# calcurate average physical CPU usage from Processor Utilization Resources Register, aka PURR. | |
# see URL below in detail. | |
# http://www.ibm.com/developerworks/wikis/display/LinuxP/Entries+in+the+proc+Filesystem | |
use strict; | |
use warnings; | |
$| = 1; | |
my $timebase; | |
my $fh; | |
my $interval = $ARGV[0]; | |
unless ($interval) { | |
print "./purr.pl interval\n"; | |
exit(1); | |
} | |
sub get_purr { | |
my $purr; | |
open $fh, "/proc/ppc64/lparcfg" or die; | |
while (<$fh>) { | |
next unless (/^purr=(\d+)$/); | |
$purr = $1; | |
} | |
close $fh; | |
chomp $purr; | |
return $purr; | |
} | |
open $fh, "/proc/cpuinfo" or die; | |
while (<$fh>) { | |
next unless (/^timebase\s+:\s+(\d+)$/); | |
$timebase = $1; | |
last; | |
} | |
chomp $timebase; | |
#print "timebase = $timebase\n"; | |
close $fh; | |
print <<END; | |
smt=On | |
physc | |
----- | |
END | |
my ($purr, $purr0, $delta); | |
while (1) { | |
$purr = get_purr; | |
if ($purr0) { | |
$delta = $purr - $purr0; | |
# print "$purr0\t$purr\t$delta\t$timebase\t$interval\t", sprintf("%.4f", $delta/$timebase/$interval), "\n"; | |
print sprintf("%.2f", $delta/$timebase/$interval), "\n"; | |
} | |
sleep $interval; | |
$purr0 = $purr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment