Reputation: 2459
Could Someone kindly tell me how can I profile single lines or blocks of code of a program in C with GNU profiler?
I used gprof ./a.out gmon.out
which gives me flat profile and Call graph. However, I would like to see lines that are more frequently accessed.
Thanks,
Upvotes: 0
Views: 797
Reputation: 2459
Ok, I'll post this answer so if some newbie like me searched for it can find it faster :) here are the steps: source
gcc -fprofile-arcs -ftest-coverage fourcefile.c
(At the end of compilation files *.gcno will be produced)gcov sourcefile.c
(At the end of running, a file (*.gcov) will be produced which contains which contains all the required info)Upvotes: 0
Reputation: 7881
This is probably one of those things that you just don't know the term you should've googled, so I'll answer it:
The term you are looking for is "annotation"-you want to annotate the source and see the line by line hits in the code.
Calling gprof with the -A
flag will dump out the samples on each line that were caught.
See Also:
https://sourceware.org/binutils/docs/gprof/Annotated-Source.html
Upvotes: 1