On Unix-like operating systems, the gprof command is a software developement tool that displays call graph profile data of a compiled binary.

This page covers the GNU/Linux version of gprof.

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.out, by default) which is created by programs that are compiled with the -pg option of cc, pc, and f77. The -pg option also links in versions of the library routines that are compiled for profiling. gprof reads the given object file (the default is a.out) and establishes the relation between its symbol table and the call graph profile from gmon.out. If more than one profile file is specified, the gprof output shows the sum of the profile information in the given profile files.

  • Description
  • Syntax
  • Related commands
  • Linux commands help

If you use gcc 2.95.x or 3.0 to compile your binaries, you may need to add the -fprofile-arcs to the compile command line for the call graphs to be properly stored in gmon.out.

gprof calculates the amount of time spent in each routine. Next, these times are propagated along the edges of the call graph. Cycles are discovered, and calls into a cycle are made to share the time of the cycle.

Several forms of output are available from the analysis:

  • The flat profile shows how much time your program spent in each function, and how many times that function was called. If you want to know which functions burn most of the cycles, it is stated concisely here.
  • The call graph shows, for each function, which functions called it, which other functions it called, and how many times. There is also an estimate of how much time was spent in the subroutines of each function. This can suggest places where you might try to eliminate function calls that use a lot of time.
  • The annotated source listing is a copy of the program’s source code, labeled with the number of times each line of the program was executed.

Syntax

gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQZ][name] ] [ -I dirs ] [ -d[num] ] [ -k from/to ] [ -m min-count ] [ -R map_file ] [ -t table-length ] [ –[no-]annotated-source[=name] ] [ –[no-]exec-counts[=name] ] [ –[no-]flat-profile[=name] ] [ –[no-]graph[=name] ] [ –[no-]time=name] [ –all-lines ] [ –brief ] [ –debug[=level] ] [ –function-ordering ] [ –file-ordering map_file ] [ –directory-path=dirs ] [ –display-unused-functions ] [ –file-format=name ] [ –file-info ] [ –help ] [ –line ] [ –min-count=n ] [ –no-static ] [ –print-path ] [ –separate-files ] [ –static-call-graph ] [ –sum ] [ –table-length=len ] [ –traditional ] [ –version ] [ –width=n ] [ –ignore-non-functions ] [ –demangle[=STYLE] ] [ –no-demangle ] [–external-symbol-table=name] [ image-file ] [ profile-file … ]

Options

These options specify which of several output formats gprof should produce.

Many of these options take an optional symspec to specify functions to be included or excluded. These options can be specified multiple times, with different symspecs, to include or exclude sets of symbols.

Specifying any of these options overrides the default (-p -q), which prints a flat profile and call graph analysis for all functions.

Analysis Options

Miscellaneous Options

Deprecated Options

These options are replaced with newer versions that use symspecs.

c-parse.o:00000000 T yyparsec-parse.o:00000004 C yyerrflagc-lang.o:00000000 T maybe_objc_method_namec-lang.o:00000000 T print_lang_statisticsc-lang.o:00000000 T recognize_objc_keywordc-decl.o:00000000 T print_lang_identifierc-decl.o:00000000 T print_lang_type…

Files

cc — Compiler of the C programming language.