1GPROF(1)                              GNU                             GPROF(1)
2
3
4

NAME

6       gprof - display call graph profile data
7

SYNOPSIS

9       gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQRStZ][name] ]
10        [ -I dirs ] [ -d[num] ] [ -k from/to ]
11        [ -m min-count ] [ -R map_file ] [ -t table-length ]
12        [ --[no-]annotated-source[=name] ]
13        [ --[no-]exec-counts[=name] ]
14        [ --[no-]flat-profile[=name] ] [ --[no-]graph[=name] ]
15        [ --[no-]time=name] [ --all-lines ] [ --brief ]
16        [ --debug[=level] ] [ --function-ordering ]
17        [ --file-ordering map_file ] [ --directory-path=dirs ]
18        [ --display-unused-functions ] [ --file-format=name ]
19        [ --file-info ] [ --help ] [ --line ] [ --inline-file-names ]
20        [ --min-count=n ] [ --no-static ] [ --print-path ]
21        [ --separate-files ] [ --static-call-graph ] [ --sum ]
22        [ --table-length=len ] [ --traditional ] [ --version ]
23        [ --width=n ] [ --ignore-non-functions ]
24        [ --demangle[=STYLE] ] [ --no-demangle ]
25        [--external-symbol-table=name]
26        [ image-file ] [ profile-file ... ]
27

DESCRIPTION

29       "gprof" produces an execution profile of C, Pascal, or Fortran77
30       programs.  The effect of called routines is incorporated in the profile
31       of each caller.  The profile data is taken from the call graph profile
32       file (gmon.out default) which is created by programs that are compiled
33       with the -pg option of "cc", "pc", and "f77".  The -pg option also
34       links in versions of the library routines that are compiled for
35       profiling.  "Gprof" reads the given object file (the default is
36       "a.out") and establishes the relation between its symbol table and the
37       call graph profile from gmon.out.  If more than one profile file is
38       specified, the "gprof" output shows the sum of the profile information
39       in the given profile files.
40
41       "Gprof" calculates the amount of time spent in each routine.  Next,
42       these times are propagated along the edges of the call graph.  Cycles
43       are discovered, and calls into a cycle are made to share the time of
44       the cycle.
45
46       Several forms of output are available from the analysis.
47
48       The flat profile shows how much time your program spent in each
49       function, and how many times that function was called.  If you simply
50       want to know which functions burn most of the cycles, it is stated
51       concisely here.
52
53       The call graph shows, for each function, which functions called it,
54       which other functions it called, and how many times.  There is also an
55       estimate of how much time was spent in the subroutines of each
56       function.  This can suggest places where you might try to eliminate
57       function calls that use a lot of time.
58
59       The annotated source listing is a copy of the program's source code,
60       labeled with the number of times each line of the program was executed.
61

OPTIONS

