Measuring CPU load

BCS ao at pathlink.com
Fri Dec 14 11:20:44 PST 2007


Reply to mike,

> Hi!
> 
> It's not really D related, I know, but I don't know where else to ask.
> 
> So: I've got this little class that measures in/out time of threads
> with  the rdtsc assembler opcode. The relevant thread gets started
> periodically,  takes time of start in[t] at the entry point and time
> of exit out [t] with  "scope (exit) ...".
> 
> This gives me the following measurments:
> 
> in[t]   // thread entered (current iteration)
> out[t]  // thread exited (current iteration)
> in[t-1] // thread entered (last iteration)
> And the following formula:
> 
> cpuload = 100 * (out[t] - in[t]) / (in[t] - in[t-1]);
> 

this is only valid if the thread is not context switched. 

the ony reliable way to get CPU loads I can think of would be to ask the OS.





More information about the Digitalmars-d mailing list