Reputation: 507
I am using GCC on ubuntu, and I want a function that does measures the time that my function uses the CPU. I do not want to include the time that the CPU spent on background processes.
For example, if my function used the CPU for 10 ms, then the processor processed some other data for 20 ms, then continued working on my function for 8 ms. I want it to return 18ms, not 38. I don't mind if the result was in CPU ticks.
Upvotes: 2
Views: 328
Reputation: 1468
In addition to the answer of Baris Demiray I can personally recommend the callgrind tool (as well as any other tool) of the valgrind toolset. This is especially useful in combination with kcachegrind/qcachegrind which should be available through the ubuntu repositories.
A very brief description of both tools, gprof and callgrind can be found here: http://kcachegrind.sourceforge.net/html/Introduction.html
Upvotes: 1
Reputation: 1607
What you want to do is called profiling and gprof
on Linux is quite handy for that, see http://www.ibm.com/developerworks/library/l-gnuprof.html.
Upvotes: 2