Time Measurement Methods
dotTrace can measure call execution time in several ways:
- Real time (performance counter)
- Real time (CPU instruction)
- Thread time
- Thread cycle time
Real time (CPU instruction)
Real time (CPU instruction), also called real-world time or wall-clock time, is time elapsed between method entry and method exit. This approach makes no difference between the cases when a method consumes CPU and does some meaningful work and when a method is in a sleep, wait or join. dotTrace measures time in both cases. So it reads values of TSC processor register on method entry and on method exit, then calculates the difference.
Real time (performance counter)
Real time (performance counter) is similar to Real time (CPU instruction) except that it uses a slightly different way of measuring time intervals. dotTrace uses Performance Counter API to retrieve and use performance counter data from operating system, network and devices for measuring time.
Thread time is the time measured by a thread-specific timer which is paused when its thread is paused (waiting for processor or sleeping). This kind of measurement is supported only for sampling profiling and has lower resolution than other methods (about 10ms).
Thread cycle time
Thread cycle time is the time measured by a thread-specific timer which is paused when its thread is paused (waiting for processor or sleeping). It is a bit more accurate way to time your application code. Actually, Thread cycle time is similar to Real time (CPU instruction), it also uses CPU instruction to calculate the time, but does not take into account the time when thread does not do real work.
To see the difference between real time and thread time, consider the following example. Some function executes for 10 seconds. It is waiting for some data from the network for 8 seconds. And it is processing the data without sleeping or waiting for the remaining 2 seconds. Real time for this function is 10 seconds. Thread time for this function is 2 seconds.
In tracing profiling, generally, due to OS limitations, measuring real time is much faster than measuring thread time (up to 10 times faster). In case sampling profiling is used, measuring both kinds of time consumes the same overhead.