Changes

Jump to: navigation, search

Profiling

408 bytes added, 12:42, 15 November 2023
Example: Profiling with 'gprof'
The <code>gprof</code> tool provides basic profiling capability using a combination of sampling (for times) and instrumentation (for call graph and counts). To use it:
# Build the software to be profiled using the <code>-pg</code> (profile generation) option and <code>-g</code> (debug) options to the gcc compiler. This may require that you modify the makefile or other build instructions, but it can often be done using the CFLAGS or CCOPTS variables passed to configure or make -- for example, <code>./configure CFLAGS="-g -pg -O2"</code>(Important: make sure that you include all of the flags that are usually used in the build. The easiest way to discover what these are is usually to perform a regular build and observe the values used).
# Execute the program. Ensure that you give it a typical to long execution time; if it is an interactive program, run through most of the commonly-used features, and if it is non-interactive, invoke it with common options and give it a good amount of data to process.
# Check that a file named <code>gmon.out</code> was produced when the program ran. If not, recheck the previous steps.
# Run the <code>gprof</code> program to generate a report: <code>gprof ''filenameOfExecutableBeingProfiled''</code>(Important: use the same executable as you used to generate the <code>gmon.out</code> file).
The output from gprof is a text report. It can be converted to a graphical representation, which is often more useful, using the <code>gprof2dot</code> script to convert it to the GraphViz "dot" format, then using the <code>dot</code> utility to output it in the desired graphics format.
gprof ''nameOfExecutable'' | gprof2dot | dot -Tx11
For more details and help on interpreting the report, see the gprof documentation.
=== Example: Profiling with perf ===

Navigation menu