Chapter 4. Using KProf

Using KProf with GNU gprof

gprof(1) is the most widely available profiler for unix platforms. When you are compiling software using GCC, you can use the -pg option to enable profiling in the code generated by the compiler. Please refer to the gcc manual for more information about profiling switches.

When you execute an application compiled with profiling turned on, a file named gprof.out is generated after execution. If a file with the same name already exists, it is overwritten. Please refer to the gprof documentation for more information about this (type info gprof).

Once you have the gprof.out generated, you can start using KProf. If the file is in the same directory than the application, then you can directly open the application itself using KProf. The gprof.out file will be automatically detected and analyzed.

In the case the gprof.out file is in another directory, you must either move it to the application directory or manually execute the gprof(1) command to generated the text output that KProf needs, using this command:

% gprof -b application-name gmon.out > results-file.txt

Now you can open the text results file with KProf, making sure that you select GNU gprof as the file type at bottom of the Open File dialog.