gprof: Introduction

1 
1 1 Introduction to Profiling
1 ***************************
1 
1 Profiling allows you to learn where your program spent its time and
1 which functions called which other functions while it was executing.
1 This information can show you which pieces of your program are slower
1 than you expected, and might be candidates for rewriting to make your
1 program execute faster.  It can also tell you which functions are being
1 called more or less often than you expected.  This may help you spot
1 bugs that had otherwise been unnoticed.
1 
1    Since the profiler uses information collected during the actual
1 execution of your program, it can be used on programs that are too large
1 or too complex to analyze by reading the source.  However, how your
1 program is run will affect the information that shows up in the profile
1 data.  If you don't use some feature of your program while it is being
1 profiled, no profile information will be generated for that feature.
1 
1    Profiling has several steps:
1 
1    * You must compile and link your program with profiling enabled.
1      ⇒Compiling a Program for Profiling Compiling.
1 
1    * You must execute your program to generate a profile data file.
1      ⇒Executing the Program Executing.
1 
11    * You must run 'gprof' to analyze the profile data.  ⇒'gprof'
      Command Summary Invoking.
1 
1    The next three chapters explain these steps in greater detail.
1 
1    Several forms of output are available from the analysis.
1 
1    The "flat profile" shows how much time your program spent in each
1 function, and how many times that function was called.  If you simply
1 want to know which functions burn most of the cycles, it is stated
1 concisely here.  ⇒The Flat Profile Flat Profile.
1 
1    The "call graph" shows, for each function, which functions called it,
1 which other functions it called, and how many times.  There is also an
1 estimate of how much time was spent in the subroutines of each function.
1 This can suggest places where you might try to eliminate function calls
1 that use a lot of time.  ⇒The Call Graph Call Graph.
1 
1    The "annotated source" listing is a copy of the program's source
1 code, labeled with the number of times each line of the program was
1 executed.  ⇒The Annotated Source Listing Annotated Source.
1 
1    To better understand how profiling works, you may wish to read a
11 description of its implementation.  ⇒Implementation of Profiling
 Implementation.
1