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

NAME

6       gprof - display call graph profile data
7

SYNOPSIS

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

FILES

386       "a.out"
387           the namelist and text space.
388
389       "gmon.out"
390           dynamic call graph and profile.
391
392       "gmon.sum"
393           summarized dynamic call graph and profile.
394

BUGS

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

SEE ALSO

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