Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring CPU clocks consumed by a process

I have written a program in C. Its a program created as result of a research. I want to compute exact CPU cycles which program consumes. Exact number of cycles. Any idea how can I find that?

like image 335
hasanatkazmi Avatar asked Dec 08 '22 03:12

hasanatkazmi


1 Answers

The valgrind tool cachegrind (valgrind --tool=cachegrind) will give you a detailed output including the number of instructions executed, cache misses and branch prediction misses. These can be accounted down to individual lines of assembler, so in principle (with knowledge of your exact architecture) you could derive precise cycle counts from this output.

Know that it will change from execution to execution, due to cache effects.

The documentation for the cachegrind tool is here.

like image 110
caf Avatar answered Dec 25 '22 19:12

caf