Measuring CPU load
Mike
vertex at gmx.at
Thu Dec 13 13:29:27 PST 2007
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]);
to get the cpu load in %.
Now I've tested this and I'm not quite sure. The results are at least
somewhat reasonable, although they seem to be double the real value (I've
got a dual core system) so that might explain that.
But before guessing around I thought I'll ask here if this way of
measuring is completely wrong or if there's a better way to do that.
-Mike
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list