1 This is ../../src/gprof/gprof.info, produced by makeinfo version 4.2
2 from ../../src/gprof/gprof.texi.
5 * gprof: (gprof). Profiling your program's execution
8 This file documents the gprof profiler of the GNU system.
10 Copyright (C) 1988, 92, 97, 98, 99, 2000, 2001, 2003 Free Software
13 Permission is granted to copy, distribute and/or modify this document
14 under the terms of the GNU Free Documentation License, Version 1.1 or
15 any later version published by the Free Software Foundation; with no
16 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
17 Texts. A copy of the license is included in the section entitled "GNU
18 Free Documentation License".
21 File: gprof.info, Node: Top, Next: Introduction, Up: (dir)
23 Profiling a Program: Where Does It Spend Its Time?
24 **************************************************
26 This manual describes the GNU profiler, `gprof', and how you can use
27 it to determine which parts of a program are taking most of the
28 execution time. We assume that you know how to write, compile, and
29 execute programs. GNU `gprof' was written by Jay Fenlason.
31 This document is distributed under the terms of the GNU Free
32 Documentation License. A copy of the license is included in the
33 section entitled "GNU Free Documentation License".
37 * Introduction:: What profiling means, and why it is useful.
39 * Compiling:: How to compile your program for profiling.
40 * Executing:: Executing your program to generate profile data
41 * Invoking:: How to run `gprof', and its options
43 * Output:: Interpreting `gprof''s output
45 * Inaccuracy:: Potential problems you should be aware of
46 * How do I?:: Answers to common questions
47 * Incompatibilities:: (between GNU `gprof' and Unix `gprof'.)
48 * Details:: Details of how profiling is done
49 * GNU Free Documentation License:: GNU Free Documentation License
52 File: gprof.info, Node: Introduction, Next: Compiling, Prev: Top, Up: Top
54 Introduction to Profiling
55 *************************
57 Profiling allows you to learn where your program spent its time and
58 which functions called which other functions while it was executing.
59 This information can show you which pieces of your program are slower
60 than you expected, and might be candidates for rewriting to make your
61 program execute faster. It can also tell you which functions are being
62 called more or less often than you expected. This may help you spot
63 bugs that had otherwise been unnoticed.
65 Since the profiler uses information collected during the actual
66 execution of your program, it can be used on programs that are too
67 large or too complex to analyze by reading the source. However, how
68 your program is run will affect the information that shows up in the
69 profile data. If you don't use some feature of your program while it
70 is being profiled, no profile information will be generated for that
73 Profiling has several steps:
75 * You must compile and link your program with profiling enabled.
78 * You must execute your program to generate a profile data file.
81 * You must run `gprof' to analyze the profile data. *Note
84 The next three chapters explain these steps in greater detail.
86 Several forms of output are available from the analysis.
88 The "flat profile" shows how much time your program spent in each
89 function, and how many times that function was called. If you simply
90 want to know which functions burn most of the cycles, it is stated
91 concisely here. *Note Flat Profile::.
93 The "call graph" shows, for each function, which functions called
94 it, which other functions it called, and how many times. There is also
95 an estimate of how much time was spent in the subroutines of each
96 function. This can suggest places where you might try to eliminate
97 function calls that use a lot of time. *Note Call Graph::.
99 The "annotated source" listing is a copy of the program's source
100 code, labeled with the number of times each line of the program was
101 executed. *Note Annotated Source::.
103 To better understand how profiling works, you may wish to read a
104 description of its implementation. *Note Implementation::.
107 File: gprof.info, Node: Compiling, Next: Executing, Prev: Introduction, Up: Top
109 Compiling a Program for Profiling
110 *********************************
112 The first step in generating profile information for your program is
113 to compile and link it with profiling enabled.
115 To compile a source file for profiling, specify the `-pg' option when
116 you run the compiler. (This is in addition to the options you normally
119 To link the program for profiling, if you use a compiler such as `cc'
120 to do the linking, simply specify `-pg' in addition to your usual
121 options. The same option, `-pg', alters either compilation or linking
122 to do what is necessary for profiling. Here are examples:
124 cc -g -c myprog.c utils.c -pg
125 cc -o myprog myprog.o utils.o -pg
127 The `-pg' option also works with a command that both compiles and
130 cc -o myprog myprog.c utils.c -g -pg
132 Note: The `-pg' option must be part of your compilation options as
133 well as your link options. If it is not then no call-graph data will
134 be gathered and when you run `gprof' you will get an error message like
137 gprof: gmon.out file is missing call-graph data
139 If you add the `-Q' switch to suppress the printing of the call
140 graph data you will still be able to see the time samples:
144 Each sample counts as 0.01 seconds.
145 % cumulative self self total
146 time seconds seconds calls Ts/call Ts/call name
147 44.12 0.07 0.07 zazLoop
149 20.59 0.17 0.04 bazMillion
151 % the percentage of the total running time of the
153 If you run the linker `ld' directly instead of through a compiler
154 such as `cc', you may have to specify a profiling startup file
155 `gcrt0.o' as the first input file instead of the usual startup file
156 `crt0.o'. In addition, you would probably want to specify the
157 profiling C library, `libc_p.a', by writing `-lc_p' instead of the
158 usual `-lc'. This is not absolutely necessary, but doing this gives
159 you number-of-calls information for standard library functions such as
160 `read' and `open'. For example:
162 ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p
164 If you compile only some of the modules of the program with `-pg',
165 you can still profile the program, but you won't get complete
166 information about the modules that were compiled without `-pg'. The
167 only information you get for the functions in those modules is the
168 total time spent in them; there is no record of how many times they
169 were called, or from where. This will not affect the flat profile
170 (except that the `calls' field for the functions will be blank), but
171 will greatly reduce the usefulness of the call graph.
173 If you wish to perform line-by-line profiling, you will also need to
174 specify the `-g' option, instructing the compiler to insert debugging
175 symbols into the program that match program addresses to source code
176 lines. *Note Line-by-line::.
178 In addition to the `-pg' and `-g' options, older versions of GCC
179 required you to specify the `-a' option when compiling in order to
180 instrument it to perform basic-block counting. Newer versions do not
181 require this option and will not accept it; basic-block counting is
182 always enabled when `-pg' is on.
184 When basic-block counting is enabled, as the program runs it will
185 count how many times it executed each branch of each `if' statement,
186 each iteration of each `do' loop, etc. This will enable `gprof' to
187 construct an annotated source code listing showing how many times each
188 line of code was executed.
190 It also worth noting that GCC supports a different profiling method
191 which is enabled by the `-fprofile-arcs', `-ftest-coverage' and
192 `-fprofile-values' switches. These switches do not produce data which
193 is useful to `gprof' however, so they are not discussed further here.
194 There is also the `-finstrument-functions' switch which will cause GCC
195 to insert calls to special user supplied instrumentation routines at
196 the entry and exit of every function in their program. This can be
197 used to implement an alternative profiling scheme.
200 File: gprof.info, Node: Executing, Next: Invoking, Prev: Compiling, Up: Top
202 Executing the Program
203 *********************
205 Once the program is compiled for profiling, you must run it in order
206 to generate the information that `gprof' needs. Simply run the program
207 as usual, using the normal arguments, file names, etc. The program
208 should run normally, producing the same output as usual. It will,
209 however, run somewhat slower than normal because of the time spent
210 collecting and the writing the profile data.
212 The way you run the program--the arguments and input that you give
213 it--may have a dramatic effect on what the profile information shows.
214 The profile data will describe the parts of the program that were
215 activated for the particular input you use. For example, if the first
216 command you give to your program is to quit, the profile data will show
217 the time used in initialization and in cleanup, but not much else.
219 Your program will write the profile data into a file called
220 `gmon.out' just before exiting. If there is already a file called
221 `gmon.out', its contents are overwritten. There is currently no way to
222 tell the program to write the profile data under a different name, but
223 you can rename the file afterwards if you are concerned that it may be
226 In order to write the `gmon.out' file properly, your program must
227 exit normally: by returning from `main' or by calling `exit'. Calling
228 the low-level function `_exit' does not write the profile data, and
229 neither does abnormal termination due to an unhandled signal.
231 The `gmon.out' file is written in the program's _current working
232 directory_ at the time it exits. This means that if your program calls
233 `chdir', the `gmon.out' file will be left in the last directory your
234 program `chdir''d to. If you don't have permission to write in this
235 directory, the file is not written, and you will get an error message.
237 Older versions of the GNU profiling library may also write a file
238 called `bb.out'. This file, if present, contains an human-readable
239 listing of the basic-block execution counts. Unfortunately, the
240 appearance of a human-readable `bb.out' means the basic-block counts
241 didn't get written into `gmon.out'. The Perl script `bbconv.pl',
242 included with the `gprof' source distribution, will convert a `bb.out'
243 file into a format readable by `gprof'. Invoke it like this:
245 bbconv.pl < bb.out > BH-DATA
247 This translates the information in `bb.out' into a form that `gprof'
248 can understand. But you still need to tell `gprof' about the existence
249 of this translated information. To do that, include BB-DATA on the
250 `gprof' command line, _along with `gmon.out'_, like this:
252 gprof OPTIONS EXECUTABLE-FILE gmon.out BB-DATA [YET-MORE-PROFILE-DATA-FILES...] [> OUTFILE]
255 File: gprof.info, Node: Invoking, Next: Output, Prev: Executing, Up: Top
257 `gprof' Command Summary
258 ***********************
260 After you have a profile data file `gmon.out', you can run `gprof'
261 to interpret the information in it. The `gprof' program prints a flat
262 profile and a call graph on standard output. Typically you would
263 redirect the output of `gprof' into a file with `>'.
265 You run `gprof' like this:
267 gprof OPTIONS [EXECUTABLE-FILE [PROFILE-DATA-FILES...]] [> OUTFILE]
269 Here square-brackets indicate optional arguments.
271 If you omit the executable file name, the file `a.out' is used. If
272 you give no profile data file name, the file `gmon.out' is used. If
273 any file is not in the proper format, or if the profile data file does
274 not appear to belong to the executable file, an error message is
277 You can give more than one profile data file by entering all their
278 names after the executable file name; then the statistics in all the
279 data files are summed together.
281 The order of these options does not matter.
285 * Output Options:: Controlling `gprof''s output style
286 * Analysis Options:: Controlling how `gprof' analyses its data
287 * Miscellaneous Options::
288 * Deprecated Options:: Options you no longer need to use, but which
289 have been retained for compatibility
290 * Symspecs:: Specifying functions to include or exclude
293 File: gprof.info, Node: Output Options, Next: Analysis Options, Up: Invoking
298 These options specify which of several output formats `gprof' should
301 Many of these options take an optional "symspec" to specify
302 functions to be included or excluded. These options can be specified
303 multiple times, with different symspecs, to include or exclude sets of
304 symbols. *Note Symspecs::.
306 Specifying any of these options overrides the default (`-p -q'),
307 which prints a flat profile and call graph analysis for all functions.
310 `--annotated-source[=SYMSPEC]'
311 The `-A' option causes `gprof' to print annotated source code. If
312 SYMSPEC is specified, print output only for matching symbols.
313 *Note Annotated Source::.
317 If the `-b' option is given, `gprof' doesn't print the verbose
318 blurbs that try to explain the meaning of all of the fields in the
319 tables. This is useful if you intend to print out the output, or
320 are tired of seeing the blurbs.
323 `--exec-counts[=SYMSPEC]'
324 The `-C' option causes `gprof' to print a tally of functions and
325 the number of times each was called. If SYMSPEC is specified,
326 print tally only for matching symbols.
328 If the profile data file contains basic-block count records,
329 specifying the `-l' option, along with `-C', will cause basic-block
330 execution counts to be tallied and displayed.
334 The `-i' option causes `gprof' to display summary information
335 about the profile data file(s) and then exit. The number of
336 histogram, call graph, and basic-block count records is displayed.
339 `--directory-path=DIRS'
340 The `-I' option specifies a list of search directories in which to
341 find source files. Environment variable GPROF_PATH can also be
342 used to convey this information. Used mostly for annotated source
346 `--no-annotated-source[=SYMSPEC]'
347 The `-J' option causes `gprof' not to print annotated source code.
348 If SYMSPEC is specified, `gprof' prints annotated source, but
349 excludes matching symbols.
353 Normally, source filenames are printed with the path component
354 suppressed. The `-L' option causes `gprof' to print the full
355 pathname of source filenames, which is determined from symbolic
356 debugging information in the image file and is relative to the
357 directory in which the compiler was invoked.
360 `--flat-profile[=SYMSPEC]'
361 The `-p' option causes `gprof' to print a flat profile. If
362 SYMSPEC is specified, print flat profile only for matching symbols.
363 *Note Flat Profile::.
366 `--no-flat-profile[=SYMSPEC]'
367 The `-P' option causes `gprof' to suppress printing a flat profile.
368 If SYMSPEC is specified, `gprof' prints a flat profile, but
369 excludes matching symbols.
373 The `-q' option causes `gprof' to print the call graph analysis.
374 If SYMSPEC is specified, print call graph only for matching symbols
375 and their children. *Note Call Graph::.
378 `--no-graph[=SYMSPEC]'
379 The `-Q' option causes `gprof' to suppress printing the call graph.
380 If SYMSPEC is specified, `gprof' prints a call graph, but excludes
385 The `-t' option causes the NUM most active source lines in each
386 source file to be listed when source annotation is enabled. The
391 This option affects annotated source output only. Normally,
392 `gprof' prints annotated source files to standard-output. If this
393 option is specified, annotated source for a file named
394 `path/FILENAME' is generated in the file `FILENAME-ann'. If the
395 underlying filesystem would truncate `FILENAME-ann' so that it
396 overwrites the original `FILENAME', `gprof' generates annotated
397 source in the file `FILENAME.ann' instead (if the original file
398 name has an extension, that extension is _replaced_ with `.ann').
401 `--no-exec-counts[=SYMSPEC]'
402 The `-Z' option causes `gprof' not to print a tally of functions
403 and the number of times each was called. If SYMSPEC is specified,
404 print tally, but exclude matching symbols.
407 `--function-ordering'
408 The `--function-ordering' option causes `gprof' to print a
409 suggested function ordering for the program based on profiling
410 data. This option suggests an ordering which may improve paging,
411 tlb and cache behavior for the program on systems which support
412 arbitrary ordering of functions in an executable.
414 The exact details of how to force the linker to place functions in
415 a particular order is system dependent and out of the scope of this
419 `--file-ordering MAP_FILE'
420 The `--file-ordering' option causes `gprof' to print a suggested
421 .o link line ordering for the program based on profiling data.
422 This option suggests an ordering which may improve paging, tlb and
423 cache behavior for the program on systems which do not support
424 arbitrary ordering of functions in an executable.
426 Use of the `-a' argument is highly recommended with this option.
428 The MAP_FILE argument is a pathname to a file which provides
429 function name to object file mappings. The format of the file is
430 similar to the output of the program `nm'.
432 c-parse.o:00000000 T yyparse
433 c-parse.o:00000004 C yyerrflag
434 c-lang.o:00000000 T maybe_objc_method_name
435 c-lang.o:00000000 T print_lang_statistics
436 c-lang.o:00000000 T recognize_objc_keyword
437 c-decl.o:00000000 T print_lang_identifier
438 c-decl.o:00000000 T print_lang_type
441 To create a MAP_FILE with GNU `nm', type a command like `nm
442 --extern-only --defined-only -v --print-file-name program-name'.
446 The `-T' option causes `gprof' to print its output in
447 "traditional" BSD style.
451 Sets width of output lines to WIDTH. Currently only used when
452 printing the function index at the bottom of the call graph.
456 This option affects annotated source output only. By default,
457 only the lines at the beginning of a basic-block are annotated.
458 If this option is specified, every line in a basic-block is
459 annotated by repeating the annotation for the first line. This
460 behavior is similar to `tcov''s `-a'.
464 These options control whether C++ symbol names should be demangled
465 when printing output. The default is to demangle symbols. The
466 `--no-demangle' option may be used to turn off demangling.
467 Different compilers have different mangling styles. The optional
468 demangling style argument can be used to choose an appropriate
469 demangling style for your compiler.
472 File: gprof.info, Node: Analysis Options, Next: Miscellaneous Options, Prev: Output Options, Up: Invoking
479 The `-a' option causes `gprof' to suppress the printing of
480 statically declared (private) functions. (These are functions
481 whose names are not listed as global, and which are not visible
482 outside the file/function/block where they were defined.) Time
483 spent in these functions, calls to/from them, etc, will all be
484 attributed to the function that was loaded directly before it in
485 the executable file. This option affects both the flat profile
489 `--static-call-graph'
490 The `-c' option causes the call graph of the program to be
491 augmented by a heuristic which examines the text space of the
492 object file and identifies function calls in the binary machine
493 code. Since normal call graph records are only generated when
494 functions are entered, this option identifies children that could
495 have been called, but never were. Calls to functions that were
496 not compiled with profiling enabled are also identified, but only
497 if symbol table entries are present for them. Calls to dynamic
498 library routines are typically _not_ found by this option.
499 Parents or children identified via this heuristic are indicated in
500 the call graph with call counts of `0'.
503 `--ignore-non-functions'
504 The `-D' option causes `gprof' to ignore symbols which are not
505 known to be functions. This option will give more accurate
506 profile data on systems where it is supported (Solaris and HPUX for
510 The `-k' option allows you to delete from the call graph any arcs
511 from symbols matching symspec FROM to those matching symspec TO.
515 The `-l' option enables line-by-line profiling, which causes
516 histogram hits to be charged to individual source code lines,
517 instead of functions. If the program was compiled with
518 basic-block counting enabled, this option will also identify how
519 many times each line of code was executed. While line-by-line
520 profiling can help isolate where in a large function a program is
521 spending its time, it also significantly increases the running
522 time of `gprof', and magnifies statistical inaccuracies. *Note
527 This option affects execution count output only. Symbols that are
528 executed less than NUM times are suppressed.
532 The `-n' option causes `gprof', in its call graph analysis, to
533 only propagate times for symbols matching SYMSPEC.
536 `--no-time[=SYMSPEC]'
537 The `-n' option causes `gprof', in its call graph analysis, not to
538 propagate times for symbols matching SYMSPEC.
541 `--display-unused-functions'
542 If you give the `-z' option, `gprof' will mention all functions in
543 the flat profile, even those that were never called, and that had
544 no time spent in them. This is useful in conjunction with the
545 `-c' option for discovering which routines were never called.
548 File: gprof.info, Node: Miscellaneous Options, Next: Deprecated Options, Prev: Analysis Options, Up: Invoking
550 Miscellaneous Options
551 =====================
555 The `-d NUM' option specifies debugging options. If NUM is not
556 specified, enable all debugging. *Note Debugging::.
560 The `-h' option prints command line usage.
564 Selects the format of the profile data files. Recognized formats
565 are `auto' (the default), `bsd', `4.4bsd', `magic', and `prof'
570 The `-s' option causes `gprof' to summarize the information in the
571 profile data files it read in, and write out a profile data file
572 called `gmon.sum', which contains all the information from the
573 profile data files that `gprof' read in. The file `gmon.sum' may
574 be one of the specified input files; the effect of this is to
575 merge the data in the other input files into `gmon.sum'.
577 Eventually you can run `gprof' again without `-s' to analyze the
578 cumulative data in the file `gmon.sum'.
582 The `-v' flag causes `gprof' to print the current version number,
586 File: gprof.info, Node: Deprecated Options, Next: Symspecs, Prev: Miscellaneous Options, Up: Invoking
591 These options have been replaced with newer versions that use
595 The `-e FUNCTION' option tells `gprof' to not print information
596 about the function FUNCTION_NAME (and its children...) in the call
597 graph. The function will still be listed as a child of any
598 functions that call it, but its index number will be shown as
599 `[not printed]'. More than one `-e' option may be given; only one
600 FUNCTION_NAME may be indicated with each `-e' option.
603 The `-E FUNCTION' option works like the `-e' option, but time
604 spent in the function (and children who were not called from
605 anywhere else), will not be used to compute the
606 percentages-of-time for the call graph. More than one `-E' option
607 may be given; only one FUNCTION_NAME may be indicated with each
611 The `-f FUNCTION' option causes `gprof' to limit the call graph to
612 the function FUNCTION_NAME and its children (and their
613 children...). More than one `-f' option may be given; only one
614 FUNCTION_NAME may be indicated with each `-f' option.
617 The `-F FUNCTION' option works like the `-f' option, but only time
618 spent in the function and its children (and their children...)
619 will be used to determine total-time and percentages-of-time for
620 the call graph. More than one `-F' option may be given; only one
621 FUNCTION_NAME may be indicated with each `-F' option. The `-F'
622 option overrides the `-E' option.
624 Note that only one function can be specified with each `-e', `-E',
625 `-f' or `-F' option. To specify more than one function, use multiple
626 options. For example, this command:
628 gprof -e boring -f foo -f bar myprogram > gprof.output
630 lists in the call graph all functions that were reached from either
631 `foo' or `bar' and were not reachable from `boring'.
634 File: gprof.info, Node: Symspecs, Prev: Deprecated Options, Up: Invoking
639 Many of the output options allow functions to be included or excluded
640 using "symspecs" (symbol specifications), which observe the following
643 filename_containing_a_dot
644 | funcname_not_containing_a_dot
646 | ( [ any_filename ] `:' ( any_funcname | linenumber ) )
648 Here are some sample symspecs:
651 Selects everything in file `main.c'--the dot in the string tells
652 `gprof' to interpret the string as a filename, rather than as a
653 function name. To select a file whose name does not contain a
654 dot, a trailing colon should be specified. For example, `odd:' is
655 interpreted as the file named `odd'.
658 Selects all functions named `main'.
660 Note that there may be multiple instances of the same function name
661 because some of the definitions may be local (i.e., static).
662 Unless a function name is unique in a program, you must use the
663 colon notation explained below to specify a function from a
664 specific source file.
666 Sometimes, function names contain dots. In such cases, it is
667 necessary to add a leading colon to the name. For example,
668 `:.mul' selects function `.mul'.
670 In some object file formats, symbols have a leading underscore.
671 `gprof' will normally not print these underscores. When you name a
672 symbol in a symspec, you should type it exactly as `gprof' prints
673 it in its output. For example, if the compiler produces a symbol
674 `_main' from your `main' function, `gprof' still prints it as
675 `main' in its output, so you should use `main' in symspecs.
678 Selects function `main' in file `main.c'.
681 Selects line 134 in file `main.c'.
684 File: gprof.info, Node: Output, Next: Inaccuracy, Prev: Invoking, Up: Top
686 Interpreting `gprof''s Output
687 *****************************
689 `gprof' can produce several different output styles, the most
690 important of which are described below. The simplest output styles
691 (file information, execution count, and function and file ordering) are
692 not described here, but are documented with the respective options that
693 trigger them. *Note Output Options::.
697 * Flat Profile:: The flat profile shows how much time was spent
698 executing directly in each function.
699 * Call Graph:: The call graph shows which functions called which
700 others, and how much time each function used
701 when its subroutine calls are included.
702 * Line-by-line:: `gprof' can analyze individual source code lines
703 * Annotated Source:: The annotated source listing displays source code
704 labeled with execution counts
707 File: gprof.info, Node: Flat Profile, Next: Call Graph, Up: Output
712 The "flat profile" shows the total amount of time your program spent
713 executing each function. Unless the `-z' option is given, functions
714 with no apparent time spent in them, and no apparent calls to them, are
715 not mentioned. Note that if a function was not compiled for profiling,
716 and didn't run long enough to show up on the program counter histogram,
717 it will be indistinguishable from a function that was never called.
719 This is part of a flat profile for a small program:
723 Each sample counts as 0.01 seconds.
724 % cumulative self self total
725 time seconds seconds calls ms/call ms/call name
726 33.34 0.02 0.02 7208 0.00 0.00 open
727 16.67 0.03 0.01 244 0.04 0.12 offtime
728 16.67 0.04 0.01 8 1.25 1.25 memccpy
729 16.67 0.05 0.01 7 1.43 1.43 write
730 16.67 0.06 0.01 mcount
731 0.00 0.06 0.00 236 0.00 0.00 tzset
732 0.00 0.06 0.00 192 0.00 0.00 tolower
733 0.00 0.06 0.00 47 0.00 0.00 strlen
734 0.00 0.06 0.00 45 0.00 0.00 strchr
735 0.00 0.06 0.00 1 0.00 50.00 main
736 0.00 0.06 0.00 1 0.00 0.00 memcpy
737 0.00 0.06 0.00 1 0.00 10.11 print
738 0.00 0.06 0.00 1 0.00 0.00 profil
739 0.00 0.06 0.00 1 0.00 50.00 report
742 The functions are sorted by first by decreasing run-time spent in them,
743 then by decreasing number of calls, then alphabetically by name. The
744 functions `mcount' and `profil' are part of the profiling apparatus and
745 appear in every flat profile; their time gives a measure of the amount
746 of overhead due to profiling.
748 Just before the column headers, a statement appears indicating how
749 much time each sample counted as. This "sampling period" estimates the
750 margin of error in each of the time figures. A time figure that is not
751 much larger than this is not reliable. In this example, each sample
752 counted as 0.01 seconds, suggesting a 100 Hz sampling rate. The
753 program's total execution time was 0.06 seconds, as indicated by the
754 `cumulative seconds' field. Since each sample counted for 0.01
755 seconds, this means only six samples were taken during the run. Two of
756 the samples occurred while the program was in the `open' function, as
757 indicated by the `self seconds' field. Each of the other four samples
758 occurred one each in `offtime', `memccpy', `write', and `mcount'.
759 Since only six samples were taken, none of these values can be regarded
760 as particularly reliable. In another run, the `self seconds' field for
761 `mcount' might well be `0.00' or `0.02'. *Note Sampling Error::, for a
764 The remaining functions in the listing (those whose `self seconds'
765 field is `0.00') didn't appear in the histogram samples at all.
766 However, the call graph indicated that they were called, so therefore
767 they are listed, sorted in decreasing order by the `calls' field.
768 Clearly some time was spent executing these functions, but the paucity
769 of histogram samples prevents any determination of how much time each
772 Here is what the fields in each line mean:
775 This is the percentage of the total execution time your program
776 spent in this function. These should all add up to 100%.
779 This is the cumulative total number of seconds the computer spent
780 executing this functions, plus the time spent in all the functions
781 above this one in this table.
784 This is the number of seconds accounted for by this function alone.
785 The flat profile listing is sorted first by this number.
788 This is the total number of times the function was called. If the
789 function was never called, or the number of times it was called
790 cannot be determined (probably because the function was not
791 compiled with profiling enabled), the "calls" field is blank.
794 This represents the average number of milliseconds spent in this
795 function per call, if this function is profiled. Otherwise, this
796 field is blank for this function.
799 This represents the average number of milliseconds spent in this
800 function and its descendants per call, if this function is
801 profiled. Otherwise, this field is blank for this function. This
802 is the only field in the flat profile that uses call graph
806 This is the name of the function. The flat profile is sorted by
807 this field alphabetically after the "self seconds" and "calls"
811 File: gprof.info, Node: Call Graph, Next: Line-by-line, Prev: Flat Profile, Up: Output
816 The "call graph" shows how much time was spent in each function and
817 its children. From this information, you can find functions that,
818 while they themselves may not have used much time, called other
819 functions that did use unusual amounts of time.
821 Here is a sample call from a small program. This call came from the
822 same `gprof' run as the flat profile example in the previous chapter.
824 granularity: each sample hit covers 2 byte(s) for 20.00% of 0.05 seconds
826 index % time self children called name
828 [1] 100.0 0.00 0.05 start [1]
829 0.00 0.05 1/1 main [2]
830 0.00 0.00 1/2 on_exit [28]
831 0.00 0.00 1/1 exit [59]
832 -----------------------------------------------
833 0.00 0.05 1/1 start [1]
834 [2] 100.0 0.00 0.05 1 main [2]
835 0.00 0.05 1/1 report [3]
836 -----------------------------------------------
837 0.00 0.05 1/1 main [2]
838 [3] 100.0 0.00 0.05 1 report [3]
839 0.00 0.03 8/8 timelocal [6]
840 0.00 0.01 1/1 print [9]
841 0.00 0.01 9/9 fgets [12]
842 0.00 0.00 12/34 strncmp <cycle 1> [40]
843 0.00 0.00 8/8 lookup [20]
844 0.00 0.00 1/1 fopen [21]
845 0.00 0.00 8/8 chewtime [24]
846 0.00 0.00 8/16 skipspace [44]
847 -----------------------------------------------
848 [4] 59.8 0.01 0.02 8+472 <cycle 2 as a whole> [4]
849 0.01 0.02 244+260 offtime <cycle 2> [7]
850 0.00 0.00 236+1 tzset <cycle 2> [26]
851 -----------------------------------------------
853 The lines full of dashes divide this table into "entries", one for
854 each function. Each entry has one or more lines.
856 In each entry, the primary line is the one that starts with an index
857 number in square brackets. The end of this line says which function
858 the entry is for. The preceding lines in the entry describe the
859 callers of this function and the following lines describe its
860 subroutines (also called "children" when we speak of the call graph).
862 The entries are sorted by time spent in the function and its
865 The internal profiling function `mcount' (*note Flat Profile::) is
866 never mentioned in the call graph.
870 * Primary:: Details of the primary line's contents.
871 * Callers:: Details of caller-lines' contents.
872 * Subroutines:: Details of subroutine-lines' contents.
873 * Cycles:: When there are cycles of recursion,
874 such as `a' calls `b' calls `a'...
877 File: gprof.info, Node: Primary, Next: Callers, Up: Call Graph
882 The "primary line" in a call graph entry is the line that describes
883 the function which the entry is about and gives the overall statistics
886 For reference, we repeat the primary line from the entry for function
887 `report' in our main example, together with the heading line that shows
888 the names of the fields:
890 index % time self children called name
892 [3] 100.0 0.00 0.05 1 report [3]
894 Here is what the fields in the primary line mean:
897 Entries are numbered with consecutive integers. Each function
898 therefore has an index number, which appears at the beginning of
901 Each cross-reference to a function, as a caller or subroutine of
902 another, gives its index number as well as its name. The index
903 number guides you if you wish to look for the entry for that
907 This is the percentage of the total time that was spent in this
908 function, including time spent in subroutines called from this
911 The time spent in this function is counted again for the callers of
912 this function. Therefore, adding up these percentages is
916 This is the total amount of time spent in this function. This
917 should be identical to the number printed in the `seconds' field
918 for this function in the flat profile.
921 This is the total amount of time spent in the subroutine calls
922 made by this function. This should be equal to the sum of all the
923 `self' and `children' entries of the children listed directly
927 This is the number of times the function was called.
929 If the function called itself recursively, there are two numbers,
930 separated by a `+'. The first number counts non-recursive calls,
931 and the second counts recursive calls.
933 In the example above, the function `report' was called once from
937 This is the name of the current function. The index number is
940 If the function is part of a cycle of recursion, the cycle number
941 is printed between the function's name and the index number (*note
942 Cycles::). For example, if function `gnurr' is part of cycle
943 number one, and has index number twelve, its primary line would be
949 File: gprof.info, Node: Callers, Next: Subroutines, Prev: Primary, Up: Call Graph
951 Lines for a Function's Callers
952 ------------------------------
954 A function's entry has a line for each function it was called by.
955 These lines' fields correspond to the fields of the primary line, but
956 their meanings are different because of the difference in context.
958 For reference, we repeat two lines from the entry for the function
959 `report', the primary line and one caller-line preceding it, together
960 with the heading line that shows the names of the fields:
962 index % time self children called name
964 0.00 0.05 1/1 main [2]
965 [3] 100.0 0.00 0.05 1 report [3]
967 Here are the meanings of the fields in the caller-line for `report'
971 An estimate of the amount of time spent in `report' itself when it
972 was called from `main'.
975 An estimate of the amount of time spent in subroutines of `report'
976 when `report' was called from `main'.
978 The sum of the `self' and `children' fields is an estimate of the
979 amount of time spent within calls to `report' from `main'.
982 Two numbers: the number of times `report' was called from `main',
983 followed by the total number of non-recursive calls to `report'
984 from all its callers.
986 `name and index number'
987 The name of the caller of `report' to which this line applies,
988 followed by the caller's index number.
990 Not all functions have entries in the call graph; some options to
991 `gprof' request the omission of certain functions. When a caller
992 has no entry of its own, it still has caller-lines in the entries
993 of the functions it calls.
995 If the caller is part of a recursion cycle, the cycle number is
996 printed between the name and the index number.
998 If the identity of the callers of a function cannot be determined, a
999 dummy caller-line is printed which has `<spontaneous>' as the "caller's
1000 name" and all other fields blank. This can happen for signal handlers.
1003 File: gprof.info, Node: Subroutines, Next: Cycles, Prev: Callers, Up: Call Graph
1005 Lines for a Function's Subroutines
1006 ----------------------------------
1008 A function's entry has a line for each of its subroutines--in other
1009 words, a line for each other function that it called. These lines'
1010 fields correspond to the fields of the primary line, but their meanings
1011 are different because of the difference in context.
1013 For reference, we repeat two lines from the entry for the function
1014 `main', the primary line and a line for a subroutine, together with the
1015 heading line that shows the names of the fields:
1017 index % time self children called name
1019 [2] 100.0 0.00 0.05 1 main [2]
1020 0.00 0.05 1/1 report [3]
1022 Here are the meanings of the fields in the subroutine-line for `main'
1026 An estimate of the amount of time spent directly within `report'
1027 when `report' was called from `main'.
1030 An estimate of the amount of time spent in subroutines of `report'
1031 when `report' was called from `main'.
1033 The sum of the `self' and `children' fields is an estimate of the
1034 total time spent in calls to `report' from `main'.
1037 Two numbers, the number of calls to `report' from `main' followed
1038 by the total number of non-recursive calls to `report'. This
1039 ratio is used to determine how much of `report''s `self' and
1040 `children' time gets credited to `main'. *Note Assumptions::.
1043 The name of the subroutine of `main' to which this line applies,
1044 followed by the subroutine's index number.
1046 If the caller is part of a recursion cycle, the cycle number is
1047 printed between the name and the index number.
1050 File: gprof.info, Node: Cycles, Prev: Subroutines, Up: Call Graph
1052 How Mutually Recursive Functions Are Described
1053 ----------------------------------------------
1055 The graph may be complicated by the presence of "cycles of
1056 recursion" in the call graph. A cycle exists if a function calls
1057 another function that (directly or indirectly) calls (or appears to
1058 call) the original function. For example: if `a' calls `b', and `b'
1059 calls `a', then `a' and `b' form a cycle.
1061 Whenever there are call paths both ways between a pair of functions,
1062 they belong to the same cycle. If `a' and `b' call each other and `b'
1063 and `c' call each other, all three make one cycle. Note that even if
1064 `b' only calls `a' if it was not called from `a', `gprof' cannot
1065 determine this, so `a' and `b' are still considered a cycle.
1067 The cycles are numbered with consecutive integers. When a function
1068 belongs to a cycle, each time the function name appears in the call
1069 graph it is followed by `<cycle NUMBER>'.
1071 The reason cycles matter is that they make the time values in the
1072 call graph paradoxical. The "time spent in children" of `a' should
1073 include the time spent in its subroutine `b' and in `b''s
1074 subroutines--but one of `b''s subroutines is `a'! How much of `a''s
1075 time should be included in the children of `a', when `a' is indirectly
1078 The way `gprof' resolves this paradox is by creating a single entry
1079 for the cycle as a whole. The primary line of this entry describes the
1080 total time spent directly in the functions of the cycle. The
1081 "subroutines" of the cycle are the individual functions of the cycle,
1082 and all other functions that were called directly by them. The
1083 "callers" of the cycle are the functions, outside the cycle, that
1084 called functions in the cycle.
1086 Here is an example portion of a call graph which shows a cycle
1087 containing functions `a' and `b'. The cycle was entered by a call to
1088 `a' from `main'; both `a' and `b' called `c'.
1090 index % time self children called name
1091 ----------------------------------------
1093 [3] 91.71 1.77 0 1+5 <cycle 1 as a whole> [3]
1094 1.02 0 3 b <cycle 1> [4]
1095 0.75 0 2 a <cycle 1> [5]
1096 ----------------------------------------
1098 [4] 52.85 1.02 0 0 b <cycle 1> [4]
1101 ----------------------------------------
1104 [5] 38.86 0.75 0 1 a <cycle 1> [5]
1107 ----------------------------------------
1109 (The entire call graph for this program contains in addition an entry
1110 for `main', which calls `a', and an entry for `c', with callers `a' and
1113 index % time self children called name
1115 [1] 100.00 0 1.93 0 start [1]
1116 0.16 1.77 1/1 main [2]
1117 ----------------------------------------
1118 0.16 1.77 1/1 start [1]
1119 [2] 100.00 0.16 1.77 1 main [2]
1120 1.77 0 1/1 a <cycle 1> [5]
1121 ----------------------------------------
1123 [3] 91.71 1.77 0 1+5 <cycle 1 as a whole> [3]
1124 1.02 0 3 b <cycle 1> [4]
1125 0.75 0 2 a <cycle 1> [5]
1127 ----------------------------------------
1129 [4] 52.85 1.02 0 0 b <cycle 1> [4]
1132 ----------------------------------------
1135 [5] 38.86 0.75 0 1 a <cycle 1> [5]
1138 ----------------------------------------
1139 0 0 3/6 b <cycle 1> [4]
1140 0 0 3/6 a <cycle 1> [5]
1141 [6] 0.00 0 0 6 c [6]
1142 ----------------------------------------
1144 The `self' field of the cycle's primary line is the total time spent
1145 in all the functions of the cycle. It equals the sum of the `self'
1146 fields for the individual functions in the cycle, found in the entry in
1147 the subroutine lines for these functions.
1149 The `children' fields of the cycle's primary line and subroutine
1150 lines count only subroutines outside the cycle. Even though `a' calls
1151 `b', the time spent in those calls to `b' is not counted in `a''s
1152 `children' time. Thus, we do not encounter the problem of what to do
1153 when the time in those calls to `b' includes indirect recursive calls
1156 The `children' field of a caller-line in the cycle's entry estimates
1157 the amount of time spent _in the whole cycle_, and its other
1158 subroutines, on the times when that caller called a function in the
1161 The `calls' field in the primary line for the cycle has two numbers:
1162 first, the number of times functions in the cycle were called by
1163 functions outside the cycle; second, the number of times they were
1164 called by functions in the cycle (including times when a function in
1165 the cycle calls itself). This is a generalization of the usual split
1166 into non-recursive and recursive calls.
1168 The `calls' field of a subroutine-line for a cycle member in the
1169 cycle's entry says how many time that function was called from
1170 functions in the cycle. The total of all these is the second number in
1171 the primary line's `calls' field.
1173 In the individual entry for a function in a cycle, the other
1174 functions in the same cycle can appear as subroutines and as callers.
1175 These lines show how many times each function in the cycle called or
1176 was called from each other function in the cycle. The `self' and
1177 `children' fields in these lines are blank because of the difficulty of
1178 defining meanings for them when recursion is going on.
1181 File: gprof.info, Node: Line-by-line, Next: Annotated Source, Prev: Call Graph, Up: Output
1183 Line-by-line Profiling
1184 ======================
1186 `gprof''s `-l' option causes the program to perform "line-by-line"
1187 profiling. In this mode, histogram samples are assigned not to
1188 functions, but to individual lines of source code. The program usually
1189 must be compiled with a `-g' option, in addition to `-pg', in order to
1190 generate debugging symbols for tracking source code lines.
1192 The flat profile is the most useful output table in line-by-line
1193 mode. The call graph isn't as useful as normal, since the current
1194 version of `gprof' does not propagate call graph arcs from source code
1195 lines to the enclosing function. The call graph does, however, show
1196 each line of code that called each function, along with a count.
1198 Here is a section of `gprof''s output, without line-by-line
1199 profiling. Note that `ct_init' accounted for four histogram hits, and
1200 13327 calls to `init_block'.
1204 Each sample counts as 0.01 seconds.
1205 % cumulative self self total
1206 time seconds seconds calls us/call us/call name
1207 30.77 0.13 0.04 6335 6.31 6.31 ct_init
1210 Call graph (explanation follows)
1213 granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
1215 index % time self children called name
1217 0.00 0.00 1/13496 name_too_long
1218 0.00 0.00 40/13496 deflate
1219 0.00 0.00 128/13496 deflate_fast
1220 0.00 0.00 13327/13496 ct_init
1221 [7] 0.0 0.00 0.00 13496 init_block
1223 Now let's look at some of `gprof''s output from the same program run,
1224 this time with line-by-line profiling enabled. Note that `ct_init''s
1225 four histogram hits are broken down into four lines of source code -
1226 one hit occurred on each of lines 349, 351, 382 and 385. In the call
1227 graph, note how `ct_init''s 13327 calls to `init_block' are broken down
1228 into one call from line 396, 3071 calls from line 384, 3730 calls from
1229 line 385, and 6525 calls from 387.
1233 Each sample counts as 0.01 seconds.
1235 time seconds seconds calls name
1236 7.69 0.10 0.01 ct_init (trees.c:349)
1237 7.69 0.11 0.01 ct_init (trees.c:351)
1238 7.69 0.12 0.01 ct_init (trees.c:382)
1239 7.69 0.13 0.01 ct_init (trees.c:385)
1242 Call graph (explanation follows)
1245 granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
1247 % time self children called name
1249 0.00 0.00 1/13496 name_too_long (gzip.c:1440)
1250 0.00 0.00 1/13496 deflate (deflate.c:763)
1251 0.00 0.00 1/13496 ct_init (trees.c:396)
1252 0.00 0.00 2/13496 deflate (deflate.c:727)
1253 0.00 0.00 4/13496 deflate (deflate.c:686)
1254 0.00 0.00 5/13496 deflate (deflate.c:675)
1255 0.00 0.00 12/13496 deflate (deflate.c:679)
1256 0.00 0.00 16/13496 deflate (deflate.c:730)
1257 0.00 0.00 128/13496 deflate_fast (deflate.c:654)
1258 0.00 0.00 3071/13496 ct_init (trees.c:384)
1259 0.00 0.00 3730/13496 ct_init (trees.c:385)
1260 0.00 0.00 6525/13496 ct_init (trees.c:387)
1261 [6] 0.0 0.00 0.00 13496 init_block (trees.c:408)
1264 File: gprof.info, Node: Annotated Source, Prev: Line-by-line, Up: Output
1266 The Annotated Source Listing
1267 ============================
1269 `gprof''s `-A' option triggers an annotated source listing, which
1270 lists the program's source code, each function labeled with the number
1271 of times it was called. You may also need to specify the `-I' option,
1272 if `gprof' can't find the source code files.
1274 Compiling with `gcc ... -g -pg -a' augments your program with
1275 basic-block counting code, in addition to function counting code. This
1276 enables `gprof' to determine how many times each line of code was
1277 executed. For example, consider the following function, taken from
1278 gzip, with line numbers added:
1286 7 static ulg crc = (ulg)0xffffffffL;
1293 14 c = crc_32_tab[...];
1297 18 return c ^ 0xffffffffL;
1300 `updcrc' has at least five basic-blocks. One is the function
1301 itself. The `if' statement on line 9 generates two more basic-blocks,
1302 one for each branch of the `if'. A fourth basic-block results from the
1303 `if' on line 13, and the contents of the `do' loop form the fifth
1304 basic-block. The compiler may also generate additional basic-blocks to
1305 handle various special cases.
1307 A program augmented for basic-block counting can be analyzed with
1308 `gprof -l -A'. I also suggest use of the `-x' option, which ensures
1309 that each line of code is labeled at least once. Here is `updcrc''s
1310 annotated source listing for a sample `gzip' run:
1318 static ulg crc = (ulg)0xffffffffL;
1320 2 -> if (s == NULL) {
1321 1 -> c = 0xffffffffL;
1325 26312 -> c = crc_32_tab[...];
1326 26312,1,26311 -> } while (--n);
1329 2 -> return c ^ 0xffffffffL;
1332 In this example, the function was called twice, passing once through
1333 each branch of the `if' statement. The body of the `do' loop was
1334 executed a total of 26312 times. Note how the `while' statement is
1335 annotated. It began execution 26312 times, once for each iteration
1336 through the loop. One of those times (the last time) it exited, while
1337 it branched back to the beginning of the loop 26311 times.
1340 File: gprof.info, Node: Inaccuracy, Next: How do I?, Prev: Output, Up: Top
1342 Inaccuracy of `gprof' Output
1343 ****************************
1347 * Sampling Error:: Statistical margins of error
1348 * Assumptions:: Estimating children times
1351 File: gprof.info, Node: Sampling Error, Next: Assumptions, Up: Inaccuracy
1353 Statistical Sampling Error
1354 ==========================
1356 The run-time figures that `gprof' gives you are based on a sampling
1357 process, so they are subject to statistical inaccuracy. If a function
1358 runs only a small amount of time, so that on the average the sampling
1359 process ought to catch that function in the act only once, there is a
1360 pretty good chance it will actually find that function zero times, or
1363 By contrast, the number-of-calls and basic-block figures are derived
1364 by counting, not sampling. They are completely accurate and will not
1365 vary from run to run if your program is deterministic.
1367 The "sampling period" that is printed at the beginning of the flat
1368 profile says how often samples are taken. The rule of thumb is that a
1369 run-time figure is accurate if it is considerably bigger than the
1372 The actual amount of error can be predicted. For N samples, the
1373 _expected_ error is the square-root of N. For example, if the sampling
1374 period is 0.01 seconds and `foo''s run-time is 1 second, N is 100
1375 samples (1 second/0.01 seconds), sqrt(N) is 10 samples, so the expected
1376 error in `foo''s run-time is 0.1 seconds (10*0.01 seconds), or ten
1377 percent of the observed value. Again, if the sampling period is 0.01
1378 seconds and `bar''s run-time is 100 seconds, N is 10000 samples,
1379 sqrt(N) is 100 samples, so the expected error in `bar''s run-time is 1
1380 second, or one percent of the observed value. It is likely to vary
1381 this much _on the average_ from one profiling run to the next.
1382 (_Sometimes_ it will vary more.)
1384 This does not mean that a small run-time figure is devoid of
1385 information. If the program's _total_ run-time is large, a small
1386 run-time for one function does tell you that that function used an
1387 insignificant fraction of the whole program's time. Usually this means
1388 it is not worth optimizing.
1390 One way to get more accuracy is to give your program more (but
1391 similar) input data so it will take longer. Another way is to combine
1392 the data from several runs, using the `-s' option of `gprof'. Here is
1395 1. Run your program once.
1397 2. Issue the command `mv gmon.out gmon.sum'.
1399 3. Run your program again, the same as before.
1401 4. Merge the new data in `gmon.out' into `gmon.sum' with this command:
1403 gprof -s EXECUTABLE-FILE gmon.out gmon.sum
1405 5. Repeat the last two steps as often as you wish.
1407 6. Analyze the cumulative data using this command:
1409 gprof EXECUTABLE-FILE gmon.sum > OUTPUT-FILE
1412 File: gprof.info, Node: Assumptions, Prev: Sampling Error, Up: Inaccuracy
1414 Estimating `children' Times
1415 ===========================
1417 Some of the figures in the call graph are estimates--for example, the
1418 `children' time values and all the time figures in caller and
1421 There is no direct information about these measurements in the
1422 profile data itself. Instead, `gprof' estimates them by making an
1423 assumption about your program that might or might not be true.
1425 The assumption made is that the average time spent in each call to
1426 any function `foo' is not correlated with who called `foo'. If `foo'
1427 used 5 seconds in all, and 2/5 of the calls to `foo' came from `a',
1428 then `foo' contributes 2 seconds to `a''s `children' time, by
1431 This assumption is usually true enough, but for some programs it is
1432 far from true. Suppose that `foo' returns very quickly when its
1433 argument is zero; suppose that `a' always passes zero as an argument,
1434 while other callers of `foo' pass other arguments. In this program,
1435 all the time spent in `foo' is in the calls from callers other than `a'.
1436 But `gprof' has no way of knowing this; it will blindly and incorrectly
1437 charge 2 seconds of time in `foo' to the children of `a'.
1439 We hope some day to put more complete data into `gmon.out', so that
1440 this assumption is no longer needed, if we can figure out how. For the
1441 nonce, the estimated figures are usually more useful than misleading.
1444 File: gprof.info, Node: How do I?, Next: Incompatibilities, Prev: Inaccuracy, Up: Top
1446 Answers to Common Questions
1447 ***************************
1449 How can I get more exact information about hot spots in my program?
1450 Looking at the per-line call counts only tells part of the story.
1451 Because `gprof' can only report call times and counts by function,
1452 the best way to get finer-grained information on where the program
1453 is spending its time is to re-factor large functions into sequences
1454 of calls to smaller ones. Beware however that this can introduce
1455 artifical hot spots since compiling with `-pg' adds a significant
1456 overhead to function calls. An alternative solution is to use a
1457 non-intrusive profiler, e.g. oprofile.
1459 How do I find which lines in my program were executed the most times?
1460 Compile your program with basic-block counting enabled, run it,
1461 then use the following pipeline:
1463 gprof -l -C OBJFILE | sort -k 3 -n -r
1465 This listing will show you the lines in your code executed most
1466 often, but not necessarily those that consumed the most time.
1468 How do I find which lines in my program called a particular function?
1469 Use `gprof -l' and lookup the function in the call graph. The
1470 callers will be broken down by function and line number.
1472 How do I analyze a program that runs for less than a second?
1473 Try using a shell script like this one:
1475 for i in `seq 1 100`; do
1477 mv gmon.out gmon.out.$i
1480 gprof -s fastprog gmon.out.*
1482 gprof fastprog gmon.sum
1484 If your program is completely deterministic, all the call counts
1485 will be simple multiples of 100 (i.e. a function called once in
1486 each run will appear with a call count of 100).
1489 File: gprof.info, Node: Incompatibilities, Next: Details, Prev: How do I?, Up: Top
1491 Incompatibilities with Unix `gprof'
1492 ***********************************
1494 GNU `gprof' and Berkeley Unix `gprof' use the same data file
1495 `gmon.out', and provide essentially the same information. But there
1496 are a few differences.
1498 * GNU `gprof' uses a new, generalized file format with support for
1499 basic-block execution counts and non-realtime histograms. A magic
1500 cookie and version number allows `gprof' to easily identify new
1501 style files. Old BSD-style files can still be read. *Note File
1504 * For a recursive function, Unix `gprof' lists the function as a
1505 parent and as a child, with a `calls' field that lists the number
1506 of recursive calls. GNU `gprof' omits these lines and puts the
1507 number of recursive calls in the primary line.
1509 * When a function is suppressed from the call graph with `-e', GNU
1510 `gprof' still lists it as a subroutine of functions that call it.
1512 * GNU `gprof' accepts the `-k' with its argument in the form
1513 `from/to', instead of `from to'.
1515 * In the annotated source listing, if there are multiple basic
1516 blocks on the same line, GNU `gprof' prints all of their counts,
1517 separated by commas.
1519 * The blurbs, field widths, and output formats are different. GNU
1520 `gprof' prints blurbs after the tables, so that you can see the
1521 tables without skipping the blurbs.
1524 File: gprof.info, Node: Details, Next: GNU Free Documentation License, Prev: Incompatibilities, Up: Top
1526 Details of Profiling
1527 ********************
1531 * Implementation:: How a program collects profiling information
1532 * File Format:: Format of `gmon.out' files
1533 * Internals:: `gprof''s internal operation
1534 * Debugging:: Using `gprof''s `-d' option
1537 File: gprof.info, Node: Implementation, Next: File Format, Up: Details
1539 Implementation of Profiling
1540 ===========================
1542 Profiling works by changing how every function in your program is
1543 compiled so that when it is called, it will stash away some information
1544 about where it was called from. From this, the profiler can figure out
1545 what function called it, and can count how many times it was called.
1546 This change is made by the compiler when your program is compiled with
1547 the `-pg' option, which causes every function to call `mcount' (or
1548 `_mcount', or `__mcount', depending on the OS and compiler) as one of
1549 its first operations.
1551 The `mcount' routine, included in the profiling library, is
1552 responsible for recording in an in-memory call graph table both its
1553 parent routine (the child) and its parent's parent. This is typically
1554 done by examining the stack frame to find both the address of the
1555 child, and the return address in the original parent. Since this is a
1556 very machine-dependent operation, `mcount' itself is typically a short
1557 assembly-language stub routine that extracts the required information,
1558 and then calls `__mcount_internal' (a normal C function) with two
1559 arguments - `frompc' and `selfpc'. `__mcount_internal' is responsible
1560 for maintaining the in-memory call graph, which records `frompc',
1561 `selfpc', and the number of times each of these call arcs was traversed.
1563 GCC Version 2 provides a magical function
1564 (`__builtin_return_address'), which allows a generic `mcount' function
1565 to extract the required information from the stack frame. However, on
1566 some architectures, most notably the SPARC, using this builtin can be
1567 very computationally expensive, and an assembly language version of
1568 `mcount' is used for performance reasons.
1570 Number-of-calls information for library routines is collected by
1571 using a special version of the C library. The programs in it are the
1572 same as in the usual C library, but they were compiled with `-pg'. If
1573 you link your program with `gcc ... -pg', it automatically uses the
1574 profiling version of the library.
1576 Profiling also involves watching your program as it runs, and
1577 keeping a histogram of where the program counter happens to be every
1578 now and then. Typically the program counter is looked at around 100
1579 times per second of run time, but the exact frequency may vary from
1582 This is done is one of two ways. Most UNIX-like operating systems
1583 provide a `profil()' system call, which registers a memory array with
1584 the kernel, along with a scale factor that determines how the program's
1585 address space maps into the array. Typical scaling values cause every
1586 2 to 8 bytes of address space to map into a single array slot. On
1587 every tick of the system clock (assuming the profiled program is
1588 running), the value of the program counter is examined and the
1589 corresponding slot in the memory array is incremented. Since this is
1590 done in the kernel, which had to interrupt the process anyway to handle
1591 the clock interrupt, very little additional system overhead is required.
1593 However, some operating systems, most notably Linux 2.0 (and
1594 earlier), do not provide a `profil()' system call. On such a system,
1595 arrangements are made for the kernel to periodically deliver a signal
1596 to the process (typically via `setitimer()'), which then performs the
1597 same operation of examining the program counter and incrementing a slot
1598 in the memory array. Since this method requires a signal to be
1599 delivered to user space every time a sample is taken, it uses
1600 considerably more overhead than kernel-based profiling. Also, due to
1601 the added delay required to deliver the signal, this method is less
1604 A special startup routine allocates memory for the histogram and
1605 either calls `profil()' or sets up a clock signal handler. This
1606 routine (`monstartup') can be invoked in several ways. On Linux
1607 systems, a special profiling startup file `gcrt0.o', which invokes
1608 `monstartup' before `main', is used instead of the default `crt0.o'.
1609 Use of this special startup file is one of the effects of using `gcc
1610 ... -pg' to link. On SPARC systems, no special startup files are used.
1611 Rather, the `mcount' routine, when it is invoked for the first time
1612 (typically when `main' is called), calls `monstartup'.
1614 If the compiler's `-a' option was used, basic-block counting is also
1615 enabled. Each object file is then compiled with a static array of
1616 counts, initially zero. In the executable code, every time a new
1617 basic-block begins (i.e. when an `if' statement appears), an extra
1618 instruction is inserted to increment the corresponding count in the
1619 array. At compile time, a paired array was constructed that recorded
1620 the starting address of each basic-block. Taken together, the two
1621 arrays record the starting address of every basic-block, along with the
1622 number of times it was executed.
1624 The profiling library also includes a function (`mcleanup') which is
1625 typically registered using `atexit()' to be called as the program
1626 exits, and is responsible for writing the file `gmon.out'. Profiling
1627 is turned off, various headers are output, and the histogram is
1628 written, followed by the call-graph arcs and the basic-block counts.
1630 The output from `gprof' gives no indication of parts of your program
1631 that are limited by I/O or swapping bandwidth. This is because samples
1632 of the program counter are taken at fixed intervals of the program's
1633 run time. Therefore, the time measurements in `gprof' output say
1634 nothing about time that your program was not running. For example, a
1635 part of the program that creates so much data that it cannot all fit in
1636 physical memory at once may run very slowly due to thrashing, but
1637 `gprof' will say it uses little time. On the other hand, sampling by
1638 run time has the advantage that the amount of load due to other users
1639 won't directly affect the output you get.
1642 File: gprof.info, Node: File Format, Next: Internals, Prev: Implementation, Up: Details
1644 Profiling Data File Format
1645 ==========================
1647 The old BSD-derived file format used for profile data does not
1648 contain a magic cookie that allows to check whether a data file really
1649 is a `gprof' file. Furthermore, it does not provide a version number,
1650 thus rendering changes to the file format almost impossible. GNU
1651 `gprof' uses a new file format that provides these features. For
1652 backward compatibility, GNU `gprof' continues to support the old
1653 BSD-derived format, but not all features are supported with it. For
1654 example, basic-block execution counts cannot be accommodated by the old
1657 The new file format is defined in header file `gmon_out.h'. It
1658 consists of a header containing the magic cookie and a version number,
1659 as well as some spare bytes available for future extensions. All data
1660 in a profile data file is in the native format of the target for which
1661 the profile was collected. GNU `gprof' adapts automatically to the
1664 In the new file format, the header is followed by a sequence of
1665 records. Currently, there are three different record types: histogram
1666 records, call-graph arc records, and basic-block execution count
1667 records. Each file can contain any number of each record type. When
1668 reading a file, GNU `gprof' will ensure records of the same type are
1669 compatible with each other and compute the union of all records. For
1670 example, for basic-block execution counts, the union is simply the sum
1671 of all execution counts for each basic-block.
1676 Histogram records consist of a header that is followed by an array of
1677 bins. The header contains the text-segment range that the histogram
1678 spans, the size of the histogram in bytes (unlike in the old BSD
1679 format, this does not include the size of the header), the rate of the
1680 profiling clock, and the physical dimension that the bin counts
1681 represent after being scaled by the profiling clock rate. The physical
1682 dimension is specified in two parts: a long name of up to 15 characters
1683 and a single character abbreviation. For example, a histogram
1684 representing real-time would specify the long name as "seconds" and the
1685 abbreviation as "s". This feature is useful for architectures that
1686 support performance monitor hardware (which, fortunately, is becoming
1687 increasingly common). For example, under DEC OSF/1, the "uprofile"
1688 command can be used to produce a histogram of, say, instruction cache
1689 misses. In this case, the dimension in the histogram header could be
1690 set to "i-cache misses" and the abbreviation could be set to "1"
1691 (because it is simply a count, not a physical dimension). Also, the
1692 profiling rate would have to be set to 1 in this case.
1694 Histogram bins are 16-bit numbers and each bin represent an equal
1695 amount of text-space. For example, if the text-segment is one thousand
1696 bytes long and if there are ten bins in the histogram, each bin
1697 represents one hundred bytes.
1702 Call-graph records have a format that is identical to the one used in
1703 the BSD-derived file format. It consists of an arc in the call graph
1704 and a count indicating the number of times the arc was traversed during
1705 program execution. Arcs are specified by a pair of addresses: the
1706 first must be within caller's function and the second must be within
1707 the callee's function. When performing profiling at the function
1708 level, these addresses can point anywhere within the respective
1709 function. However, when profiling at the line-level, it is better if
1710 the addresses are as close to the call-site/entry-point as possible.
1711 This will ensure that the line-level call-graph is able to identify
1712 exactly which line of source code performed calls to a function.
1714 Basic-Block Execution Count Records
1715 -----------------------------------
1717 Basic-block execution count records consist of a header followed by a
1718 sequence of address/count pairs. The header simply specifies the
1719 length of the sequence. In an address/count pair, the address
1720 identifies a basic-block and the count specifies the number of times
1721 that basic-block was executed. Any address within the basic-address can
1725 File: gprof.info, Node: Internals, Next: Debugging, Prev: File Format, Up: Details
1727 `gprof''s Internal Operation
1728 ============================
1730 Like most programs, `gprof' begins by processing its options.
1731 During this stage, it may building its symspec list
1732 (`sym_ids.c:sym_id_add'), if options are specified which use symspecs.
1733 `gprof' maintains a single linked list of symspecs, which will
1734 eventually get turned into 12 symbol tables, organized into six
1735 include/exclude pairs - one pair each for the flat profile
1736 (INCL_FLAT/EXCL_FLAT), the call graph arcs (INCL_ARCS/EXCL_ARCS),
1737 printing in the call graph (INCL_GRAPH/EXCL_GRAPH), timing propagation
1738 in the call graph (INCL_TIME/EXCL_TIME), the annotated source listing
1739 (INCL_ANNO/EXCL_ANNO), and the execution count listing
1740 (INCL_EXEC/EXCL_EXEC).
1742 After option processing, `gprof' finishes building the symspec list
1743 by adding all the symspecs in `default_excluded_list' to the exclude
1744 lists EXCL_TIME and EXCL_GRAPH, and if line-by-line profiling is
1745 specified, EXCL_FLAT as well. These default excludes are not added to
1746 EXCL_ANNO, EXCL_ARCS, and EXCL_EXEC.
1748 Next, the BFD library is called to open the object file, verify that
1749 it is an object file, and read its symbol table (`core.c:core_init'),
1750 using `bfd_canonicalize_symtab' after mallocing an appropriately sized
1751 array of symbols. At this point, function mappings are read (if the
1752 `--file-ordering' option has been specified), and the core text space
1753 is read into memory (if the `-c' option was given).
1755 `gprof''s own symbol table, an array of Sym structures, is now built.
1756 This is done in one of two ways, by one of two routines, depending on
1757 whether line-by-line profiling (`-l' option) has been enabled. For
1758 normal profiling, the BFD canonical symbol table is scanned. For
1759 line-by-line profiling, every text space address is examined, and a new
1760 symbol table entry gets created every time the line number changes. In
1761 either case, two passes are made through the symbol table - one to
1762 count the size of the symbol table required, and the other to actually
1763 read the symbols. In between the two passes, a single array of type
1764 `Sym' is created of the appropriate length. Finally,
1765 `symtab.c:symtab_finalize' is called to sort the symbol table and
1766 remove duplicate entries (entries with the same memory address).
1768 The symbol table must be a contiguous array for two reasons. First,
1769 the `qsort' library function (which sorts an array) will be used to
1770 sort the symbol table. Also, the symbol lookup routine
1771 (`symtab.c:sym_lookup'), which finds symbols based on memory address,
1772 uses a binary search algorithm which requires the symbol table to be a
1773 sorted array. Function symbols are indicated with an `is_func' flag.
1774 Line number symbols have no special flags set. Additionally, a symbol
1775 can have an `is_static' flag to indicate that it is a local symbol.
1777 With the symbol table read, the symspecs can now be translated into
1778 Syms (`sym_ids.c:sym_id_parse'). Remember that a single symspec can
1779 match multiple symbols. An array of symbol tables (`syms') is created,
1780 each entry of which is a symbol table of Syms to be included or
1781 excluded from a particular listing. The master symbol table and the
1782 symspecs are examined by nested loops, and every symbol that matches a
1783 symspec is inserted into the appropriate syms table. This is done
1784 twice, once to count the size of each required symbol table, and again
1785 to build the tables, which have been malloced between passes. From now
1786 on, to determine whether a symbol is on an include or exclude symspec
1787 list, `gprof' simply uses its standard symbol lookup routine on the
1788 appropriate table in the `syms' array.
1790 Now the profile data file(s) themselves are read
1791 (`gmon_io.c:gmon_out_read'), first by checking for a new-style
1792 `gmon.out' header, then assuming this is an old-style BSD `gmon.out' if
1793 the magic number test failed.
1795 New-style histogram records are read by `hist.c:hist_read_rec'. For
1796 the first histogram record, allocate a memory array to hold all the
1797 bins, and read them in. When multiple profile data files (or files
1798 with multiple histogram records) are read, the starting address, ending
1799 address, number of bins and sampling rate must match between the
1800 various histograms, or a fatal error will result. If everything
1801 matches, just sum the additional histograms into the existing in-memory
1804 As each call graph record is read (`call_graph.c:cg_read_rec'), the
1805 parent and child addresses are matched to symbol table entries, and a
1806 call graph arc is created by `cg_arcs.c:arc_add', unless the arc fails
1807 a symspec check against INCL_ARCS/EXCL_ARCS. As each arc is added, a
1808 linked list is maintained of the parent's child arcs, and of the child's
1809 parent arcs. Both the child's call count and the arc's call count are
1810 incremented by the record's call count.
1812 Basic-block records are read (`basic_blocks.c:bb_read_rec'), but
1813 only if line-by-line profiling has been selected. Each basic-block
1814 address is matched to a corresponding line symbol in the symbol table,
1815 and an entry made in the symbol's bb_addr and bb_calls arrays. Again,
1816 if multiple basic-block records are present for the same address, the
1817 call counts are cumulative.
1819 A gmon.sum file is dumped, if requested (`gmon_io.c:gmon_out_write').
1821 If histograms were present in the data files, assign them to symbols
1822 (`hist.c:hist_assign_samples') by iterating over all the sample bins
1823 and assigning them to symbols. Since the symbol table is sorted in
1824 order of ascending memory addresses, we can simple follow along in the
1825 symbol table as we make our pass over the sample bins. This step
1826 includes a symspec check against INCL_FLAT/EXCL_FLAT. Depending on the
1827 histogram scale factor, a sample bin may span multiple symbols, in
1828 which case a fraction of the sample count is allocated to each symbol,
1829 proportional to the degree of overlap. This effect is rare for normal
1830 profiling, but overlaps are more common during line-by-line profiling,
1831 and can cause each of two adjacent lines to be credited with half a
1834 If call graph data is present, `cg_arcs.c:cg_assemble' is called.
1835 First, if `-c' was specified, a machine-dependent routine (`find_call')
1836 scans through each symbol's machine code, looking for subroutine call
1837 instructions, and adding them to the call graph with a zero call count.
1838 A topological sort is performed by depth-first numbering all the
1839 symbols (`cg_dfn.c:cg_dfn'), so that children are always numbered less
1840 than their parents, then making a array of pointers into the symbol
1841 table and sorting it into numerical order, which is reverse topological
1842 order (children appear before parents). Cycles are also detected at
1843 this point, all members of which are assigned the same topological
1844 number. Two passes are now made through this sorted array of symbol
1845 pointers. The first pass, from end to beginning (parents to children),
1846 computes the fraction of child time to propagate to each parent and a
1847 print flag. The print flag reflects symspec handling of
1848 INCL_GRAPH/EXCL_GRAPH, with a parent's include or exclude (print or no
1849 print) property being propagated to its children, unless they
1850 themselves explicitly appear in INCL_GRAPH or EXCL_GRAPH. A second
1851 pass, from beginning to end (children to parents) actually propagates
1852 the timings along the call graph, subject to a check against
1853 INCL_TIME/EXCL_TIME. With the print flag, fractions, and timings now
1854 stored in the symbol structures, the topological sort array is now
1855 discarded, and a new array of pointers is assembled, this time sorted
1858 Finally, print the various outputs the user requested, which is now
1859 fairly straightforward. The call graph (`cg_print.c:cg_print') and
1860 flat profile (`hist.c:hist_print') are regurgitations of values already
1861 computed. The annotated source listing
1862 (`basic_blocks.c:print_annotated_source') uses basic-block information,
1863 if present, to label each line of code with call counts, otherwise only
1864 the function call counts are presented.
1866 The function ordering code is marginally well documented in the
1867 source code itself (`cg_print.c'). Basically, the functions with the
1868 most use and the most parents are placed first, followed by other
1869 functions with the most use, followed by lower use functions, followed
1870 by unused functions at the end.
1873 File: gprof.info, Node: Debugging, Prev: Internals, Up: Details
1878 If `gprof' was compiled with debugging enabled, the `-d' option
1879 triggers debugging output (to stdout) which can be helpful in
1880 understanding its operation. The debugging number specified is
1881 interpreted as a sum of the following options:
1883 2 - Topological sort
1884 Monitor depth-first numbering of symbols during call graph analysis
1887 Shows symbols as they are identified as cycle heads
1890 As the call graph arcs are read, show each arc and how the total
1891 calls to each function are tallied
1893 32 - Call graph arc sorting
1894 Details sorting individual parents/children within each call graph
1897 64 - Reading histogram and call graph records
1898 Shows address ranges of histograms as they are read, and each call
1902 Reading, classifying, and sorting the symbol table from the object
1903 file. For line-by-line profiling (`-l' option), also shows line
1904 numbers being assigned to memory addresses.
1906 256 - Static call graph
1907 Trace operation of `-c' option
1909 512 - Symbol table and arc table lookups
1910 Detail operation of lookup routines
1912 1024 - Call graph propagation
1913 Shows how function times are propagated along the call graph
1916 Shows basic-block records as they are read from profile data (only
1917 meaningful with `-l' option)
1920 Shows symspec-to-symbol pattern matching operation
1922 8192 - Annotate source
1923 Tracks operation of `-A' option
1926 File: gprof.info, Node: GNU Free Documentation License, Prev: Details, Up: Top
1928 GNU Free Documentation License
1929 ******************************
1931 GNU Free Documentation License
1933 Version 1.1, March 2000
1935 Copyright (C) 2000 Free Software Foundation, Inc. 51 Franklin
1936 Street, Fifth Floor, Boston, MA 02110-1301 USA
1938 Everyone is permitted to copy and distribute verbatim copies of
1939 this license document, but changing it is not allowed.
1943 The purpose of this License is to make a manual, textbook, or other
1944 written document "free" in the sense of freedom: to assure everyone the
1945 effective freedom to copy and redistribute it, with or without
1946 modifying it, either commercially or noncommercially. Secondarily,
1947 this License preserves for the author and publisher a way to get credit
1948 for their work, while not being considered responsible for
1949 modifications made by others.
1951 This License is a kind of "copyleft", which means that derivative
1952 works of the document must themselves be free in the same sense. It
1953 complements the GNU General Public License, which is a copyleft license
1954 designed for free software.
1956 We have designed this License in order to use it for manuals for free
1957 software, because free software needs free documentation: a free
1958 program should come with manuals providing the same freedoms that the
1959 software does. But this License is not limited to software manuals; it
1960 can be used for any textual work, regardless of subject matter or
1961 whether it is published as a printed book. We recommend this License
1962 principally for works whose purpose is instruction or reference.
1964 1. APPLICABILITY AND DEFINITIONS
1966 This License applies to any manual or other work that contains a
1967 notice placed by the copyright holder saying it can be distributed
1968 under the terms of this License. The "Document", below, refers to any
1969 such manual or work. Any member of the public is a licensee, and is
1972 A "Modified Version" of the Document means any work containing the
1973 Document or a portion of it, either copied verbatim, or with
1974 modifications and/or translated into another language.
1976 A "Secondary Section" is a named appendix or a front-matter section
1977 of the Document that deals exclusively with the relationship of the
1978 publishers or authors of the Document to the Document's overall subject
1979 (or to related matters) and contains nothing that could fall directly
1980 within that overall subject. (For example, if the Document is in part a
1981 textbook of mathematics, a Secondary Section may not explain any
1982 mathematics.) The relationship could be a matter of historical
1983 connection with the subject or with related matters, or of legal,
1984 commercial, philosophical, ethical or political position regarding them.
1986 The "Invariant Sections" are certain Secondary Sections whose titles
1987 are designated, as being those of Invariant Sections, in the notice
1988 that says that the Document is released under this License.
1990 The "Cover Texts" are certain short passages of text that are listed,
1991 as Front-Cover Texts or Back-Cover Texts, in the notice that says that
1992 the Document is released under this License.
1994 A "Transparent" copy of the Document means a machine-readable copy,
1995 represented in a format whose specification is available to the general
1996 public, whose contents can be viewed and edited directly and
1997 straightforwardly with generic text editors or (for images composed of
1998 pixels) generic paint programs or (for drawings) some widely available
1999 drawing editor, and that is suitable for input to text formatters or
2000 for automatic translation to a variety of formats suitable for input to
2001 text formatters. A copy made in an otherwise Transparent file format
2002 whose markup has been designed to thwart or discourage subsequent
2003 modification by readers is not Transparent. A copy that is not
2004 "Transparent" is called "Opaque".
2006 Examples of suitable formats for Transparent copies include plain
2007 ASCII without markup, Texinfo input format, LaTeX input format, SGML or
2008 XML using a publicly available DTD, and standard-conforming simple HTML
2009 designed for human modification. Opaque formats include PostScript,
2010 PDF, proprietary formats that can be read and edited only by
2011 proprietary word processors, SGML or XML for which the DTD and/or
2012 processing tools are not generally available, and the machine-generated
2013 HTML produced by some word processors for output purposes only.
2015 The "Title Page" means, for a printed book, the title page itself,
2016 plus such following pages as are needed to hold, legibly, the material
2017 this License requires to appear in the title page. For works in
2018 formats which do not have any title page as such, "Title Page" means
2019 the text near the most prominent appearance of the work's title,
2020 preceding the beginning of the body of the text.
2024 You may copy and distribute the Document in any medium, either
2025 commercially or noncommercially, provided that this License, the
2026 copyright notices, and the license notice saying this License applies
2027 to the Document are reproduced in all copies, and that you add no other
2028 conditions whatsoever to those of this License. You may not use
2029 technical measures to obstruct or control the reading or further
2030 copying of the copies you make or distribute. However, you may accept
2031 compensation in exchange for copies. If you distribute a large enough
2032 number of copies you must also follow the conditions in section 3.
2034 You may also lend copies, under the same conditions stated above, and
2035 you may publicly display copies.
2037 3. COPYING IN QUANTITY
2039 If you publish printed copies of the Document numbering more than
2040 100, and the Document's license notice requires Cover Texts, you must
2041 enclose the copies in covers that carry, clearly and legibly, all these
2042 Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts
2043 on the back cover. Both covers must also clearly and legibly identify
2044 you as the publisher of these copies. The front cover must present the
2045 full title with all words of the title equally prominent and visible.
2046 You may add other material on the covers in addition. Copying with
2047 changes limited to the covers, as long as they preserve the title of
2048 the Document and satisfy these conditions, can be treated as verbatim
2049 copying in other respects.
2051 If the required texts for either cover are too voluminous to fit
2052 legibly, you should put the first ones listed (as many as fit
2053 reasonably) on the actual cover, and continue the rest onto adjacent
2056 If you publish or distribute Opaque copies of the Document numbering
2057 more than 100, you must either include a machine-readable Transparent
2058 copy along with each Opaque copy, or state in or with each Opaque copy
2059 a publicly-accessible computer-network location containing a complete
2060 Transparent copy of the Document, free of added material, which the
2061 general network-using public has access to download anonymously at no
2062 charge using public-standard network protocols. If you use the latter
2063 option, you must take reasonably prudent steps, when you begin
2064 distribution of Opaque copies in quantity, to ensure that this
2065 Transparent copy will remain thus accessible at the stated location
2066 until at least one year after the last time you distribute an Opaque
2067 copy (directly or through your agents or retailers) of that edition to
2070 It is requested, but not required, that you contact the authors of
2071 the Document well before redistributing any large number of copies, to
2072 give them a chance to provide you with an updated version of the
2077 You may copy and distribute a Modified Version of the Document under
2078 the conditions of sections 2 and 3 above, provided that you release the
2079 Modified Version under precisely this License, with the Modified
2080 Version filling the role of the Document, thus licensing distribution
2081 and modification of the Modified Version to whoever possesses a copy of
2082 it. In addition, you must do these things in the Modified Version:
2084 A. Use in the Title Page (and on the covers, if any) a title distinct
2085 from that of the Document, and from those of previous versions
2086 (which should, if there were any, be listed in the History section
2087 of the Document). You may use the same title as a previous version
2088 if the original publisher of that version gives permission. B. List on
2089 the Title Page, as authors, one or more persons or entities
2090 responsible for authorship of the modifications in the Modified
2091 Version, together with at least five of the principal authors of the
2092 Document (all of its principal authors, if it has less than five). C.
2093 State on the Title page the name of the publisher of the Modified
2094 Version, as the publisher. D. Preserve all the copyright notices of
2095 the Document. E. Add an appropriate copyright notice for your
2096 modifications adjacent to the other copyright notices. F. Include,
2097 immediately after the copyright notices, a license notice giving the
2098 public permission to use the Modified Version under the terms of
2099 this License, in the form shown in the Addendum below. G. Preserve in
2100 that license notice the full lists of Invariant Sections and
2101 required Cover Texts given in the Document's license notice. H.
2102 Include an unaltered copy of this License. I. Preserve the section
2103 entitled "History", and its title, and add to it an item stating at
2104 least the title, year, new authors, and publisher of the Modified
2105 Version as given on the Title Page. If there is no section entitled
2106 "History" in the Document, create one stating the title, year,
2107 authors, and publisher of the Document as given on its Title Page,
2108 then add an item describing the Modified Version as stated in the
2109 previous sentence. J. Preserve the network location, if any, given in
2110 the Document for public access to a Transparent copy of the
2111 Document, and likewise the network locations given in the Document
2112 for previous versions it was based on. These may be placed in the
2113 "History" section. You may omit a network location for a work that
2114 was published at least four years before the Document itself, or if
2115 the original publisher of the version it refers to gives permission.
2116 K. In any section entitled "Acknowledgements" or "Dedications",
2117 preserve the section's title, and preserve in the section all the
2118 substance and tone of each of the contributor acknowledgements
2119 and/or dedications given therein. L. Preserve all the Invariant
2120 Sections of the Document, unaltered in their text and in their
2121 titles. Section numbers or the equivalent are not considered part
2122 of the section titles. M. Delete any section entitled "Endorsements".
2123 Such a section may not be included in the Modified Version. N. Do
2124 not retitle any existing section as "Endorsements" or to conflict in
2125 title with any Invariant Section.
2127 If the Modified Version includes new front-matter sections or
2128 appendices that qualify as Secondary Sections and contain no material
2129 copied from the Document, you may at your option designate some or all
2130 of these sections as invariant. To do this, add their titles to the
2131 list of Invariant Sections in the Modified Version's license notice.
2132 These titles must be distinct from any other section titles.
2134 You may add a section entitled "Endorsements", provided it contains
2135 nothing but endorsements of your Modified Version by various
2136 parties-for example, statements of peer review or that the text has
2137 been approved by an organization as the authoritative definition of a
2140 You may add a passage of up to five words as a Front-Cover Text, and
2141 a passage of up to 25 words as a Back-Cover Text, to the end of the list
2142 of Cover Texts in the Modified Version. Only one passage of
2143 Front-Cover Text and one of Back-Cover Text may be added by (or through
2144 arrangements made by) any one entity. If the Document already includes
2145 a cover text for the same cover, previously added by you or by
2146 arrangement made by the same entity you are acting on behalf of, you
2147 may not add another; but you may replace the old one, on explicit
2148 permission from the previous publisher that added the old one.
2150 The author(s) and publisher(s) of the Document do not by this License
2151 give permission to use their names for publicity for or to assert or
2152 imply endorsement of any Modified Version.
2154 5. COMBINING DOCUMENTS
2156 You may combine the Document with other documents released under this
2157 License, under the terms defined in section 4 above for modified
2158 versions, provided that you include in the combination all of the
2159 Invariant Sections of all of the original documents, unmodified, and
2160 list them all as Invariant Sections of your combined work in its
2163 The combined work need only contain one copy of this License, and
2164 multiple identical Invariant Sections may be replaced with a single
2165 copy. If there are multiple Invariant Sections with the same name but
2166 different contents, make the title of each such section unique by
2167 adding at the end of it, in parentheses, the name of the original
2168 author or publisher of that section if known, or else a unique number.
2169 Make the same adjustment to the section titles in the list of Invariant
2170 Sections in the license notice of the combined work.
2172 In the combination, you must combine any sections entitled "History"
2173 in the various original documents, forming one section entitled
2174 "History"; likewise combine any sections entitled "Acknowledgements",
2175 and any sections entitled "Dedications". You must delete all sections
2176 entitled "Endorsements."
2178 6. COLLECTIONS OF DOCUMENTS
2180 You may make a collection consisting of the Document and other
2181 documents released under this License, and replace the individual
2182 copies of this License in the various documents with a single copy that
2183 is included in the collection, provided that you follow the rules of
2184 this License for verbatim copying of each of the documents in all other
2187 You may extract a single document from such a collection, and
2188 distribute it individually under this License, provided you insert a
2189 copy of this License into the extracted document, and follow this
2190 License in all other respects regarding verbatim copying of that
2193 7. AGGREGATION WITH INDEPENDENT WORKS
2195 A compilation of the Document or its derivatives with other separate
2196 and independent documents or works, in or on a volume of a storage or
2197 distribution medium, does not as a whole count as a Modified Version of
2198 the Document, provided no compilation copyright is claimed for the
2199 compilation. Such a compilation is called an "aggregate", and this
2200 License does not apply to the other self-contained works thus compiled
2201 with the Document, on account of their being thus compiled, if they are
2202 not themselves derivative works of the Document.
2204 If the Cover Text requirement of section 3 is applicable to these
2205 copies of the Document, then if the Document is less than one quarter
2206 of the entire aggregate, the Document's Cover Texts may be placed on
2207 covers that surround only the Document within the aggregate. Otherwise
2208 they must appear on covers around the whole aggregate.
2212 Translation is considered a kind of modification, so you may
2213 distribute translations of the Document under the terms of section 4.
2214 Replacing Invariant Sections with translations requires special
2215 permission from their copyright holders, but you may include
2216 translations of some or all Invariant Sections in addition to the
2217 original versions of these Invariant Sections. You may include a
2218 translation of this License provided that you also include the original
2219 English version of this License. In case of a disagreement between the
2220 translation and the original English version of this License, the
2221 original English version will prevail.
2225 You may not copy, modify, sublicense, or distribute the Document
2226 except as expressly provided for under this License. Any other attempt
2227 to copy, modify, sublicense or distribute the Document is void, and will
2228 automatically terminate your rights under this License. However,
2229 parties who have received copies, or rights, from you under this
2230 License will not have their licenses terminated so long as such parties
2231 remain in full compliance.
2233 10. FUTURE REVISIONS OF THIS LICENSE
2235 The Free Software Foundation may publish new, revised versions of
2236 the GNU Free Documentation License from time to time. Such new
2237 versions will be similar in spirit to the present version, but may
2238 differ in detail to address new problems or concerns. See
2239 http://www.gnu.org/copyleft/.
2241 Each version of the License is given a distinguishing version number.
2242 If the Document specifies that a particular numbered version of this
2243 License "or any later version" applies to it, you have the option of
2244 following the terms and conditions either of that specified version or
2245 of any later version that has been published (not as a draft) by the
2246 Free Software Foundation. If the Document does not specify a version
2247 number of this License, you may choose any version ever published (not
2248 as a draft) by the Free Software Foundation.
2250 ADDENDUM: How to use this License for your documents
2252 To use this License in a document you have written, include a copy of
2253 the License in the document and put the following copyright and license
2254 notices just after the title page:
2256 Copyright (c) YEAR YOUR NAME.
2257 Permission is granted to copy, distribute and/or modify this document
2258 under the terms of the GNU Free Documentation License, Version 1.1
2259 or any later version published by the Free Software Foundation;
2260 with the Invariant Sections being LIST THEIR TITLES, with the
2261 Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
2262 A copy of the license is included in the section entitled "GNU
2263 Free Documentation License".
2265 If you have no Invariant Sections, write "with no Invariant Sections"
2266 instead of saying which ones are invariant. If you have no Front-Cover
2267 Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being
2268 LIST"; likewise for Back-Cover Texts.
2270 If your document contains nontrivial examples of program code, we
2271 recommend releasing these examples in parallel under your choice of
2272 free software license, such as the GNU General Public License, to
2273 permit their use in free software.