mld has asked for the wisdom of the Perl Monks concerning the following question:
I want to calculate CPU Usage of aprticular process.I have calculated Memory USage and CPU Time
use Win32::Process::Info; my $pi = Win32::Process::Info->new(); my @process_information = $pi->GetProcInfo(1333); while(1){ foreach $info (@process_information) { foreach my $key (keys %{$info}) { if ($key eq "WorkingSetSize") { $value_Mem = ${$info}{$key}/1024; print "$key:=>$value_Mem \t" } if ($key eq "KernelModeTime") { $value_Ker=${$info}{$key}; print "$key:=$value_Ker \t" } if ($key eq "UserModeTime") { $value_User=${$info}{$key}; print "$key:=$value_User \t" } } $value_CPU=$value_Ker+$value_User; $value_CPU=$value_CPU/10000000; print "CPU Time :=$value_CPU\t"; print "\n" } }
In the code I have passed the process ID.Since the process id changes I want to pass the process name.Is this possible
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to calculate CPU Usage
by kennethk (Abbot) on May 05, 2009 at 14:24 UTC | |
|
Re: How to calculate CPU Usage
by BrowserUk (Patriarch) on May 05, 2009 at 17:40 UTC |