Tech Support > Microsoft Windows > Development Resources > Record process cpu time?
Record process cpu time?
Posted by John Dumais on February 14th, 2006


Hello,

I'm trying to figure out how much time a process spends using the
processor resources: something equivalent to what is shown when running
the unix time command. For instance, if the process took 1 second to
run, I'd like to know how much time the process spent in user-mode code
and kernel-mode code. Those 2 numbers would probably add up to
something less than the 1 second total elapsed time it took the process
to run. I've seen WMI functions that record the percentage of time a
process spends in kernel mode or user mode, but those functions don't
record the time values themselves.

Maybe what I'm looking for is a sort of programmatic profiler? Is there
a way to do so with the windows API?

Thanks,

Posted by Kellie Fitton on February 14th, 2006


Hi,

I gather you are wanting to determine the CPU load of each process,
in this case, try to use the function GetProcessTimes() in a loop,
and then compare the user and the kernel times with the time passed
using the function GetTickCount(), this approach should report the
time that your process is using on the machine.

http://msdn.microsoft.com/library/de...ocesstimes.asp

http://msdn.microsoft.com/library/de...ttickcount.asp

Hope these information helps,

Kellie.


Similar Posts