| Author |
CPU/Memory usage of a process on Windows machine
|
|
|
| Greetings
I am trying to find CPU and memory usage on a windows machine and i
was able to get through memory usage using Win32::Process::Info
module's GetProcInfo function.
This code may be helpfull to others which calculate the memory usage
of a particular process on windows
#!c:/perl/bin/perl.exe
# This is a test scrip
use Win32::Process::Info;
use warnings;
use strict;
my $pi = Win32::Process::Info->new ();
my @process_information = $pi->GetProcInfo(4488); ## 4488 is pid of a
particular process.
foreach $info (@process_information) {
foreach my $key (keys %{$info}) {
if ($key eq "WorkingSetSize") {
my $value = ${$info}{$key}/1024;
print "$key:=>$value \n"
}
}
}
However i am struck at the cpu usage part.. If anyone can point me to
some good article or any docs to read for the same would be
appreciated. I have already googled a lot but i think i am missing
something..
Thanks ..
| |
| Oryann9 2007-06-29, 9:58 pm |
|
> #!c:/perl/bin/perl.exe
> # This is a test scrip
> use Win32::Process::Info;
> use warnings;
> use strict;
> my $pi = Win32::Process::Info->new ();
> my @process_information = $pi->GetProcInfo(4488);
> ## 4488 is pid of a
> particular process.
> foreach $info (@process_information) {
> foreach my $key (keys %{$info}) {
> if ($key eq "WorkingSetSize") {
> my $value = ${$info}{$key}/1024;
> print "$key:=>$value \n"
> }
>
> }
> }
>
>
I tried to use a regexp like so
and it prints nothing, however I use the PID of the
outlook process and it works???
Any help would be appreciated!
my $name qr(/out\w+/i);
my @process_information = $pi->GetProcInfo($name);
________________________________________
________________________________________
____
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097
| |
| Oryann9 2007-06-29, 9:58 pm |
|
You have to add UserModeTime and KernelModeTime then
divide by 10,000,000.
See:
http://www.microsoft.com/technet/sc...05/hey0922.mspx
use Win32::Process::Info;
use Data::Dumper;
my $pi = Win32::Process::Info->new ();
my @process_information = $pi->GetProcInfo(3692);
foreach my $info (@process_information) {
foreach my $key (keys %{$info}) {
if ($key eq "Name" or $key eq
"WorkingSetSize" or
$key eq "UserModeTime" or $key eq
"KernelModeTime") {
my $value = ${$info}{$key};
print "\n$key: => $value \n";
}
}
}
~
________________________________________
________________________________________
____
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=o...+for+kids&cs=bz
|
|
|
|