1GPROF(1) GNU GPROF(1)
2
3
4
6 gprof - display call graph profile data
7
9 gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQZ][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 ] [ --min-count=n ]
20 [ --no-static ] [ --print-path ] [ --separate-files ]
21 [ --static-call-graph ] [ --sum ] [ --table-length=len ]
22 [ --traditional ] [ --version ] [ --width=n ]
23 [ --ignore-non-functions ] [ --demangle[=STYLE] ]
24 [ --no-demangle ] [--external-symbol-table=name]
25 [ image-file ] [ profile-file ... ]
26
28 "gprof" produces an execution profile of C, Pascal, or Fortran77
29 programs. The effect of called routines is incorporated in the profile
30 of each caller. The profile data is taken from the call graph profile
31 file (gmon.out default) which is created by programs that are compiled
32 with the -pg option of "cc", "pc", and "f77". The -pg option also
33 links in versions of the library routines that are compiled for
34 profiling. "Gprof" reads the given object file (the default is
35 "a.out") and establishes the relation between its symbol table and the
36 call graph profile from gmon.out. If more than one profile file is
37 specified, the "gprof" output shows the sum of the profile information
38 in the given profile files.
39
40 "Gprof" calculates the amount of time spent in each routine. Next,
41 these times are propagated along the edges of the call graph. Cycles
42 are discovered, and calls into a cycle are made to share the time of
43 the cycle.
44
45 Several forms of output are available from the analysis.
46
47 The flat profile shows how much time your program spent in each
48 function, and how many times that function was called. If you simply
49 want to know which functions burn most of the cycles, it is stated
50 concisely here.
51
52 The call graph shows, for each function, which functions called it,
53 which other functions it called, and how many times. There is also an
54 estimate of how much time was spent in the subroutines of each
55 function. This can suggest places where you might try to eliminate
56 function calls that use a lot of time.
57
58 The annotated source listing is a copy of the program's source code,
59 labeled with the number of times each line of the program was executed.
60
62 These options specify which of several output formats "gprof" should
63 produce.
64
65 Many of these options take an optional symspec to specify functions to
66 be included or excluded. These options can be specified multiple
67 times, with different symspecs, to include or exclude sets of symbols.
68
69 Specifying any of these options overrides the default (-p -q), which
70 prints a flat profile and call graph analysis for all functions.
71
72 "-A[symspec]"
73 "--annotated-source[=symspec]"
74 The -A option causes "gprof" to print annotated source code. If
75 symspec is specified, print output only for matching symbols.
76
77 "-b"
78 "--brief"
79 If the -b option is given, "gprof" doesn't print the verbose blurbs
80 that try to explain the meaning of all of the fields in the tables.
81 This is useful if you intend to print out the output, or are tired
82 of seeing the blurbs.
83
84 "-C[symspec]"
85 "--exec-counts[=symspec]"
86 The -C option causes "gprof" to print a tally of functions and the
87 number of times each was called. If symspec is specified, print
88 tally only for matching symbols.
89
90 If the profile data file contains basic-block count records,
91 specifying the -l option, along with -C, will cause basic-block
92 execution counts to be tallied and displayed.
93
94 "-i"
95 "--file-info"
96 The -i option causes "gprof" to display summary information about
97 the profile data file(s) and then exit. The number of histogram,
98 call graph, and basic-block count records is displayed.
99
100 "-I dirs"
101 "--directory-path=dirs"
102 The -I option specifies a list of search directories in which to
103 find source files. Environment variable GPROF_PATH can also be
104 used to convey this information. Used mostly for annotated source
105 output.
106
107 "-J[symspec]"
108 "--no-annotated-source[=symspec]"
109 The -J option causes "gprof" not to print annotated source code.
110 If symspec is specified, "gprof" prints annotated source, but
111 excludes matching symbols.
112
113 "-L"
114 "--print-path"
115 Normally, source filenames are printed with the path component
116 suppressed. The -L option causes "gprof" to print the full
117 pathname of source filenames, which is determined from symbolic
118 debugging information in the image file and is relative to the
119 directory in which the compiler was invoked.
120
121 "-p[symspec]"
122 "--flat-profile[=symspec]"
123 The -p option causes "gprof" to print a flat profile. If symspec
124 is specified, print flat profile only for matching symbols.
125
126 "-P[symspec]"
127 "--no-flat-profile[=symspec]"
128 The -P option causes "gprof" to suppress printing a flat profile.
129 If symspec is specified, "gprof" prints a flat profile, but
130 excludes matching symbols.
131
132 "-q[symspec]"
133 "--graph[=symspec]"
134 The -q option causes "gprof" to print the call graph analysis. If
135 symspec is specified, print call graph only for matching symbols
136 and their children.
137
138 "-Q[symspec]"
139 "--no-graph[=symspec]"
140 The -Q option causes "gprof" to suppress printing the call graph.
141 If symspec is specified, "gprof" prints a call graph, but excludes
142 matching symbols.
143
144 "-t"
145 "--table-length=num"
146 The -t option causes the num most active source lines in each
147 source file to be listed when source annotation is enabled. The
148 default is 10.
149
150 "-y"
151 "--separate-files"
152 This option affects annotated source output only. Normally,
153 "gprof" prints annotated source files to standard-output. If this
154 option is specified, annotated source for a file named
155 path/filename is generated in the file filename-ann. If the
156 underlying file system would truncate filename-ann so that it
157 overwrites the original filename, "gprof" generates annotated
158 source in the file filename.ann instead (if the original file name
159 has an extension, that extension is replaced with .ann).
160
161 "-Z[symspec]"
162 "--no-exec-counts[=symspec]"
163 The -Z option causes "gprof" not to print a tally of functions and
164 the number of times each was called. If symspec is specified,
165 print tally, but exclude matching symbols.
166
167 "-r"
168 "--function-ordering"
169 The --function-ordering option causes "gprof" to print a suggested
170 function ordering for the program based on profiling data. This
171 option suggests an ordering which may improve paging, tlb and cache
172 behavior for the program on systems which support arbitrary
173 ordering of functions in an executable.
174
175 The exact details of how to force the linker to place functions in
176 a particular order is system dependent and out of the scope of this
177 manual.
178
179 "-R map_file"
180 "--file-ordering map_file"
181 The --file-ordering option causes "gprof" to print a suggested .o
182 link line ordering for the program based on profiling data. This
183 option suggests an ordering which may improve paging, tlb and cache
184 behavior for the program on systems which do not support arbitrary
185 ordering of functions in an executable.
186
187 Use of the -a argument is highly recommended with this option.
188
189 The map_file argument is a pathname to a file which provides
190 function name to object file mappings. The format of the file is
191 similar to the output of the program "nm".
192
193 c-parse.o:00000000 T yyparse
194 c-parse.o:00000004 C yyerrflag
195 c-lang.o:00000000 T maybe_objc_method_name
196 c-lang.o:00000000 T print_lang_statistics
197 c-lang.o:00000000 T recognize_objc_keyword
198 c-decl.o:00000000 T print_lang_identifier
199 c-decl.o:00000000 T print_lang_type
200 ...
201
202 To create a map_file with GNU "nm", type a command like "nm
203 --extern-only --defined-only -v --print-file-name program-name".
204
205 "-T"
206 "--traditional"
207 The -T option causes "gprof" to print its output in "traditional"
208 BSD style.
209
210 "-w width"
211 "--width=width"
212 Sets width of output lines to width. Currently only used when
213 printing the function index at the bottom of the call graph.
214
215 "-x"
216 "--all-lines"
217 This option affects annotated source output only. By default, only
218 the lines at the beginning of a basic-block are annotated. If this
219 option is specified, every line in a basic-block is annotated by
220 repeating the annotation for the first line. This behavior is
221 similar to "tcov"'s -a.
222
223 "--demangle[=style]"
224 "--no-demangle"
225 These options control whether C++ symbol names should be demangled
226 when printing output. The default is to demangle symbols. The
227 "--no-demangle" option may be used to turn off demangling.
228 Different compilers have different mangling styles. The optional
229 demangling style argument can be used to choose an appropriate
230 demangling style for your compiler.
231
232 Analysis Options
233
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 "-m num"
284 "--min-count=num"
285 This option affects execution count output only. Symbols that are
286 executed less than num times are suppressed.
287
288 "-nsymspec"
289 "--time=symspec"
290 The -n option causes "gprof", in its call graph analysis, to only
291 propagate times for symbols matching symspec.
292
293 "-Nsymspec"
294 "--no-time=symspec"
295 The -n option causes "gprof", in its call graph analysis, not to
296 propagate times for symbols matching symspec.
297
298 "-Sfilename"
299 "--external-symbol-table=filename"
300 The -S option causes "gprof" to read an external symbol table file,
301 such as /proc/kallsyms, rather than read the symbol table from the
302 given object file (the default is "a.out"). This is useful for
303 profiling kernel modules.
304
305 "-z"
306 "--display-unused-functions"
307 If you give the -z option, "gprof" will mention all functions in
308 the flat profile, even those that were never called, and that had
309 no time spent in them. This is useful in conjunction with the -c
310 option for discovering which routines were never called.
311
312 Miscellaneous Options
313
314 "-d[num]"
315 "--debug[=num]"
316 The -d num option specifies debugging options. If num is not
317 specified, enable all debugging.
318
319 "-h"
320 "--help"
321 The -h option prints command line usage.
322
323 "-Oname"
324 "--file-format=name"
325 Selects the format of the profile data files. Recognized formats
326 are auto (the default), bsd, 4.4bsd, magic, and prof (not yet
327 supported).
328
329 "-s"
330 "--sum"
331 The -s option causes "gprof" to summarize the information in the
332 profile data files it read in, and write out a profile data file
333 called gmon.sum, which contains all the information from the
334 profile data files that "gprof" read in. The file gmon.sum may be
335 one of the specified input files; the effect of this is to merge
336 the data in the other input files into gmon.sum.
337
338 Eventually you can run "gprof" again without -s to analyze the
339 cumulative data in the file gmon.sum.
340
341 "-v"
342 "--version"
343 The -v flag causes "gprof" to print the current version number, and
344 then exit.
345
346 Deprecated Options
347
348 These options have been replaced with newer versions that use
349 symspecs.
350
351 "-e function_name"
352
353 The -e function option tells "gprof" to not print information about
354 the function function_name (and its children...) in the call graph.
355 The function will still be listed as a child of any functions that
356 call it, but its index number will be shown as [not printed]. More
357 than one -e option may be given; only one function_name may be
358 indicated with each -e option.
359
360 "-E function_name"
361
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
370 The -f function option causes "gprof" to limit the call graph to
371 the function function_name and its children (and their
372 children...). More than one -f option may be given; only one
373 function_name may be indicated with each -f option.
374
375 "-F function_name"
376
377 The -F function option works like the "-f" option, but only time
378 spent in the function and its children (and their children...) will
379 be used to determine total-time and percentages-of-time for the
380 call graph. More than one -F option may be given; only one
381 function_name may be indicated with each -F option. The -F option
382 overrides the -E option.
383
385 "a.out"
386 the namelist and text space.
387
388 "gmon.out"
389 dynamic call graph and profile.
390
391 "gmon.sum"
392 summarized dynamic call graph and profile.
393
395 The granularity of the sampling is shown, but remains statistical at
396 best. We assume that the time for each execution of a function can be
397 expressed by the total time for the function divided by the number of
398 times the function is called. Thus the time propagated along the call
399 graph arcs to the function's parents is directly proportional to the
400 number of times that arc is traversed.
401
402 Parents that are not themselves profiled will have the time of their
403 profiled children propagated to them, but they will appear to be
404 spontaneously invoked in the call graph listing, and will not have
405 their time propagated further. Similarly, signal catchers, even though
406 profiled, will appear to be spontaneous (although for more obscure
407 reasons). Any profiled children of signal catchers should have their
408 times propagated properly, unless the signal catcher was invoked during
409 the execution of the profiling routine, in which case all is lost.
410
411 The profiled program must call "exit"(2) or return normally for the
412 profiling information to be saved in the gmon.out file.
413
415 monitor(3), profil(2), cc(1), prof(1), and the Info entry for gprof.
416
417 "An Execution Profiler for Modular Programs", by S. Graham, P. Kessler,
418 M. McKusick; Software - Practice and Experience, Vol. 13, pp. 671-685,
419 1983.
420
421 "gprof: A Call Graph Execution Profiler", by S. Graham, P. Kessler, M.
422 McKusick; Proceedings of the SIGPLAN '82 Symposium on Compiler
423 Construction, SIGPLAN Notices, Vol. 17, No 6, pp. 120-126, June 1982.
424
426 Copyright (c) 1988, 92, 97, 98, 99, 2000, 2001, 2003, 2007, 2008, 2009
427 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
437 Hey! The above document had some coding errors, which are explained
438 below:
439
440 Around line 539:
441 You can't have =items (as at line 545) unless the first thing after
442 the =over is an =item
443
444
445
446binutils-2.20 2009-10-16 GPROF(1)