Gprof

Gprof allows for profiling a program, so you can analyze where your program passes most of its time in order to increase performance by modifying the code. The program must be compiled with a profiling option or available in the sourcecode. Then you will do a test run to collect profiling data. The results will be based on this test run.

= Example =

int main {  std::cout << "hello world" << std::endl; }
 * Write main.cpp:
 * 1) include

gcc -Wall -c -pg main.cpp gcc -Wall -lstdc++ -pg main.o
 * Build it using the pg option:

./a.out
 * Call it so you get profile data from one run:

gmon.out
 * Verify you have the profile file:
 * 1) ls gmon.out

Flat profile: Each sample counts as 0.01 seconds. no time accumulated %  cumulative   self              self     total time  seconds   seconds    calls  Ts/call  Ts/call  name 0.00     0.00     0.00        1     0.00     0.00  global constructors keyed to main 0.00     0.00     0.00        1     0.00     0.00  __static_initialization_and_destruction_0(int, int) [...]
 * Call gprof:
 * 1) gprof

= See also =
 * programming-related commands
 * ldd
 * nm
 * gprof man page.
 * introduction to profiling
 * introduction to gprof