© 2008 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.

ITCWeb: Program Profiling and Timing

Two utilities, prof and gprof, generate program execution profiles. The prof profiler provides a flat analysis of the program execution, counting the total time spent in each function and the number of calls to each function. The timing information is based on a sampling of where the program is at random intervals during the run; therefore, up to a point a longer run will give a more accurate analysis.

The gprof profiler provides a call graph analysis of the program. In addition to the same information provided by the prof profiler, it also provides a detailed analysis of how functions call each other, how much time each function spends on behalf of each of its callers, etc. There are man pages on line for both utilities and they can be used on C, C++, or Fortran programs.

Some Unix systems, such as the Suns and IBMs, offer both prof and gprof. Others, such as Linux, provide only gprof by default. A few compilers, specifically the Portland Group compiler suite, provide their own profilers.

The options to use to enable profiling vary with the compiler. For example, the following compilation options should be invoked for prof and gprof respectively for the Fortran 90 compiler on Solaris systems:

  f90 -O -p -o myprog myprog.f

  f90 -O -pg -o myprog myprog.f
On Linux, ITC supports the Intel and the Portland Group compilers. Profiling is enabled for the Intel compilers with the -qp option for both compiling and linking.
  ifc -qp -c myprog.f
  ifc -qp -c mysub.f
  ifc -qp -o myprog myprof.o mysub.o
When the program is executed, a file of raw statistics is created(mon.out for prof and gmon.out for gprof). The respective profiler utility is then used to interpret and display the data from these files.
  prof [list of options] myprog > myprog.profile 
   
  gprof [list of options] myprog > myprog.profile 
The information generated by these profilers allow determination of the functions where the program spends the majority of its execution time, and therefore where optimization efforts should be concentrated.

Further information about gprof can be found on the following links:

http://www.delorie.com/gnu/docs/binutils/gprof_toc.html

http://www.delorie.com/gnu/docs/binutils/gprof.1.html

The Portland Group compilers require a different pattern. There are a variety of options that may be invoked, but the most common is -Mprof=func for profiling by function.

  pgf90 -Mprof=func -c myprog.f 
  pgf90 -Mprof=func -o myprog myprog.o
This produces a file pgprof.out on which the profiler pgprof can be run.
  pgprof pgprof.out
This profiler provides X-based graphical user interface (GUI) application, but if an X server is not available on the user's local desktop machine, it will revert to a command-line application. Instructions for using this more detailed information from pgprof is available in the PGI Tools manual at http://www.pgroup.com/doc/pgitools.pdf.

The PGI profiler can also be used in sampling mode, like the prof and gprof profilers; for this the option is -pg:

   pgf90 -pg -c myprog.f
   pgf90 -pg -o myprog myprog.o
   pgprof myprog > myprog.profile