Win32::SystemInfo::CpuUsage - Perl extension for getting CPU Usage in percentage
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"; }
In windows, there is no tool for querying CPU usage and print it in DOS prompt.
Win32::SystemInfo::CpuUsage is designed for monitoring CPU usage and return the value in percentage. To calculate the percentage, it needs an interval of twice retrieving CPU info.
Get CPU's Usage in Percentage
Args: $intvl interval for getting CPU info. 1000 means 1 second
Returns CPU's usage in percentage
The returned CPU usage number doesn't match the number exactly shown in task manager, because of the interval setting and CPU query timing. But the numbers can be very close after tuning.
Jing Kang <kxj@hotmail.com>
To install Win32::SystemInfo::CpuUsage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::SystemInfo::CpuUsage
CPAN shell
perl -MCPAN -e shell install Win32::SystemInfo::CpuUsage
For more information on module installation, please visit the detailed CPAN module installation guide.