g-prof Toolcase

Install gprof

apt-get install binutils

Compile

To use profiling you need to use the following flags:

  • -g for debugging information
  • -pg for profiling information

Add the -g -pg flags to the compiler (either gcc or g++):

Example in C

 gcc -g -pg -o my_executable my_file.c

Example in C++

 g++ -g -pg -o my_executable my_file.c

Execute and profile the application

Use gprof to generate the profile:

gprof my_executable > profile.txt

Review the profiling details

Review the profile with any text editor you wish:

geany profile.txt