I know that getrusage()
can provide per-thread CPU utilization, but only the time spent on the CPU. Is there any way to get the number of executed CPU instructions? Or the number of cycles spent on the cpu?
Basically, I need to find a reproducible measure of how much the thread spends on the CPU. Any suggestions to do this in C?
UPDATE (to respond to comments):
- Ideally I'd need this in a platform independent way, but Linux would be the most useful.
- Reproducibility is the most important for me, even if that means the actual runtime may be slightly different.
- I know vTune (and have used it), but I'd like to have this info programmatically while my code is running. So vTune is out, as well as the suggestions made in the post linked by Craig Estey.
- I did look at the Intel Intrinsics Guide, but did not find anything useful...