Profiling with gprof
The gprof program is a profiling tool found in most Linux environments. It collects performance metrics using sampling techniques as well as instrumentation. It requires your program to be compiled with a supporting compiler such as the GNU compiler.
Prerequisite knowledge
To use gprof on Pawsey supercomputers you should first be familiar with using it in your own development environment.
Overview
The following is an overview of the process for using gprof to profile your program:
Enable profiling in your program by compiling and linking with appropriate flags for the compiler.
(Optional) Set environment variables for MPI programs to set output profile filenames.
Run your program as usual, and a file containing profiling information will be generated.
Analyse the output of this file using the
gprofcommand.
This page provides a step-by-step example of using the gprof tool to generate profiling information regarding the performance of a program.
Steps
Compile and link the source code using the
-pgcompiler flag, for example:(Optional) Set the profile output filename prefix in your jobscript if your program uses MPI for parallelism:
Run the program to generate the output file(s)
View the output with
gprof. For non-MPI programs use the singlegmon.outfile:For MPI programs, specify a particular
gmon.out.*file if a particular process is of interests, or all of them for combined output:
Result
The final gprof command will print the profiling information, which can be customised using command line options.
Example
This example profiles a MPI program which calculates the value of pi.
Create a file
darts-mpi.cthat contains the source code:Compile and link the source code using the
-pgcompiler flag, for example:Create a jobscript called
darts-mpi.slurmand set theGMON_OUT_PREFIX:Run the program to generate the output file(s)
View the output with
gprofspecifyinggmon.out.*:
Next steps
The gprof output can be customised using command line options.
Refer to the gprof manual page for more information:
Pressing q will exit the manual pages.