Jing Kang - 康 小靖

NAME

Win32::SystemInfo::CpuUsage - Perl extension for getting CPU Usage in percentage

SYNOPSIS

  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";
  }

DESCRIPTION

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.

METHODS

Win32::SystemInfo::CpuUsage::getCpuUsage($intvl)

Get CPU's Usage in Percentage

    Args:

        $intvl          interval for getting CPU info. 1000 means 1 second

Returns CPU's usage in percentage

SUMMARY

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.

AUTHOR

Jing Kang <kxj@hotmail.com>