gprof and dot – some hints using gprof, gprof2dot and dot

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.

(provided by

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 >
dot -Tpng -oreport.png

Hint 5: useful links:

gprof and gprof2dot brief intro (Chinese version)

‘-pg’ option for gprof



About daveti

Interested in kernel hacking, compilers, machine learning and guitars.
This entry was posted in IDE_Make, Programming, Stuff about Compiler and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.