Gprof

Table of Contents

It is a performance profiling tool for the running time of procedures.

1 Steps

1.1 Compile and Run program

Compile with flag -pg. It should appear in both compile and link options, otherwise no call-graph will be produced. Running program as normal, and gmon.out will be produced in the current working directory.

1.2 Running gprof

gprof OPTIONS EXECUTABLE-FILE PROFILE-DATA-FILES
  • options (pq as default, specify to overwrite)
    p
    flat profile
    q
    call graph
    A
    annotated source code
  • if not given, use a.out
  • if not given, use gmon.out

Most likely, no options needed. Just run gprof in the same directory with a.out and gmon.out, it will print to stdout the flat profile and call graph profile.