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