Is there anything better than GetThreadTimes for obtaining per-thread CPU usage information?

Raymond Chen

A customer was using the Get­Thread­Times function for high-resolution profiling of performance-sensitive code, but found that its accuracy is rather poor. They were hoping there would be something more along the lines of a Query­Performance­Counter that reported only CPU time consumed by a particular thread, rather than by the system in general.

Fortunately, there is. The Query­Thread­Cycle­Time function gives you the CPU cycles consumed by a particular thread. This includes time spent both in user mode and in kernel mode.

Note, however, that these values are reported directly from the CPU using mechanisms like RDTSC or the performance monitor control register. This means that the actual results are at the mercy of whatever the CPU manufacturer decides the CPU cycle counter means. Maybe they correspond to wall clock time; maybe they don’t.


Discussion is closed.

Feedback usabilla icon