Recently done a performance tuning using gprof, gprof2dot and dot. While there are already a lot of webs talking about them respectively or generally. This post is trying to provide some hints from my real experience, as well as some usefully links for reference. May it help.
Hint 1: ‘-pg’ is needed both in compiling and linking: If the binary is generated from source within one cmd, please no worry about this. However, as long as ‘Make’ is used. Make sure you have ‘-pg’ in the 2 stages. Otherwise, call graph data would be lost in the gprof report.
Hint 2: gprof: gmon.out file is missing call-graph data: There are 2 possibilities worth checking. A, there is no call graph indeed as our code is simple; B, ‘-pg’ is only included during the linking stage but not compiling.
Hint 3: which kind of gprof report is in favor of gprof2dot: ‘gprof BIN gmon.out > report.txt’ is fairly good enough.
Hint 4: commands summary:
gcc -g -pg -o BIN SRC.c
gcc -g -pg -c SRC.c
gcc -pg -o BIN SRC.o
gprof BIN gmon.out > report.txt
gprof2dot report.txt > report.dot
dot -Tpng -oreport.png report.dot
Hint 5: useful links: