A customer was using the GetThreadTimes
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 QueryPerformanceCounter
that reported only CPU time consumed by a particular thread, rather than by the system in general.
Fortunately, there is. The QueryThreadCycleTime
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.
0 comments