in reply to Re: CPU usage on winxp
in thread CPU usage on winxp

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: CPU usage on winxp
by BrowserUk (Patriarch) on Mar 21, 2006 at 19:32 UTC

    You can't. Or at least, not easily. The times returned by Win32::Process::Info (and other similar modules) are the accumulated usage times for each process.

    To convert that to instantaneous system usage values you would have to accumulate all the times for all the processes. Do that twice, either side of a known time period. Subtract the first from the second and then calculate that number (of 100 nanosecond time ticks) as a percentage of the time period chosen.

    Doing that in perl, with all the numeric conversions involved, would take so long that your processing would itself amount to a significant percentage of the overall cpu usage. And adding fudge factors to account for the time spent accumulating and converting, as a percentage of the time period chosen for aquiring the deltas, would mean that any figures produced would be suspect anyway.

    However, in later versions of Win32 (XP sp1, 2003 and later), there is (at last) a single API that returns the information required to calculate this. I'll post some code under your newer thread to demostrate that.


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.