63       These options specify which of several output formats "gprof" should
64       produce.
65
66       Many of these options take an optional symspec to specify functions to
67       be included or excluded.  These options can be specified multiple
68       times, with different symspecs, to include or exclude sets of symbols.
69
70       Specifying any of these options overrides the default (-p -q), which
71       prints a flat profile and call graph analysis for all functions.
72
73       "-A[symspec]"
74       "--annotated-source[=symspec]"
75           The -A option causes "gprof" to print annotated source code.  If
76           symspec is specified, print output only for matching symbols.
77
78       "-b"
79       "--brief"
80           If the -b option is given, "gprof" doesn't print the verbose blurbs
81           that try to explain the meaning of all of the fields in the tables.
82           This is useful if you intend to print out the output, or are tired
83           of seeing the blurbs.
84
85       "-C[symspec]"
86       "--exec-counts[=symspec]"
87           The -C option causes "gprof" to print a tally of functions and the
88           number of times each was called.  If symspec is specified, print
89           tally only for matching symbols.
90
91           If the profile data file contains basic-block count records,
92           specifying the -l option, along with -C, will cause basic-block
93           execution counts to be tallied and displayed.
94
95       "-i"
96       "--file-info"
97           The -i option causes "gprof" to display summary information about
98           the profile data file(s) and then exit.  The number of histogram,
99           call graph, and basic-block count records is displayed.
100
101       "-I dirs"
102       "--directory-path=dirs"
103           The -I option specifies a list of search directories in which to
104           find source files.  Environment variable GPROF_PATH can also be
105           used to convey this information.  Used mostly for annotated source
106           output.
107
108       "-J[symspec]"
109       "--no-annotated-source[=symspec]"
110           The -J option causes "gprof" not to print annotated source code.
111           If symspec is specified, "gprof" prints annotated source, but
112           excludes matching symbols.
113
114       "-L"
115       "--print-path"
116           Normally, source filenames are printed with the path component
117           suppressed.  The -L option causes "gprof" to print the full
118           pathname of source filenames, which is determined from symbolic
119           debugging information in the image file and is relative to the
120           directory in which the compiler was invoked.
121
122       "-p[symspec]"
123       "--flat-profile[=symspec]"
124           The -p option causes "gprof" to print a flat profile.  If symspec
125           is specified, print flat profile only for matching symbols.
126
127       "-P[symspec]"
128       "--no-flat-profile[=symspec]"
129           The -P option causes "gprof" to suppress printing a flat profile.
130           If symspec is specified, "gprof" prints a flat profile, but
131           excludes matching symbols.
132
133       "-q[symspec]"
134       "--graph[=symspec]"
135           The -q option causes "gprof" to print the call graph analysis.  If
136           symspec is specified, print call graph only for matching symbols
137           and their children.
138
139       "-Q[symspec]"
140       "--no-graph[=symspec]"
141           The -Q option causes "gprof" to suppress printing the call graph.
142           If symspec is specified, "gprof" prints a call graph, but excludes
143           matching symbols.
144
145       "-t"
146       "--table-length=num"
147           The -t option causes the num most active source lines in each
148           source file to be listed when source annotation is enabled.  The
149           default is 10.
150
151       "-y"
152       "--separate-files"
153           This option affects annotated source output only.  Normally,
154           "gprof" prints annotated source files to standard-output.  If this
155           option is specified, annotated source for a file named
156           path/filename is generated in the file filename-ann.  If the
157           underlying file system would truncate filename-ann so that it
158           overwrites the original filename, "gprof" generates annotated
159           source in the file filename.ann instead (if the original file name
160           has an extension, that extension is replaced with .ann).
161
162       "-Z[symspec]"
163       "--no-exec-counts[=symspec]"
164           The -Z option causes "gprof" not to print a tally of functions and
165           the number of times each was called.  If symspec is specified,
166           print tally, but exclude matching symbols.
167
168       "-r"
169       "--function-ordering"
170           The --function-ordering option causes "gprof" to print a suggested
171           function ordering for the program based on profiling data.  This
172           option suggests an ordering which may improve paging, tlb and cache
173           behavior for the program on systems which support arbitrary
174           ordering of functions in an executable.
175
176           The exact details of how to force the linker to place functions in
177           a particular order is system dependent and out of the scope of this
178           manual.
179
180       "-R map_file"
181       "--file-ordering map_file"
182           The --file-ordering option causes "gprof" to print a suggested .o
183           link line ordering for the program based on profiling data.  This
184           option suggests an ordering which may improve paging, tlb and cache
185           behavior for the program on systems which do not support arbitrary
186           ordering of functions in an executable.
187
188           Use of the -a argument is highly recommended with this option.
189
190           The map_file argument is a pathname to a file which provides
191           function name to object file mappings.  The format of the file is
192           similar to the output of the program "nm".
193
194                   c-parse.o:00000000 T yyparse
195                   c-parse.o:00000004 C yyerrflag
196                   c-lang.o:00000000 T maybe_objc_method_name
197                   c-lang.o:00000000 T print_lang_statistics
198                   c-lang.o:00000000 T recognize_objc_keyword
199                   c-decl.o:00000000 T print_lang_identifier
200                   c-decl.o:00000000 T print_lang_type
201                   ...
202
203           To create a map_file with GNU "nm", type a command like "nm
204           --extern-only --defined-only -v --print-file-name program-name".
205
206       "-T"
207       "--traditional"
208           The -T option causes "gprof" to print its output in "traditional"
209           BSD style.
210
211       "-w width"
212       "--width=width"
213           Sets width of output lines to width.  Currently only used when
214           printing the function index at the bottom of the call graph.
215
216       "-x"
217       "--all-lines"
218           This option affects annotated source output only.  By default, only
219           the lines at the beginning of a basic-block are annotated.  If this
220           option is specified, every line in a basic-block is annotated by
221           repeating the annotation for the first line.  This behavior is
222           similar to "tcov"'s -a.
223
224       "--demangle[=style]"
225       "--no-demangle"
226           These options control whether C++ symbol names should be demangled
227           when printing output.  The default is to demangle symbols.  The
228           "--no-demangle" option may be used to turn off demangling.
229           Different compilers have different mangling styles.  The optional
230           demangling style argument can be used to choose an appropriate
231           demangling style for your compiler.
232
233   Analysis Options
234       "-a"
235       "--no-static"
236           The -a option causes "gprof" to suppress the printing of statically
237           declared (private) functions.  (These are functions whose names are
238           not listed as global, and which are not visible outside the
239           file/function/block where they were defined.)  Time spent in these
240           functions, calls to/from them, etc., will all be attributed to the
241           function that was loaded directly before it in the executable file.
242           This option affects both the flat profile and the call graph.
243
244       "-c"
245       "--static-call-graph"
246           The -c option causes the call graph of the program to be augmented
247           by a heuristic which examines the text space of the object file and
248           identifies function calls in the binary machine code.  Since normal
249           call graph records are only generated when functions are entered,
250           this option identifies children that could have been called, but
251           never were.  Calls to functions that were not compiled with
252           profiling enabled are also identified, but only if symbol table
253           entries are present for them.  Calls to dynamic library routines
254           are typically not found by this option.  Parents or children
255           identified via this heuristic are indicated in the call graph with
256           call counts of 0.
257
258       "-D"
259       "--ignore-non-functions"
260           The -D option causes "gprof" to ignore symbols which are not known
261           to be functions.  This option will give more accurate profile data
262           on systems where it is supported (Solaris and HPUX for example).
263
264       "-k from/to"
265           The -k option allows you to delete from the call graph any arcs
266           from symbols matching symspec from to those matching symspec to.
267
268       "-l"
269       "--line"
270           The -l option enables line-by-line profiling, which causes
271           histogram hits to be charged to individual source code lines,
272           instead of functions.  This feature only works with programs
273           compiled by older versions of the "gcc" compiler.  Newer versions
274           of "gcc" are designed to work with the "gcov" tool instead.
275
276           If the program was compiled with basic-block counting enabled, this
277           option will also identify how many times each line of code was
278           executed.  While line-by-line profiling can help isolate where in a
279           large function a program is spending its time, it also
280           significantly increases the running time of "gprof", and magnifies
281           statistical inaccuracies.
282
283       "--inline-file-names"
284           This option causes "gprof" to print the source file after each
285           symbol in both the flat profile and the call graph. The full path
286           to the file is printed if used with the -L option.
287
288       "-m num"
289       "--min-count=num"
290           This option affects execution count output only.  Symbols that are
291           executed less than num times are suppressed.
292
293       "-nsymspec"
294       "--time=symspec"
295           The -n option causes "gprof", in its call graph analysis, to only
296           propagate times for symbols matching symspec.
297
298       "-Nsymspec"
299       "--no-time=symspec"
300           The -n option causes "gprof", in its call graph analysis, not to
301           propagate times for symbols matching symspec.
302
303       "-Sfilename"
304       "--external-symbol-table=filename"
305           The -S option causes "gprof" to read an external symbol table file,
306           such as /proc/kallsyms, rather than read the symbol table from the
307           given object file (the default is "a.out"). This is useful for
308           profiling kernel modules.
309
310       "-z"
311       "--display-unused-functions"
312           If you give the -z option, "gprof" will mention all functions in
313           the flat profile, even those that were never called, and that had
314           no time spent in them.  This is useful in conjunction with the -c
315           option for discovering which routines were never called.
316
317   Miscellaneous Options
318       "-d[num]"
319       "--debug[=num]"
320           The -d num option specifies debugging options.  If num is not
321           specified, enable all debugging.
322
323       "-h"
324       "--help"
325           The -h option prints command line usage.
326
327       "-Oname"
328       "--file-format=name"
329           Selects the format of the profile data files.  Recognized formats
330           are auto (the default), bsd, 4.4bsd, magic, and prof (not yet
331           supported).
332
333       "-s"
334       "--sum"
335           The -s option causes "gprof" to summarize the information in the
336           profile data files it read in, and write out a profile data file
337           called gmon.sum, which contains all the information from the
338           profile data files that "gprof" read in.  The file gmon.sum may be
339           one of the specified input files; the effect of this is to merge
340           the data in the other input files into gmon.sum.
341
342           Eventually you can run "gprof" again without -s to analyze the
343           cumulative data in the file gmon.sum.
344
345       "-v"
346       "--version"
347           The -v flag causes "gprof" to print the current version number, and
348           then exit.
349
350   Deprecated Options
351       These options have been replaced with newer versions that use symspecs.
352
353       "-e function_name"
354           The -e function option tells "gprof" to not print information about
355           the function function_name (and its children...) in the call graph.
356           The function will still be listed as a child of any functions that
357           call it, but its index number will be shown as [not printed].  More
358           than one -e option may be given; only one function_name may be
359           indicated with each -e option.
360
361       "-E function_name"
362           The "-E function" option works like the "-e" option, but time spent
363           in the function (and children who were not called from anywhere
364           else), will not be used to compute the percentages-of-time for the
365           call graph.  More than one -E option may be given; only one
366           function_name may be indicated with each -E option.
367
368       "-f function_name"
369           The -f function option causes "gprof" to limit the call graph to
370           the function function_name and its children (and their
371           children...).  More than one -f option may be given; only one
372           function_name may be indicated with each -f option.
373
374       "-F function_name"
375           The -F function option works like the "-f" option, but only time
376           spent in the function and its children (and their children...) will
377           be used to determine total-time and percentages-of-time for the
378           call graph.  More than one -F option may be given; only one
379           function_name may be indicated with each -F option.  The -F option
380           overrides the -E option.
381

