mld has asked for the wisdom of the Perl Monks concerning the following question:

I have done with particluar process memory usage adn CPU time calculation.Here is the code ..

use Win32::Process::Info; use Win32::Process::List; $proc= Win32::Process::List->new(); $pi=Win32::Process::Info->new(); %list =$proc->GetProcesses(); open FILE, '>D:\\Automation Team\\Performance\\CPUUsage\\process_detai +ls1.txt' or die $!; print FILE "Process Name\t Mem in Bytes \t CPU time \n"; while(1) { foreach $pid (keys %list) { #print "$pid : $list{$pid}\n"; $pname=$list{$pid}; #print $pname, "\n"; if (($pname eq q/jqs.exe/)) { print FILE "$list{$pid}\t"; @process_information=$pi->GetProcInfo($pid); foreach $info (@process_information) { $value_Mem = ${$info}{"WorkingSetSize" +}; print FILE "\t$value_Mem \t"; $value_Ker=${$info}{"KernelModeTime"}; #print "Kernel Time:=$value_Ker \t"; $value_User=${$info}{"UserModeTime"}; #print "UserTime:=$value_User \t"; $value_CPU=$value_Ker+$value_User; #$value_CPU=$value_CPU/10000000; print FILE "$value_CPU\t"; print FILE "\n" } } } }

I want to calculate CPU usage of this process. Thanks.

Replies are listed 'Best First'.
Re: CPU Usage of particular process
by Corion (Patriarch) on May 07, 2009 at 07:16 UTC

    How about simply using the time the process has taken so far, and setting it in relation to the time the CPU has run overall? That should give you the part of time that has been spent on this process.