As tye pointed out, Win32::PerfLib is the way to get the info you want.
However, using this module is extremely non-intuative due to the amount and complexity of the information returned and the weird format it is returned in, so here's some crude code to show how to get and display some of the info available, including the process name/ID/thread count.
#! perl -w
use strict;
use Data::Dumper;
use Win32::PerfLib;
my (%counters, %r_counters);
Win32::PerfLib::GetCounterNames('', \%counters);
# Build a reverse lookup table. Names are clearer than numbers.
@r_counters{values %counters} = (keys %counters);
# retrieve the id for process object
my $processObj_id = $r_counters{Process};
# retrieve the id for the process ID counter
my $processCounter_id = $r_counters{'ID Process'};
my %processes;
# create connection to $server
my $perflib = new Win32::PerfLib('');
# get the performance data for the process object
$perflib->GetObjectList($processObj_id, \%processes);
$perflib->Close();
my $pInstances = $processes{Objects}{$processObj_id}{Instances};
foreach my $p (keys %{$pInstances}) {
my $pICounters = $pInstances->{$p}{Counters};
print "\nProcess name=$pInstances->{$p}{Name}\n";
foreach my $i (keys %{$pICounters}) {
printf "%s=%s %s\n",
$counters{$pICounters->{$i}{CounterNameTitleIndex}}||'?',
$pICounters->{$i}{Counter},
exists $pICounters->{$i}{Display} ? $pICounters->{$i}{Disp
+lay} : '';
}
# print Dumper $pICounters; # Uncomment to view other available inf
+o
}
Some sample output
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
|