For what it's worth, here's an example script for Win32::Perflib that Dave Roth wrote. It could easily be changed to include CPU usage.

use Win32::PerfLib; my $Server; my $ProcessIndex; $Server = Win32::NodeName unless( $Server = $ARGV[0] ); print "Collecting process info for $Server...\n"; Win32::PerfLib::GetCounterNames( $Server, \%StringIndex ); map { $String{$StringIndex{$_}} = $_; } ( keys( %StringIndex ) ); $ProcessIndex = $String{Process}; # Connect to the server's performance data $Perf = new Win32::PerfLib( $Server ); if( ! $Perf ) { print "Could not obtain the process list.\n"; exit(); } $ProcessList = {}; # get the performance data for the process object $Perf->GetObjectList( $ProcessObject, $ProcessList ); $Perf->Close(); $InstanceHash = $ProcessList->{Objects}->{$ProcessIndex}->{Instances}; foreach my $ProcessObject ( sort( keys( %{$InstanceHash} ) ) ) { my $ProcessCounter = $InstanceHash->{$ProcessObject}->{Counters}; my %ThisProcess; $ThisProcess{Name} = $InstanceHash->{$ProcessObject}->{Name}; foreach my $Attrib ( keys( %$ProcessCounter ) ) { my $AttribName = $StringIndex{$ProcessCounter->{$Attrib}->{Cou +nterNameTitleIndex}}; $ThisProcess{$AttribName} = Format( $ProcessCounter->{$Attrib} +, $ProcessList->{Objects}->{$ProcessIndex} ); } $ProcessList{$ThisProcess{'ID Process'}} = \%ThisProcess; } $~ = PROCESS_HEADER; write; $~ = PROCESS_INFO; foreach $Process ( sort( keys( %ProcessList ) ) ) { # Don't make $Proc lexicaly scoped since it is used in a formatted # write. $Proc = $ProcessList{$Process}; write; } sub Format { my( $Proc, $ObjectList ) = @_; my $Value = $Proc->{Counter}; my $Type = $Proc->{CounterType}; my $TB = $ObjectList->{PerfFreq}; my $Y = $ObjectList->{PerfTime}; if( PERF_100NSEC_TIMER == $Type ) { $Value = 100 * ( $Value / 1000000 ) ; } elsif( PERF_ELAPSED_TIME == $Type ) { my( $Hour, $Min, $Sec ); # Convert the value into seconds... $Value = ( $Y - $Value ) / $TB; $Hour = $Value / ( 60 * 60 ); $Min = ( $Hour - int( $Hour ) ) * 60; $Sec = ( $Min - int( $Min ) ) * 60; $Value = sprintf( "%d:%02d:%02d", int( $Hour ), int( $Min ), i +nt( $Sec ) ); } return( $Value ); } sub FormatNumber { my( $Number ) = @_; my( $Suffix ) = ""; my $K = 1024; if( $K <= $Number ) { $Suffix = " K"; $Number /= $K; } $Number =~ s/(\.\d{0,2})\d*$/$1/; {} while ($Number =~ s/^(-?\d+)(\d{3})/$1,$2/); return( $Number . $Suffix ); } format PROCESS_HEADER = @||| @||||| @|||||||||||||||| @|||||| @|||||||||||| @|||||||||||| @||| +||| PID, Parent, "Process Name", "Threads", "Memory", "Memory Peak", "Hand +les" ---- ------ ----------------- ------- ------------- ------------- ---- +--- . format PROCESS_INFO = @||| @||||| @<<<<<<<<<<<<<<<< @>>>>>> @>>>>>>>>>>>> @>>>>>>>>>>>> @>>> +>>> $Proc->{'ID Process'}, $Proc->{'Creating Process ID'}, $Proc->{Name}, +$Proc->{'Thread Count'}, FormatNumber( $Proc->{'Working Set'} ), Form +atNumber( $Proc->{'Working Set Peak'} ), $Proc->{'Handle Count'} . print "Finished.\n";

In reply to Re: Re: (tye)Re: WinNT CPU & MEM usage by myocom
in thread WinNT CPU & MEM usage by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.