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

Can anybody help me please figure out how to collect information CPU/RAM on windows xp with perl?

Replies are listed 'Best First'.
Re: CPU usage on winxp
by BrowserUk (Patriarch) on Jul 08, 2005 at 06:34 UTC

    Win32::Process::Info The following lists all processes, but you can pass a list of pids to only get info on those ids.

    #! perl -slw use strict; use Win32::Process::Info; my @fields = qw[ ProcessId Name ExecutablePath UserModeTime KernelModeTime MaximumWorkingSetSize MinimumWorkingSetSize ]; my $i = new Win32::Process::Info; printf "%10.10s %-22.22s %-40.40s %12.12s %14.14s %7.7s %7.7s\n", @fie +lds; printf "%10.10s %-22.22s %-40.40s %12.12s %14.14s %7.7s %7.7s\n", map{ defined() ? $_ : 'n/a' } @{ $_ }{ @fields } for $i->GetProcInfo(); __END__ P:\test>ProcInfo.pl ProcessId Name ExecutablePath + UserModeTime KernelModeTime Maximum Minimum 0 System Idle Process n/a + 0 183399.78125 n/a n/a 4 System n/a + 0 77.71875 1413120 0 572 SMSS.EXE C:\WINDOWS\System32\smss.exe + 0.015625 0.015625 1413120 204800 660 CSRSS.EXE n/a + 9.59375 49.78125 n/a n/a 684 WINLOGON.EXE C:\WINDOWS\system32\winlogon.exe + 0.640625 0.734375 1413120 204800 728 SERVICES.EXE C:\WINDOWS\system32\services.exe + 0.96875 2.625 1413120 204800 740 LSASS.EXE C:\WINDOWS\system32\lsass.exe + 1.671875 2.171875 1413120 204800 912 SVCHOST.EXE C:\WINDOWS\system32\svchost.exe + 0.21875 0.25 1413120 204800 968 SVCHOST.EXE C:\WINDOWS\System32\svchost.exe + 25.734375 21.984375 1413120 204800

    Caution: The Max/MinWorkingSet (memory) sizes coming up on my machine are very suspect?

    The script below used to produce good numbers on my old NT box, so it's probably something broken with my installation.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: CPU usage on winxp
by neniro (Priest) on Jul 08, 2005 at 07:52 UTC
Re: CPU usage on winxp
by jbrugger (Parson) on Jul 08, 2005 at 05:30 UTC
      Win32::SystemInfo has too many Caveats and is no where near tested enough on modern systems with modern Operating Systems. You may be able to throw something together if you study the module itself but I would not use it in any stable production.

        I realize I'm coming into this discussion a bit late, but I felt I needed to chime in. (I'm the author of Win32::SystemInfo.)

        The Caveats section is large because they come directly from the Win32 MSDN documentation. I felt it necessary to provide this information to users of the module.

        I agree that I haven't tested the module as extensively as I would like. However, there are quite a few people who do use the module so I'd wager that it has seen use on most "modern systems with modern Operating Systems".

        I do have to take issue with the statement about not using the module in "stable production". I see no reason why this statement should be true. The module has evolved quite a bit since 2005 and I'd like to think that stability is something that has only increased over time.



        Guildenstern
        Negated character class uber alles!
      Sys::CPU is only for BSD and Linux based platforms. The OP explained they needed something for Windows XP.
        From cpan: win32 support has been added (but not tested).

        Next the OP wanted to figure out on how to do it, a cpan module (working or not) can help by looking at the source.

        Since the OP did not provide any sign of effort (what he has tried, or which direction he's thinking), i point to the most logic place to start searching for it

        update anyway, i've found a better perl module on cpan, that would suit all needs

        "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.