Contents
How does Gprof work?
Gprof works by automatically instrumenting your code during compilation, and then sampling the application’s program counter during execution. Sampling data is saved in a file, typically named gmon. Gprof was developed as an extension of the prof command, by providing a call graph of the program’s execution.
What is Gprof in Linux?
DESCRIPTION. gprof produces an execution profile of C, Pascal, or Fortran77 programs. The effect of called routines is incorporated in the profile of each caller. The profile data is taken from the call graph profile file (gmon.
How is a code profiler such as Gprof useful?
Through profiling one can determine the parts in program code that are time consuming and need to be re-written. This helps make your program execution faster which is always desired.
How accurate is gprof?
They are completely accurate and will not vary from run to run if your program is deterministic. The sampling period that is printed at the beginning of the flat profile says how often samples are taken. The rule of thumb is that a run-time figure is accurate if it is considerably bigger than the sampling period.
How to link a program for profiling in gprof?
To link the program for profiling, if you use a compiler such as cc to do the linking, simply specify `-pg’ in addition to your usual options. The same option, `-pg’, alters either compilation or linking to do what is necessary for profiling.
What kind of analysis is done in gprof?
By default, two kinds of analysis are performed: the flat profile and the call graph. Both types are explained in the following sections. The flat profile shows the total amount of time your program spent executing each function. At the end of the profile, you will see a legend describing what each of the columns of numbers means.
Where do I save the output of gprof?
Following the gprof command with ” > output-file ” causes the output of gprof to be saved to output-file so you can examine it later. For this example, the program name is kruse and we will save the output into a file called kruse.output : After completing the last step, the gprof’s analysis has been saved into the kruse.output file.
How to create a gprof profile for EECS 380?
gprof Quick-Start Guide 1 Compiling for profiling. Before you can profile your program, you must first recompile it specifically for profiling. 2 Creating gmon.out. 3 Running gprof. 4 Analyzing gprof’s output. 5 Interpreting the flat profile. 6 Interpreting the call graph.