GProf

From ScorecWiki

Jump to: navigation, search

This page serves as a gateway for information related to use of the gprof profiling tool at SCOREC.

Quick Usage Guide

The following was tested on Romulus and Piglet.

Download the following source code linpack_bench.C from http://people.sc.fsu.edu/~jburkardt/cpp_src/gprof/gprof.html

Build the code, note that the '-pg' is required for gprof profiling

 g++ -pg linpack_bench.C -lm -o linpack_bench

Run the code

 ./linpack_bench

Run gprof. Note that gprof only needs to know which executable is being profiled; input arguments passed to the executable being profiled are not needed.

 gprof ./linpack_bench > gprof.out

Look at the output, you will see two main sections, the flat profile and the call graph.

 vi gprof.out

Filter the flat profile using the symspec argument to the '-p' option. The symspec argument expects the function name to appear exactly as it is named in the binary. Note that since we used the g++ compiler then the symbols in the binary are mangled. To get the mangled name we will use the objdump command piped into grep and piped into awk. The name of the function in this example is 'r8_random' and was found by reading the source code linpack_bench.C.

 gprof -p`objdump -t linpack_bench | grep r8_random | awk '{print $6}'` ./linpack_bench > gprof.r8_random.out

Look at the output. You should see the following:

 Flat profile:
 Each sample counts as 0.01 seconds.
 %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 100.50      0.29     0.29  2000000     0.00     0.00  r8_random(int*)
 %         the percentage of the total running time of the
 time       program used by this function.
 cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.
 self      the number of seconds accounted for by this
 seconds    function alone.  This is the major sort for this
          listing.
 calls      the number of times this function was invoked, if
          this function is profiled, else blank.
 self      the average number of milliseconds spent in this
 ms/call    function per call, if this function is profiled,
          else blank.
 total     the average number of milliseconds spent in this
 ms/call    function and its descendents per call, if this 
          function is profiled, else blank.
 name       the name of the function.  This is the minor sort
          for this listing. The index shows the location of
          the function in the gprof listing. If the index is
          in parenthesis it shows where it would appear in
          the gprof listing if it were to be printed.

References

Guide

Manual

Personal tools