C:\Perl_PPM\Win32-Process-Perf-1.05\blib/lib/Win32/Process/Perf.pm |
Win32::Process::Perf: Shows Performance counter for a given process
This document describes version 1.00 of Win32::Process::Perf, released in April, 2005.
use Win32::Process::Perf; my $PERF = Win32::Process::Perf->new(<computer name>, <process name>); # The computer name have to be used without the \\ # e.g. my $PERF = Win32::Process::Perf->new("taifun", "explorer"); # check if success: if(!$PERF) { die; }
my $anz = $PERF->GetNumberofCounterNames(); print "$anz Counters available\n"; my %counternames = $PERF->GetCounterNames(); print "Avilable Counternames:\n"; foreach (1 .. $anz) { print $counternames{$_} . "\n"; } my $status = $PERF->PAddCounter(); # add all available counters to the query if($status == 0) { my $error = $PERF->GetErrorText(); print $error . "\n"; exit; } while(1) { $status = $PERF->PCollectData(); if($status == 0) { my $error = $PERF->GetErrorText(); print $error . "\n"; exit; } my %val = $PERF->PGetCounterValues($status); # now you can also get the CPU Time: my $cputime = $PERF->PGetCPUTime(); # and also the username which started the process: my $username = $PERF->PGetUserName(); foreach (1..$anz) { if(!$val{$_}) { exit; } my $key = $counternames{$_}; print "$key=" . $val{$_} . "\n"; } sleep(1); print "\n"; }
The Win32::Process::Perf
provides an interface to the performance data of a specific running process.
It uses the PDH library.
The module provide an Interface to the performance data of a specific running process. It uses the PDH library. The modul uses Win32::Locale to get the language of the operating system. To add the support for your language please look in the site/lib/Win32/Process/Perf directory. There are samples for the counter definition. The counter data files have to be only in the directory site/lib/Win32/Process/Perf. NOTE: The first line have to be the name for process in YOUR language. e.g. in german is it Prozess. The second line have to be the for the process ID in your language. At this time I have only support for Windows with en-us, de-at, de-ch. Maybe someone can provide me with data files for his language. Sample for en-us (english US): Process ID Process Sample for de-at (german Austria,Germany): Prozess Prozesskennung Sample for spain: (please provide me with one)
All funcitons return a non zero value if successful, and zero is they fail, excpet GetCounterValue()
which will return -1 if it fails.
new($ServerName,$ProcessName)
GetErrorText()
my $err = $PERF->GetErrorText();
PAddCounter()
my $err = $PERF->PAddCounter();
The return code is 0 on failur.
PCollectData()
PCollectData()
collects the current raw data value for all counters in the specified query
my $err $PERF->PCollectData(); On failur the return code is 0.
my %val = $PERF->PGetCounterValues(); To check if the process ended check if the value of the hash exist. The last value of %val is the CPU time in seconds of the process. Please take a look in test.pl
PGetCPUTime()
With this function the time the process used on the CPU can be retrived. my $cputime=$PERF->PGetCPUTime() The function returns the CPU time in seconds on success. If the function fails -1 will be returned NOTE: Use it only after the call to $PERF->PGetCounterValues(); =item PGetUserName()
This function returns the username which started the process. my $username = $PERF->PGetUserName(); On success the function returns the username and if it fails -1. NOTE: Use it only after the call to $PERF->PGetCounterValues(); Use $PERF->GetErrorText(); to get the error ocured if the function was called.
PGetPid()
This function returns the process id on success and undef if it fails.
Perl Modules: the File::Basename manpage <Win32::Locale> Win32 dll's pdh.dll and now Advapi32.lib
1) Better handling of the conter names provided in the *.dat files.
Reinhard Pagitsch <rpirpag@gmx.at>
I want to give Glen Small my special thank, because without his module Win32::PerfMon the implementation would taken much longer.
the Win32::PerfMon manpage the perl manpage
C:\Perl_PPM\Win32-Process-Perf-1.05\blib/lib/Win32/Process/Perf.pm |