Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Win32::PerfMon get no instances or objects name

by shonorio (Hermit)
on Mar 14, 2005 at 15:40 UTC ( #439313=perlquestion: print w/replies, xml ) Need Help??
shonorio has asked for the wisdom of the Perl Monks concerning the following question:


I'm trying to use Win32::PerfMon to get the counters and instances names, but for some objects (like 'Processor') I can't get this value, always return -1.

I could observe that all objects that contain any instances return no counters names, but I can get the values without problem.

If someone has any lights to share me, I'll apprecciate any help.

Solli Moreira Honorio
Sao Paulo - Brazil
  • Comment on Win32::PerfMon get no instances or objects name

Replies are listed 'Best First'.
Re: Win32::PerfMon get no instances or objects name
by ZlR (Chaplain) on Mar 15, 2005 at 09:29 UTC
    Update : please excuse my following rant, it concerns Win32::PerfLib, while shonorio is really asking about Win32::PerfMon , a module that I didn't know but actually exists.
    It's still possible to access counters with Win32::PerfLib , but PerfMon looks much simpler .



    The win32 perflib data structure is very close to hell !

    If your are using Win32::PerfLib ( and not PerfMon as you say) the return value of the method you use has no sense other than failure (0) or success (anything but 0).
    The interesting results are obtained in a hash that you pass as a reference in the call to the method.
    Look at the docs :

    $ok = Win32::PerfLib::GetCounterNames($server,$hashref)
    Then you have a reference to an hash in $hashref .
    The meanings of the keys of this hash are described in the docs.
    It gets nasty because most of these keys point to other hashes that in turn point to hashes .
    There is seven levels of such hashes in this so-called "structure" ...
    ... Don't use it if you don't have to ;)

    Hope this helps,
    zlr .


      You are double right, right because I can get this information by Win32::PerLib and it is not easy, but I have one script to do this.

      And second right because Win32::PerfMon is to much easy and simple, that why I'm trying to solve this little problem.

      Thanks for your post

      Solli Moreira Honorio
      Sao Paulo - Brazil
        Hello shonorio,

        Did you find a solution for this yet ?
        I finally got to install Win32::PerfMon. (i used the ppm version available at )
        My finds are : it works if you don't use strict .
        For the record the exact error message with this is :

        Can't use string ("-1") as an ARRAY ref while "strict refs" in use
        The other interesting find is that i can't get any "Instances" values to print, only "Counters" . This sounds really like some "PerfLib hell" to me. The way i understand it, an object can have either counters or instances which in turn can have either one and so on .

        Maybe the module is not fully functional ?
        Can anyone shed more light on this since Win32::Perfmon looks promising but not fully working ?! .

Re: Win32::PerfMon get no instances or objects name
by FitTrend (Pilgrim) on Mar 15, 2005 at 18:11 UTC
Re: Win32::PerfMon get no instances or objects name
by jimrobertsiii (Scribe) on Mar 15, 2005 at 06:36 UTC
    Hi Solli,

    Can you please post some code that demonstrates your problem?


      Sory, forgot to post the code, but as you can see there are nothing special.

      I have the same behavior on Windows XP/2000/2003.

      use Win32::PerfMon; my $PerfObj = Win32::PerfMon->new("."); my $Objects = $PerfObj->ListObjects(); foreach $Object (@$Objects) { print "$Object\n"; my $Counters = $PerfObj->ListCounters($Object); my $Instances = $PerfObj->ListInstances($Object); foreach $Counter (@$Counters) { print "\t[Counter]$Counter\n"; } foreach $Instance (@$Instances) { print "\t[Instance]$Instance\n"; } }
      Solli Moreira Honorio
      Sao Paulo - Brazil

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://439313]
Approved by tye
Front-paged by tye
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2018-07-22 03:25 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (451 votes). Check out past polls.