I need to profile a couple of C codes and get an annotated file with percentage of exeuction time taken by each line or atleast each block(while/if-else/for-functions) etc.
So far I have looked into valgrind(callgrind) and gperf and some other tools. So far what I get is
- Count of each function or line of source Code like how many times it is execution.
- Or Percentage of Count.
- Or execution time taken by each funtion call.
What I do need however if percentage of execution time not the count and that should be for each line of source code or atleast all blocks(while/if-else/for-functions).
Can someone let me know of a way I can do it ?
Thanks,
I believe
perf(1)
(part of thelinux-tools-common
package in Ubuntu) will get you what you want. It makes use of a kernel-based subsystem called Performance counters for Linux, included in newer kernels. More information can be found here.Simple usage example below. Make sure to compile with debugging symbols.
Cachegrind might be worth looking into too.