The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Win32::Process::CpuUsage - Perl extension for getting a Windows process's CPU usage, command line parameter, and system CPU usage.

SYNOPSIS

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);

DESCRIPTION

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.

METHODS

Win32::Process::CpuUsage::GetProcessCpuUsage($pid, $interval, $counts, $prcCPU, $sysCPU)

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.

  • pid

    Process ID in integer

  • interval

    Time interval in millisecond is for how often the CPU usage is calculated. 1000 means 1 second.

  • counts

    Specify how many times to calculate the CPU Usage

  • prcCPU

    The process CPU usage in last calculation is returned to $prcCPU.

  • sysCPU

    The system CPU usage in last calculation is returned to $sysCPU.

Win32::Process::CpuUsage::GetPidCommandLine($pid, $str)

Same method in Win32::Process::CommandLine. Please see details in that module.

Win32::Process::CpuUsage::GetSystemCpuUsage($interval)

Same as method "getCpuUsage" in Win32::SystemInfo::CpuUsage. Please see details in that module.

SEE ALSO

Win32::Process::CommandLine

Win32::SystemInfo::CpuUsage

AUTHOR

Jing Kang <kxj@cpan.org>