Win32::Process::CpuUsage - Perl extension for getting a Windows process's CPU usage
use Win32::Process::CpuUsage; ($pid, $interval, $counts) = (4800, 1000, 3); $rs = Win32::Process::CpuUsage::GetProcessCpuUsage($pid, $interval, $counts, $prcCPU, $sysCPU); $rs = Win32::Process::CpuUsage::GetPidCommandLine($pid, $str); $usage = Win32::Process::CpuUsage::GetSystemCpuUsage($interval);
This module is designed to constantly monitor a Windows process's CPU usage and system CPU usage. And it has some merged methods from other 2 modules. You can find out more about how the CPU usage percentage computed from http://www.codeproject.com/KB/threads/Get_CPU_Usage.aspx.
This method calculates the CPU usage based on process ID and time interval. The CPU usage means that within the specified time, for example 1000 milliseconds, how much CPU time is used by the process and system. The values of CPU usage are printed in DOS prompt for each calculation. The first value is the process CPU usage; the second one is system CPU usage. The values in last calculation are returned to variables, $prcCPU and $sysCPU.
If the method is called successfully, the return value is 0, otherwise it is -1.
Time interval in millisecond is for how often the CPU usage is calculated. 1000 means 1 second.
Specify how many times to calculate the CPU Usage
The process CPU usage in last calculation is returned to $prcCPU.
The system CPU usage in last calculation is returned to $sysCPU.
Same method in Win32::Process::CommandLine. Please see details in that module.
Same as method "getCpuUsage" in Win32::SystemInfo::CpuUsage. Please see details in that module.
Jing Kang <email@example.com>