[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Looking at the per-line call counts only tells part of the story.
Because gprof
can only report call times and counts by function,
the best way to get finer-grained information on where the program
is spending its time is to re-factor large functions into sequences
of calls to smaller ones. Beware however that this can introduce
artifical hot spots since compiling with `-pg' adds a significant
overhead to function calls. An alternative solution is to use a
non-intrusive profiler, e.g. oprofile.
Compile your program with basic-block counting enabled, run it, then use the following pipeline:
gprof -l -C objfile | sort -k 3 -n -r |
This listing will show you the lines in your code executed most often, but not necessarily those that consumed the most time.
Use `gprof -l' and lookup the function in the call graph. The callers will be broken down by function and line number.
Try using a shell script like this one:
for i in `seq 1 100`; do fastprog mv gmon.out gmon.out.$i done gprof -s fastprog gmon.out.* gprof fastprog gmon.sum |
If your program is completely deterministic, all the call counts will be simple multiples of 100 (i.e. a function called once in each run will appear with a call count of 100).