less than 1 minute read

In-depth tutorial: https://www.thegeekstuff.com/2012/08/gprof-tutorial/

Summary: Compile with -pg compiler flag (gcc/clang). Executing binary gives gmon.out output file. Opening that file with gprof yields function times. Different output possible for different flags. Output mainly contains two sections:

  • flat profile: sorts all function calls by time
  • call graph: lists many table entries. each entry is one function call and shows its callees, callers, and times.

Example usage:

clang -pg main.cpp -o main
gprof -b main gmon.out > analysis.txt