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.

In reply to Re^3: CPU usage on winxp by BrowserUk
in thread CPU usage on winxp 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.