FILES

383       "a.out"
384           the namelist and text space.
385
386       "gmon.out"
387           dynamic call graph and profile.
388
389       "gmon.sum"
390           summarized dynamic call graph and profile.
391

BUGS

393       The granularity of the sampling is shown, but remains statistical at
394       best.  We assume that the time for each execution of a function can be
395       expressed by the total time for the function divided by the number of
396       times the function is called.  Thus the time propagated along the call
397       graph arcs to the function's parents is directly proportional to the
398       number of times that arc is traversed.
399
400       Parents that are not themselves profiled will have the time of their
401       profiled children propagated to them, but they will appear to be
402       spontaneously invoked in the call graph listing, and will not have
403       their time propagated further.  Similarly, signal catchers, even though
404       profiled, will appear to be spontaneous (although for more obscure
405       reasons).  Any profiled children of signal catchers should have their
406       times propagated properly, unless the signal catcher was invoked during
407       the execution of the profiling routine, in which case all is lost.
408
409       The profiled program must call "exit"(2) or return normally for the
410       profiling information to be saved in the gmon.out file.
411

SEE ALSO

413       monitor(3), profil(2), cc(1), prof(1), and the Info entry for gprof.
414
415       "An Execution Profiler for Modular Programs", by S. Graham, P. Kessler,
416       M. McKusick; Software - Practice and Experience, Vol. 13, pp. 671-685,
417       1983.
418
419       "gprof: A Call Graph Execution Profiler", by S. Graham, P. Kessler, M.
420       McKusick; Proceedings of the SIGPLAN '82 Symposium on Compiler
421       Construction, SIGPLAN Notices, Vol. 17, No  6, pp. 120-126, June 1982.
422
424       Copyright (c) 1988-2021 Free Software Foundation, Inc.
425
426       Permission is granted to copy, distribute and/or modify this document
427       under the terms of the GNU Free Documentation License, Version 1.3 or
428       any later version published by the Free Software Foundation; with no
429       Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
430       Texts.  A copy of the license is included in the section entitled "GNU
431       Free Documentation License".
432
433
434
435binutils-2.37                     2022-03-10                          GPROF(1)
Impressum