Program Profiling


If you have a program that takes a lot of time to run, profiling is a way to find out where the program is spending most of it's time. Knowing this will indicate what changes need to be made to speed up the program.

The gprof Profiling Tool

The following procedure works on Linux and uses the gprof tool:
  1. Compile and link the program with the -pg flag. This is done by inserting the following commands in the CMakeLIsts.txt file:
    set (FFLAGS "-pg") # For profiling
    set (CFLAGS "-pg")
    Note: If you are interested in timing code that is in libraries used by the program, local copies of the libraries of interest need to be created, the above lines put in their CMakeLists.txt files, and the libraries recompiled.
  2. Run the program. This will make a "raw" data file called gmon.out
  3. Run gprof to produce a profile file with "flat profile" and "call graph" information:
    gprof exe-file >
    where exe-file is the name of the executable file. This will create a file (but any name can be used here instead).
  4. The information in the profie file is generally self-explanatory. The man gprof command gives information on gprof including various profile file options (for example, creating an annotated source listing labeling the number of times each line of the program was executed). Doing a google search for gprof will give further info.

Getting Help

If you need to contact someone for help, please see the Help and Mailing List Information wiki page.

This topic: ACC/ACL > WebHome > ProgramProfile
Topic revision: 20 Jan 2015, AttilioDeFalco
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CLASSE Wiki? Send feedback