gprof: How do I?
1
1 7 Answers to Common Questions
1 *****************************
1
1 How can I get more exact information about hot spots in my program?
1
1 Looking at the per-line call counts only tells part of the story.
1 Because 'gprof' can only report call times and counts by function,
1 the best way to get finer-grained information on where the program
1 is spending its time is to re-factor large functions into sequences
1 of calls to smaller ones. Beware however that this can introduce
1 artificial hot spots since compiling with '-pg' adds a significant
1 overhead to function calls. An alternative solution is to use a
1 non-intrusive profiler, e.g. oprofile.
1
1 How do I find which lines in my program were executed the most times?
1
1 Use the 'gcov' program.
1
1 How do I find which lines in my program called a particular function?
1
1 Use 'gprof -l' and lookup the function in the call graph. The
1 callers will be broken down by function and line number.
1
1 How do I analyze a program that runs for less than a second?
1
1 Try using a shell script like this one:
1
1 for i in `seq 1 100`; do
1 fastprog
1 mv gmon.out gmon.out.$i
1 done
1
1 gprof -s fastprog gmon.out.*
1
1 gprof fastprog gmon.sum
1
1 If your program is completely deterministic, all the call counts
1 will be simple multiples of 100 (i.e., a function called once in
1 each run will appear with a call count of 100).
1