Previous Page
Next Page

18.8. Profiling

The -p option adds special functions to your program to output profiling information when you run it. Profiling is useful in resolving performance problems, because it lets you see which functions your program is spending its execution time on. The profiling output is saved in a file called mon.out. You can then use the prof utility to analyze the profiling information in a number of ways; see the prof manual for details.

For the GNU profiler, gprof, compile your program with the -pg option. The default output filename for the profiling information is then gmon.out. gprof with the -pg option can generate a call graph showing which functions in your program call which others. If you combine the -pg option with -g, the GCC option that provides source-line information for a debugger, then gprof can also provide line-by-line profiling.


Previous Page
Next Page