= GNU Gprof == Docs # [[https://sourceware.org/binutils/docs/gprof/|Manual]] according to [[wp>Gprof]] # GLAP p.619 == Preparing the Executable Both compiling an linking phase of [[GNU GCC]] must be telled to generate extra code to write profile information {{{-pg}}}: gcc -o foo foo.c -pg # or gcc -c foo.c -pg gcc -o foo foo.o -pg FIXME What if external libs are used? == Generating Profile Data According to GLAP p.619 the profile data file {{{gmon.out}}} is only written upon normal exit of the application, not eg on exit with SIGKILL. See also [[terminal_special_characters]] In order to exit gracefully for a programm with an infintite main loop, eg a signal handler for TERM could be installed. See [[/becki/my/linux/linux_signals]] == Analysing Profile Data gprof foo gmon.out Writes ACII to stdout for review. It shows that different gmon.out produces from the same binary produce different results. GLAP p.628 proposes to produce multiple gmon.out's, build the average and review this: gprof --sum foo gmon.out.? gprof foo gmon.sum > gmon.sum.txt