
Amitk
Novice
Feb 16, 2013, 1:51 AM
Post #1 of 8
(33615 views)
|
calculating CPU Utilization on Windows and unix machine
|
Can't Post
|
|
Dear All, I am new to perl programming, i want to create the script for cpu utilization of local system. I serached through the internet and found some useful information. Copy pasting the scripts for the reference use Win32::SystemInfo::CpuUsage; my $intvl = 1000; # in milliseconds my $usage = Win32::SystemInfo::CpuUsage::getCpuUsage($intvl); my $i = 0; while($i < 5){ #query 5 times $i++; $usage = Win32::SystemInfo::CpuUsage::getCpuUsage($intvl); print "$i: cpu usage $usage\n"; } while running this script I am getting below errors C:\Perl\bin>perl CpuUsage1.pl Can't locate Win32/API/Prototype.pm in @INC (@INC contains: C:/Perl/site/lib C:/ Perl/lib .) at CpuUsage1.pl line 3. BEGIN failed--compilation aborted at CpuUsage1.pl line 3. There is another script i found as below use strict; use Win32::API::Prototype; ApiLink( 'kernel32', q[ BOOL GetSystemTimes( LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime ) ]) or die $^E; sub SystemTimes { my( $idleTicks, $kernelTicks, $userTicks ) =( chr( 0 ) x 8 ) x 3; GetSystemTimes( $idleTicks, $kernelTicks, $userTicks ) or die $^E; return map{ my( $lo, $hi ) = unpack 'VV', $_; ( $hi * 2**32 + $lo ); } $idleTicks, $kernelTicks, $userTicks;} use constant { IDLE=>0, KERNEL=>1, USER=>2 };$|=1; my @last = SystemTimes; while( sleep 1 ) { my @now = SystemTimes; my @deltas = map{ $now[ $_ ] - $last[ $_ ] } IDLE, KERNEL, USER; my $busy = $deltas[ KERNEL ] + $deltas[ USER ]; my $pcUsage = ( $busy - $deltas[ IDLE ] )* 100 /( $deltas[ IDLE ] || 100e5 ); printf "\rCPU usage(%%): %6.3f ", $pcUsage; @last = @now;} for this i am getting below error C:\Perl\bin>perl CpuUsage1.pl Can't locate Win32/API/Prototype.pm in @INC (@INC contains: C:/Perl/site/lib C:/ Perl/lib .) at CpuUsage1.pl line 3. BEGIN failed--compilation aborted at CpuUsage1.pl line 3. Can some one help me to sort this out or of there is any easy to find out the cpuutilization please suggest. Thanks Amit
|