:@8u-@;^u"xP^t^f8)f;)^렋@8t(rwXPPjS}t^=xP^y(qD6G(p,(rfOwtBVVj%S蝈t#^_QQj%S胈(q[RRj%SXt^_PPj%S>u(p[^xP^t(r<餦(q$^xP^t(pm(r_PPj%S謇t^_PPj%S蒇u(q^xP^t(p(rx_PPj%S7t^_PPj%Su(q:^xP^t(p郥(r_PPjDS莄t^Gf8 u(q@8t(pXVVjSDzt^7(r_%=2%t(qisQQj .A ..gmp.info gprof.info binutils.infostandards.info gmp.info-2 mpfr.info gmp.info-1configure.infobfd.info dirld.infoas.infoThis is ../../gmp/doc/gmp.info, produced by makeinfo version 4.8 from ../../gmp/doc/gmp.texi. This manual describes how to install and use the GNU multiple precision arithmetic library, version 5.0.1. Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being "A GNU Manual", and with the Back-Cover Texts being "You have freedom to copy and modify this GNU Manual, like GNU software". A copy of the license is included in *Note GNU Free Documentation License::. INFO-DIR-SECTION GNU libraries START-INFO-DIR-ENTRY * gmp: (gmp). GNU Multiple Precision Arithmetic Library. END-INFO-DIR-ENTRY  Indirect: gmp.info-1: 981 gmp.info-2: 300864  Tag Table: (Indirect) Node: Top981 Node: Copying3211 Node: Introduction to GMP5062 Node: Installing GMP7773 Node: Build Options8505 Node: ABI and ISA24573 Node: Notes for Package Builds34251 Node: Notes for Particular Systems37338 Node: Known Build Problems43895 Node: Performance optimization47429 Node: GMP Basics48563 Node: Headers and Libraries49211 Node: Nomenclature and Types50635 Node: Function Classes52632 Node: Variable Conventions54325 Node: Parameter Conventions55934 Node: Memory Management57990 Node: Reentrancy59118 Node: Useful Macros and Constants60991 Node: Compatibility with older versions61989 Node: Demonstration Programs62950 Node: Efficiency64815 Node: Debugging72439 Node: Profiling78997 Node: Autoconf82988 Node: Emacs84767 Node: Reporting Bugs85373 Node: Integer Functions87916 Node: Initializing Integers88692 Node: Assigning Integers90839 Node: Simultaneous Integer Init & Assign92426 Node: Converting Integers94051 Node: Integer Arithmetic96973 Node: Integer Division98559 Node: Integer Exponentiation104869 Node: Integer Roots106309 Node: Number Theoretic Functions107983 Node: Integer Comparisons114126 Node: Integer Logic and Bit Fiddling115504 Node: I/O of Integers118051 Node: Integer Random Numbers120935 Node: Integer Import and Export123546 Node: Miscellaneous Integer Functions127556 Node: Integer Special Functions129416 Node: Rational Number Functions132503 Node: Initializing Rationals133696 Node: Rational Conversions136157 Node: Rational Arithmetic137888 Node: Comparing Rationals139192 Node: Applying Integer Functions140559 Node: I/O of Rationals142042 Node: Floating-point Functions143902 Node: Initializing Floats146787 Node: Assigning Floats150874 Node: Simultaneous Float Init & Assign153441 Node: Converting Floats154969 Node: Float Arithmetic158217 Node: Float Comparison160230 Node: I/O of Floats161811 Node: Miscellaneous Float Functions164409 Node: Low-level Functions166303 Node: Random Number Functions190437 Node: Random State Initialization191505 Node: Random State Seeding194363 Node: Random State Miscellaneous195752 Node: Formatted Output196393 Node: Formatted Output Strings196638 Node: Formatted Output Functions201852 Node: C++ Formatted Output205927 Node: Formatted Input208609 Node: Formatted Input Strings208845 Node: Formatted Input Functions213497 Node: C++ Formatted Input216466 Node: C++ Class Interface218369 Node: C++ Interface General219370 Node: C++ Interface Integers222440 Node: C++ Interface Rationals225871 Node: C++ Interface Floats229548 Node: C++ Interface Random Numbers234830 Node: C++ Interface Limitations237236 Node: BSD Compatible Functions240056 Node: Custom Allocation244767 Node: Language Bindings249085 Node: Algorithms253038 Node: Multiplication Algorithms253738 Node: Basecase Multiplication254710 Node: Karatsuba Multiplication256618 Node: Toom 3-Way Multiplication260243 Node: Toom 4-Way Multiplication266657 Node: FFT Multiplication268029 Node: Other Multiplication273365 Node: Unbalanced Multiplication275839 Node: Division Algorithms276627 Node: Single Limb Division277006 Node: Basecase Division279897 Node: Divide and Conquer Division281100 Node: Block-Wise Barrett Division283169 Node: Exact Division283821 Node: Exact Remainder286986 Node: Small Quotient Division289213 Node: Greatest Common Divisor Algorithms290811 Node: Binary GCD291108 Node: Lehmer's Algorithm293957 Node: Subquadratic GCD296177 Node: Extended GCD298636 Node: Jacobi Symbol299948 Node: Powering Algorithms300864 Node: Normal Powering Algorithm301127 Node: Modular Powering Algorithm301655 Node: Root Extraction Algorithms302435 Node: Square Root Algorithm302750 Node: Nth Root Algorithm304891 Node: Perfect Square Algorithm305676 Node: Perfect Power Algorithm307762 Node: Radix Conversion Algorithms308383 Node: Binary to Radix308759 Node: Radix to Binary312688 Node: Other Algorithms314776 Node: Prime Testing Algorithm315128 Node: Factorial Algorithm316312 Node: Binomial Coefficients Algorithm317715 Node: Fibonacci Numbers Algorithm318609 Node: Lucas Numbers Algorithm321083 Node: Random Number Algorithms321804 Node: Assembly Coding323925 Node: Assembly Code Organisation324885 Node: Assembly Basics325852 Node: Assembly Carry Propagation327002 Node: Assembly Cache Handling328833 Node: Assembly Functional Units330994 Node: Assembly Floating Point332607 Node: Assembly SIMD Instructions336385 Node: Assembly Software Pipelining337367 Node: Assembly Loop Unrolling338429 Node: Assembly Writing Guide340644 Node: Internals343409 Node: Integer Internals343921 Node: Rational Internals346177 Node: Float Internals347415 Node: Raw Output Internals354829 Node: C++ Interface Internals356023 Node: Contributors359309 Node: References364267 Node: GNU Free Documentation License369925 Node: Concept Index395094 Node: Function Index441276  End Tag Table This is gprof.info, produced by makeinfo version 4.8 from gprof.texi. INFO-DIR-SECTION Software development START-INFO-DIR-ENTRY * gprof: (gprof). Profiling your program's execution END-INFO-DIR-ENTRY This file documents the gprof profiler of the GNU system. Copyright (C) 1988, 1992, 1997, 1998, 1999, 2000, 2001, 2003, 2007, 2008, 2009 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".  File: gprof.info, Node: Top, Next: Introduction, Up: (dir) Profiling a Program: Where Does It Spend Its Time? ************************************************** This manual describes the GNU profiler, `gprof', and how you can use it to determine which parts of a program are taking most of the execution time. We assume that you know how to write, compile, and execute programs. GNU `gprof' was written by Jay Fenlason. This manual is for `gprof' (GNU Binutils) version 2.21. This document is distributed under the terms of the GNU Free Documentation License version 1.3. A copy of the license is included in the section entitled "GNU Free Documentation License". * Menu: * Introduction:: What profiling means, and why it is useful. * Compiling:: How to compile your program for profiling. * Executing:: Executing your program to generate profile data * Invoking:: How to run `gprof', and its options * Output:: Interpreting `gprof''s output * Inaccuracy:: Potential problems you should be aware of * How do I?:: Answers to common questions * Incompatibilities:: (between GNU `gprof' and Unix `gprof'.) * Details:: Details of how profiling is done * GNU Free Documentation License:: GNU Free Documentation License  File: gprof.info, Node: Introduction, Next: Compiling, Prev: Top, Up: Top 1 Introduction to Profiling *************************** Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing. This information can show you which pieces of your program are slower than you expected, and might be candidates for rewriting to make your program execute faster. It can also tell you which functions are being called more or less often than you expected. This may help you spot bugs that had otherwise been unnoticed. Since the profiler uses information collected during the actual execution of your program, it can be used on programs that are too large or too complex to analyze by reading the source. However, how your program is run will affect the information that shows up in the profile data. If you don't use some feature of your program while it is being profiled, no profile information will be generated for that feature. Profiling has several steps: * You must compile and link your program with profiling enabled. *Note Compiling a Program for Profiling: Compiling. * You must execute your program to generate a profile data file. *Note Executing the Program: Executing. * You must run `gprof' to analyze the profile data. *Note `gprof' Command Summary: Invoking. The next three chapters explain these steps in greater detail. Several forms of output are available from the analysis. The "flat profile" shows how much time your program spent in each function, and how many times that function was called. If you simply want to know which functions burn most of the cycles, it is stated concisely here. *Note The Flat Profile: Flat Profile. The "call graph" shows, for each function, which functions called it, which other functions it called, and how many times. There is also an estimate of how much time was spent in the subroutines of each function. This can suggest places where you might try to eliminate function calls that use a lot of time. *Note The Call Graph: Call Graph. The "annotated source" listing is a copy of the program's source code, labeled with the number of times each line of the program was executed. *Note The Annotated Source Listing: Annotated Source. To better understand how profiling works, you may wish to read a description of its implementation. *Note Implementation of Profiling: Implementation.  File: gprof.info, Node: Compiling, Next: Executing, Prev: Introduction, Up: Top 2 Compiling a Program for Profiling *********************************** The first step in generating profile information for your program is to compile and link it with profiling enabled. To compile a source file for profiling, specify the `-pg' option when you run the compiler. (This is in addition to the options you normally use.) To link the program for profiling, if you use a compiler such as `cc' to do the linking, simply specify `-pg' in addition to your usual options. The same option, `-pg', alters either compilation or linking to do what is necessary for profiling. Here are examples: cc -g -c myprog.c utils.c -pg cc -o myprog myprog.o utils.o -pg The `-pg' option also works with a command that both compiles and links: cc -o myprog myprog.c utils.c -g -pg Note: The `-pg' option must be part of your compilation options as well as your link options. If it is not then no call-graph data will be gathered and when you run `gprof' you will get an error message like this: gprof: gmon.out file is missing call-graph data If you add the `-Q' switch to suppress the printing of the call graph data you will still be able to see the time samples: Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls Ts/call Ts/call name 44.12 0.07 0.07 zazLoop 35.29 0.14 0.06 main 20.59 0.17 0.04 bazMillion If you run the linker `ld' directly instead of through a compiler such as `cc', you may have to specify a profiling startup file `gcrt0.o' as the first input file instead of the usual startup file `crt0.o'. In addition, you would probably want to specify the profiling C library, `libc_p.a', by writing `-lc_p' instead of the usual `-lc'. This is not absolutely necessary, but doing this gives you number-of-calls information for standard library functions such as `read' and `open'. For example: ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p If you are running the program on a system which supports shared libraries you may run into problems with the profiling support code in a shared library being called before that library has been fully initialised. This is usually detected by the program encountering a segmentation fault as soon as it is run. The solution is to link against a static version of the library containing the profiling support code, which for `gcc' users can be done via the `-static' or `-static-libgcc' command line option. For example: gcc -g -pg -static-libgcc myprog.c utils.c -o myprog If you compile only some of the modules of the program with `-pg', you can still profile the program, but you won't get complete information about the modules that were compiled without `-pg'. The only information you get for the functions in those modules is the total time spent in them; there is no record of how many times they were called, or from where. This will not affect the flat profile (except that the `calls' field for the functions will be blank), but will greatly reduce the usefulness of the call graph. If you wish to perform line-by-line profiling you should use the `gcov' tool instead of `gprof'. See that tool's manual or info pages for more details of how to do this. Note, older versions of `gcc' produce line-by-line profiling information that works with `gprof' rather than `gcov' so there is still support for displaying this kind of information in `gprof'. *Note Line-by-line Profiling: Line-by-line. It also worth noting that `gcc' implements a `-finstrument-functions' command line option which will insert calls to special user supplied instrumentation routines at the entry and exit of every function in their program. This can be used to implement an alternative profiling scheme.  File: gprof.info, Node: Executing, Next: Invoking, Prev: Compiling, Up: Top 3 Executing the Program *********************** Once the program is compiled for profiling, you must run it in order to generate the information that `gprof' needs. Simply run the program as usual, using the normal arguments, file names, etc. The program should run normally, producing the same output as usual. It will, however, run somewhat slower than normal because of the time spent collecting and writing the profile data. The way you run the program--the arguments and input that you give it--may have a dramatic effect on what the profile information shows. The profile data will describe the parts of the program that were activated for the particular input you use. For example, if the first command you give to your program is to quit, the profile data will show the time used in initialization and in cleanup, but not much else. Your program will write the profile data into a file called `gmon.out' just before exiting. If there is already a file called `gmon.out', its contents are overwritten. There is currently no way to tell the program to write the profile data under a different name, but you can rename the file afterwards if you are concerned that it may be overwritten. In order to write the `gmon.out' file properly, your program must exit normally: by returning from `main' or by calling `exit'. Calling the low-level function `_exit' does not write the profile data, and neither does abnormal termination due to an unhandled signal. The `gmon.out' file is written in the program's _current working directory_ at the time it exits. This means that if your program calls `chdir', the `gmon.out' file will be left in the last directory your program `chdir''d to. If you don't have permission to write in this directory, the file is not written, and you will get an error message. Older versions of the GNU profiling library may also write a file called `bb.out'. This file, if present, contains an human-readable listing of the basic-block execution counts. Unfortunately, the appearance of a human-readable `bb.out' means the basic-block counts didn't get written into `gmon.out'. The Perl script `bbconv.pl', included with the `gprof' source distribution, will convert a `bb.out' file into a format readable by `gprof'. Invoke it like this: bbconv.pl < bb.out > BH-DATA This translates the information in `bb.out' into a form that `gprof' can understand. But you still need to tell `gprof' about the existence of this translated information. To do that, include BB-DATA on the `gprof' command line, _along with `gmon.out'_, like this: gprof OPTIONS EXECUTABLE-FILE gmon.out BB-DATA [YET-MORE-PROFILE-DATA-FILES...] [> OUTFILE]  File: gprof.info, Node: Invoking, Next: Output, Prev: Executing, Up: Top 4 `gprof' Command Summary ************************* After you have a profile data file `gmon.out', you can run `gprof' to interpret the information in it. The `gprof' program prints a flat profile and a call graph on standard output. Typically you would redirect the output of `gprof' into a file with `>'. You run `gprof' like this: gprof OPTIONS [EXECUTABLE-FILE [PROFILE-DATA-FILES...]] [> OUTFILE] Here square-brackets indicate optional arguments. If you omit the executable file name, the file `a.out' is used. If you give no profile data file name, the file `gmon.out' is used. If any file is not in the proper format, or if the profile data file does not appear to belong to the executable file, an error message is printed. You can give mor !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwe than one profile data file by entering all their names after the executable file name; then the statistics in all the data files are summed together. The order of these options does not matter. * Menu: * Output Options:: Controlling `gprof''s output style * Analysis Options:: Controlling how `gprof' analyzes its data * Miscellaneous Options:: * Deprecated Options:: Options you no longer need to use, but which have been retained for compatibility * Symspecs:: Specifying functions to include or exclude  File: gprof.info, Node: Output Options, Next: Analysis Options, Up: Invoking 4.1 Output Options ================== These options specify which of several output formats `gprof' should produce. Many of these options take an optional "symspec" to specify functions to be included or excluded. These options can be specified multiple times, with different symspecs, to include or exclude sets of symbols. *Note Symspecs: Symspecs. Specifying any of these options overrides the default (`-p -q'), which prints a flat profile and call graph analysis for all functions. `-A[SYMSPEC]' `--annotated-source[=SYMSPEC]' The `-A' option causes `gprof' to print annotated source code. If SYMSPEC is specified, print output only for matching symbols. *Note The Annotated Source Listing: Annotated Source. `-b' `--brief' If the `-b' option is given, `gprof' doesn't print the verbose blurbs that try to explain the meaning of all of the fields in the tables. This is useful if you intend to print out the output, or are tired of seeing the blurbs. `-C[SYMSPEC]' `--exec-counts[=SYMSPEC]' The `-C' option causes `gprof' to print a tally of functions and the number of times each was called. If SYMSPEC is specified, print tally only for matching symbols. If the profile data file contains basic-block count records, specifying the `-l' option, along with `-C', will cause basic-block execution counts to be tallied and displayed. `-i' `--file-info' The `-i' option causes `gprof' to display summary information about the profile data file(s) and then exit. The number of histogram, call graph, and basic-block count records is displayed. `-I DIRS' `--directory-path=DIRS' The `-I' option specifies a list of search directories in which to find source files. Environment variable GPROF_PATH can also be used to convey this information. Used mostly for annotated source output. `-J[SYMSPEC]' `--no-annotated-source[=SYMSPEC]' The `-J' option causes `gprof' not to print annotated source code. If SYMSPEC is specified, `gprof' prints annotated source, but excludes matching symbols. `-L' `--print-path' Normally, source filenames are printed with the path component suppressed. The `-L' option causes `gprof' to print the full pathname of source filenames, which is determined from symbolic debugging information in the image file and is relative to the directory in which the compiler was invoked. `-p[SYMSPEC]' `--flat-profile[=SYMSPEC]' The `-p' option causes `gprof' to print a flat profile. If SYMSPEC is specified, print flat profile only for matching symbols. *Note The Flat Profile: Flat Profile. `-P[SYMSPEC]' `--no-flat-profile[=SYMSPEC]' The `-P' option causes `gprof' to suppress printing a flat profile. If SYMSPEC is specified, `gprof' prints a flat profile, but excludes matching symbols. `-q[SYMSPEC]' `--graph[=SYMSPEC]' The `-q' option causes `gprof' to print the call graph analysis. If SYMSPEC is specified, print call graph only for matching symbols and their children. *Note The Call Graph: Call Graph. `-Q[SYMSPEC]' `--no-graph[=SYMSPEC]' The `-Q' option causes `gprof' to suppress printing the call graph. If SYMSPEC is specified, `gprof' prints a call graph, but excludes matching symbols. `-t' `--table-length=NUM' The `-t' option causes the NUM most active source lines in each source file to be listed when source annotation is enabled. The default is 10. `-y' `--separate-files' This option affects annotated source output only. Normally, `gprof' prints annotated source files to standard-output. If this option is specified, annotated source for a file named `path/FILENAME' is generated in the file `FILENAME-ann'. If the underlying file system would truncate `FILENAME-ann' so that it overwrites the original `FILENAME', `gprof' generates annotated source in the file `FILENAME.ann' instead (if the original file name has an extension, that extension is _replaced_ with `.ann'). `-Z[SYMSPEC]' `--no-exec-counts[=SYMSPEC]' The `-Z' option causes `gprof' not to print a tally of functions and the number of times each was called. If SYMSPEC is specified, print tally, but exclude matching symbols. `-r' `--function-ordering' The `--function-ordering' option causes `gprof' to print a suggested function ordering for the program based on profiling data. This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems which support arbitrary ordering of functions in an executable. The exact details of how to force the linker to place functions in a particular order is system dependent and out of the scope of this manual. `-R MAP_FILE' `--file-ordering MAP_FILE' The `--file-ordering' option causes `gprof' to print a suggested .o link line ordering for the program based on profiling data. This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems which do not support arbitrary ordering of functions in an executable. Use of the `-a' argument is highly recommended with this option. The MAP_FILE argument is a pathname to a file which provides function name to object file mappings. The format of the file is similar to the output of the program `nm'. c-parse.o:00000000 T yyparse c-parse.o:00000004 C yyerrflag c-lang.o:00000000 T maybe_objc_method_name c-lang.o:00000000 T print_lang_statistics c-lang.o:00000000 T recognize_objc_keyword c-decl.o:00000000 T print_lang_identifier c-decl.o:00000000 T print_lang_type ... To create a MAP_FILE with GNU `nm', type a command like `nm --extern-only --defined-only -v --print-file-name program-name'. `-T' `--traditional' The `-T' option causes `gprof' to print its output in "traditional" BSD style. `-w WIDTH' `--width=WIDTH' Sets width of output lines to WIDTH. Currently only used when printing the function index at the bottom of the call graph. `-x' `--all-lines' This option affects annotated source output only. By default, only the lines at the beginning of a basic-block are annotated. If this option is specified, every line in a basic-block is annotated by repeating the annotation for the first line. This behavior is similar to `tcov''s `-a'. `--demangle[=STYLE]' `--no-demangle' These options control whether C++ symbol names should be demangled when printing output. The default is to demangle symbols. The `--no-demangle' option may be used to turn off demangling. Different compilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your compiler.  File: gprof.info, Node: Analysis Options, Next: Miscellaneous Options, Prev: Output Options, Up: Invoking 4.2 Analysis Options ==================== `-a' `--no-static' The `-a' option causes `gprof' to suppress the printing of statically declared (private) functions. (These are functions whose names are not listed as global, and which are not visible outside the file/function/block where they were defined.) Time spent in these functions, calls to/from them, etc., will all be attributed to the function that was loaded directly before it in the executable file. This option affects both the flat profile and the call graph. `-c' `--static-call-graph' The `-c' option causes the call graph of the program to be augmented by a heuristic which examines the text space of the object file and identifies function calls in the binary machine code. Since normal call graph records are only generated when functions are entered, this option identifies children that could have been called, but never were. Calls to functions that were not compiled with profiling enabled are also identified, but only if symbol table entries are present for them. Calls to dynamic library routines are typically _not_ found by this option. Parents or children identified via this heuristic are indicated in the call graph with call counts of `0'. `-D' `--ignore-non-functions' The `-D' option causes `gprof' to ignore symbols which are not known to be functions. This option will give more accurate profile data on systems where it is supported (Solaris and HPUX for example). `-k FROM/TO' The `-k' option allows you to delete from the call graph any arcs from symbols matching symspec FROM to those matching symspec TO. `-l' `--line' The `-l' option enables line-by-line profiling, which causes histogram hits to be charged to individual source code lines, instead of functions. This feature only works with programs compiled by older versions of the `gcc' compiler. Newer versions of `gcc' are designed to work with the `gcov' tool instead. If the program was compiled with basic-block counting enabled, this option will also identify how many times each line of code was executed. While line-by-line profiling can help isolate where in a large function a program is spending its time, it also significantly increases the running time of `gprof', and magnifies statistical inaccuracies. *Note Statistical Sampling Error: Sampling Error. `-m NUM' `--min-count=NUM' This option affects execution count output only. Symbols that are executed less than NUM times are suppressed. `-nSYMSPEC' `--time=SYMSPEC' The `-n' option causes `gprof', in its call graph analysis, to only propagate times for symbols matching SYMSPEC. `-NSYMSPEC' `--no-time=SYMSPEC' The `-n' option causes `gprof', in its call graph analysis, not to propagate times for symbols matching SYMSPEC. `-SFILENAME' `--external-symbol-table=FILENAME' The `-S' option causes `gprof' to read an external symbol table file, such as `/proc/kallsyms', rather than read the symbol table from the given object file (the default is `a.out'). This is useful for profiling kernel modules. `-z' `--display-unused-functions' If you give the `-z' option, `gprof' will mention all functions in the flat profile, even those that were never called, and that had no time spent in them. This is useful in conjunction with the `-c' option for discovering which routines were never called.  File: gprof.info, Node: Miscellaneous Options, Next: Deprecated Options, Prev: Analysis Options, Up: Invoking 4.3 Miscellaneous Options ========================= `-d[NUM]' `--debug[=NUM]' The `-d NUM' option specifies debugging options. If NUM is not specified, enable all debugging. *Note Debugging `gprof': Debugging. `-h' `--help' The `-h' option prints command line usage. `-ONAME' `--file-format=NAME' Selects the format of the profile data files. Recognized formats are `auto' (the default), `bsd', `4.4bsd', `magic', and `prof' (not yet supported). `-s' `--sum' The `-s' option causes `gprof' to summarize the information in the profile data files it read in, and write out a profile data file called `gmon.sum', which contains all the information from the profile data files that `gprof' read in. The file `gmon.sum' may be one of the specified input files; the effect of this is to merge the data in the other input files into `gmon.sum'. Eventually you can run `gprof' again without `-s' to analyze the cumulative data in the file `gmon.sum'. `-v' `--version' The `-v' flag causes `gprof' to print the current version number, and then exit.  File: gprof.info, Node: Deprecated Options, Next: Symspecs, Prev: Miscellaneous Options, Up: Invoking 4.4 Deprecated Options ====================== These options have been replaced with newer versions that use symspecs. `-e FUNCTION_NAME' The `-e FUNCTION' option tells `gprof' to not print information about the function FUNCTION_NAME (and its children...) in the call graph. The function will still be listed as a child of any functions that call it, but its index number will be shown as `[not printed]'. More than one `-e' option may be given; only one FUNCTION_NAME may be indicated with each `-e' option. `-E FUNCTION_NAME' The `-E FUNCTION' option works like the `-e' option, but time spent in the function (and children who were not called from anywhere else), will not be used to compute the percentages-of-time for the call graph. More than one `-E' option may be given; only one FUNCTION_NAME may be indicated with each `-E' option. `-f FUNCTION_NAME' The `-f FUNCTION' option causes `gprof' to limit the call graph to the function FUNCTION_NAME and its children (and their children...). More than one `-f' option may be given; only one FUNCTION_NAME may be indicated with each `-f' option. `-F FUNCTION_NAME' The `-F FUNCTION' option works like the `-f' option, but only time spent in the function and its children (and their children...) will be used to determine total-time and percentages-of-time for the call graph. More than one `-F' option may be given; only one FUNCTION_NAME may be indicated with each `-F' option. The `-F' option overrides the `-E' option. Note that only one function can be specified with each `-e', `-E', `-f' or `-F' option. To specify more than one function, use multiple options. For example, this command: gprof -e boring -f foo -f bar myprogram > gprof.output lists in the call graph all functions that were reached from either `foo' or `bar' and were not reachable from `boring'.  File: gprof.info, Node: Symspecs, Prev: Deprecated Options, Up: Invoking 4.5 Symspecs ============ Many of the output options allow functions to be included or excluded using "symspecs" (symbol specifications), which observe the following syntax: filename_containing_a_dot | funcname_not_containing_a_dot | linenumber | ( [ any_filename ] `:' ( any_funcname | linenumber ) ) Here are some sample symspecs: `main.c' Selects everything in file `main.c'--the dot in the string tells `gprof' to interpret the string as a filename, rather than as a function name. To select a file whose name does not contain a dot, a trailing colon should be specified. For example, `odd:' is interpreted as the file named `odd'. `main' Selects all functions named `main'. Note that there may be multiple instances of the same function name because some of the definitions may be local (i.e., static). Unless a function name is unique in a program, you must use the colon notation explained below to specify a function from a specific source file. Sometimes, function names contain dots. In such cases, it is necessary to add a leading colon to the name. For example, `:.mul' selects function `.mul'. In some object file formats, symbols have a leading underscore. `gprof' will normally not print these underscores. When you name a symbol in a symspec, you should type it exactly as `gprof' prints it in its output. For example, if the compiler produces a symbol `_main' from your `main' function, `gprof' still prints it as `main' in its output, so you should use `main' in symspecs. `main.c:main' Selects function `main' in file `main.c'. `main.c:134' Selects line 134 in file `main.c'.  File: gprof.info, Node: Output, Next: Inaccuracy, Prev: Invoking, Up: Top 5 Interpreting `gprof''s Output ******************************* `gprof' can produce several different output styles, the most important of which are described below. The simplest output styles (file information, execution count, and function and file ordering) are not described here, but are documented with the respective options that trigger them. *Note Output Options: Output Options. * Menu: * Flat Profile:: The flat profile shows how much time was spent executing directly in each function. * Call Graph:: The call graph shows which functions called which others, and how much time each function used when its subroutine calls are included. * Line-by-line:: `gprof' can analyze individual source code lines * Annotated Source:: The annotated source listing displays source code labeled with execution counts  File: gprof.info, Node: Flat Profile, Next: Call Graph, Up: Output 5.1 The Flat Profile ==================== The "flat profile" shows the total amount of time your program spent executing each function. Unless the `-z' option is given, functions with no apparent time spent in them, and no apparent calls to them, are not mentioned. Note that if a function was not compiled for profiling, and didn't run long enough to show up on the program counter histogram, it will be indistinguishable from a function that was never called. This is part of a flat profile for a small program: Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls ms/call ms/call name 33.34 0.02 0.02 7208 0.00 0.00 open 16.67 0.03 0.01 244 0.04 0.12 offtime 16.67 0.04 0.01 8 1.25 1.25 memccpy 16.67 0.05 0.01 7 1.43 1.43 write 16.67 0.06 0.01 mcount 0.00 0.06 0.00 236 0.00 0.00 tzset 0.00 0.06 0.00 192 0.00 0.00 tolower 0.00 0.06 0.00 47 0.00 0.00 strlen 0.00 0.06 0.00 45 0.00 0.00 strchr 0.00 0.06 0.00 1 0.00 50.00 main 0.00 0.06 0.00 1 0.00 0.00 memcpy 0.00 0.06 0.00 1 0.00 10.11 print 0.00 0.06 0.00 1 0.00 0.00 profil 0.00 0.06 0.00 1 0.00 50.00 report ... The functions are sorted first by decreasing run-time spent in them, then by decreasing number of calls, then alphabetically by name. The functions `mcount' and `profil' are part of the profiling apparatus and appear in every flat profile; their time gives a measure of the amount of overhead due to profiling. Just before the column headers, a statement appears indicating how much time each sample counted as. This "sampling period" estimates the margin of error in each of the time figures. A time figure that is not much larger than this is not reliable. In this example, each sample counted as 0.01 seconds, suggesting a 100 Hz sampling rate. The program's total execution time was 0.06 seconds, as indicated by the `cumulative seconds' field. Since each sample counted for 0.01 seconds, this means only six samples were taken during the run. Two of the samples occurred while the program was in the `open' function, as indicated by the `self seconds' field. Each of the other four samples occurred one each in `offtime', `memccpy', `write', and `mcount'. Since only six samples were taken, none of these values can be regarded as particularly reliable. In another run, the `self seconds' field for `mcount' might well be `0.00' or `0.02'. *Note Statistical Sampling Error: Sampling Error, for a complete discussion. The remaining functions in the listing (those whose `self seconds' field is `0.00') didn't appear in the histogram samples at all. However, the call graph indicated that they were called, so therefore they are listed, sorted in decreasing order by the `calls' field. Clearly some time was spent executing these functions, but the paucity of histogram samples prevents any determination of how much time each took. Here is what the fields in each line mean: `% time' This is the percentage of the total execution time your program spent in this function. These should all add up to 100%. `cumulative seconds' This is the cumulative total number of seconds the computer spent executing this functions, plus the time spent in all the functions above this one in this table. `self seconds' This is the number of seconds accounted for by this function alone. The flat profile listing is sorted first by this number. `calls' This is the total number of times the function was called. If the function was never called, or the number of times it was called cannot be determined (probably because the function was not compiled with profiling enabled), the "calls" field is blank. `self ms/call' This represents the average number of milliseconds spent in this function per call, if this function is profiled. Otherwise, this field is blank for this function. `total ms/call' This represents the average number of milliseconds spent in this function and its descendants per call, if this function is profiled. Otherwise, this field is blank for this function. This is the only field in the flat profile that uses call graph analysis. `name' This is the name of the function. The flat profile is sorted by this field alphabetically after the "self seconds" and "calls" fields are sorted.  File: gprof.info, Node: Call Graph, Next: Line-by-line, Prev: Flat Profile, Up: Output 5.2 The Call Graph ================== The "call graph" shows how much time was spent in each function and its children. From this information, you can find functions that, while they themselves may not have used much time, called other functions that did use unusual amounts of time. Here is a sample call from a small program. This call came from the same `gprof' run as the flat profile example in the previous section. granularity: each sample hit covers 2 byte(s) for 20.00% of 0.05 seconds index % time self children called name [1] 100.0 0.00 0.05 start [1] 0.00 0.05 1/1 main [2] 0.00 0.00 1/2 on_exit [28] 0.00 0.00 1/1 exit [59] ----------------------------------------------- 0.00 0.05 1/1 start [1] [2] 100.0 0.00 0.05 1 main [2] 0.00 0.05 1/1 report [3] ----------------------------------------------- 0.00 0.05 1/1 main [2] [3] 100.0 0.00 0.05 1 report [3] 0.00 0.03 8/8 timelocal [6] 0.00 0.01 1/1 print [9] 0.00 0.01 9/9 fgets [12] 0.00 0.00 12/34 strncmp [40] 0.00 0.00 8/8 lookup [20] 0.00 0.00 1/1 fopen [21] 0.00 0.00 8/8 chewtime [24] 0.00 0.00 8/16 skipspace [44] ----------------------------------------------- [4] 59.8 0.01 0.02 8+472 [4] 0.01 0.02 244+260 offtime [7] 0.00 0.00 236+1 tzset [26] ----------------------------------------------- The lines full of dashes divide this table into "entries", one for each function. Each entry has one or more lines. In each entry, the primary line is the one that starts with an index number in square brackets. The end of this line says which function the entry is for. The preceding lines in the entry describe the callers of this function and the following lines describe its subroutines (also called "children" when we speak of the call graph). The entries are sorted by time spent in the function and its subroutines. The internal profiling function `mcount' (*note The Flat Profile: Flat Profile.) is never mentioned in the call graph. * Menu: * Primary:: Details of the primary line's contents. * Callers:: Details of caller-lines' contents. * Subroutines:: Details of subroutine-lines' contents. * Cycles:: When there are cycles of recursion, such as `a' calls `b' calls `a'...  File: gprof.info, Node: Primary, Next: Callers, Up: Call Graph 5.2.1 The Primary Line ---------------------- The "primary line" in a call graph entry is the line that describes the function which the entry is about and gives the overall statistics for this function. For reference, we repeat the primary line from the entry for function `report' in our main example, together with the heading line that shows the names of the fields: index % time self children called name ... [3] 100.0 0.00 0.05 1 report [3] Here is what the fields in the primary line mean: `index' Entries are numbered with consecutive integers. Each function therefore has an index number, which appears at the beginning of its primary line. Each cross-reference to a function, as a caller or subroutine of another, gives its index number as well as its name. The index number guides you if you wish to look for the entry for that function. `% time' This is the percentage of the total time that was spent in this function, including time spent in subroutines called from this function. The time spent in this function is counted again for the callers of this function. Therefore, adding up these percentages is meaningless. `self' This is the total amount of time spent in this function. This should be identical to the number printed in the `seconds' field for this function in the flat profile. `children' This is the total amount of time spent in the subroutine calls made by this function. This should be equal to the sum of all the `self' and `children' entries of the children listed directly below this function. `called' This is the number of times the function was called. If the function called itself recursively, there are two numbers, separated by a `+'. The first number counts non-recursive calls, and the second counts recursive calls. In the example above, the function `report' was called once from `main'. `name' This is the name of the current function. The index number is repeated after it. If the function is part of a cycle of recursion, the cycle number is printed between the function's name and the index number (*note How Mutually Recursive Functions Are Described: Cycles.). For example, if function `gnurr' is part of cycle number one, and has index number twelve, its primary line would be end like this: gnurr [12]  File: gprof.info, Node: Callers, Next: Subroutines, Prev: Primary, Up: Call Graph 5.2.2 Lines for a Function's Callers ------------------------------------ A function's entry has a line for each function it was called by. These lines' fields correspond to the fields of the primary line, but their meanings are different because of the difference in context. For reference, we repeat two lines from the entry for the function `report', the primary line and one caller-line preceding it, together with the heading line that shows the names of the fields: index % time self children called name ... 0.00 0.05 1/1 main [2] [3] 100.0 0.00 0.05 1 report [3] Here are the meanings of the fields in the caller-line for `report' called from `main': `self' An estimate of the amount of time spent in `report' itself when it was called from `main'. `children' An estimate of the amount of time spent in subroutines of `report' when `report' was called from `main'. The sum of the `self' and `children' fields is an estimate of the amount of time spent within calls to `report' from `main'. `called' Two numbers: the number of times `report' was called from `main', followed by the total number of non-recursive calls to `report' from all its callers. `name and index number' The name of the caller of `report' to which this line applies, followed by the caller's index number. Not all functions have entries in the call graph; some options to `gprof' request the omission of certain functions. When a caller has no entry of its own, it still has caller-lines in the entries of the functions it calls. If the caller is part of a recursion cycle, the cycle number is printed between the name and the index number. If the identity of the callers of a function cannot be determined, a dummy caller-line is printed which has `' as the "caller's name" and all other fields blank. This can happen for signal handlers.  File: gprof.info, Node: Subroutines, Next: Cycles, Prev: Callers, Up: Call Graph 5.2.3 Lines for a Function's Subroutines ---------------------------------------- A function's entry has a line for each of its subroutines--in other words, a line for each other function that it called. These lines' fields correspond to the fields of the primary line, but their meanings are different because of the difference in context. For reference, we repeat two lines from the entry for the function `main', the primary line and a line for a subroutine, together with the heading line that shows the names of the fields: index % time self children called name ... [2] 100.0 0.00 0.05 1 main [2] 0.00 0.05 1/1 report [3] Here are the meanings of the fields in the subroutine-line for `main' calling `report': `self' An estimate of the amount of time spent directly within `report' when `report' was called from `main'. `children' An estimate of the amount of time spent in subroutines of `report' when `report' was called from `main'. The sum of the `self' and `children' fields is an estimate of the total time spent in calls to `report' from `main'. `called' Two numbers, the number of calls to `report' from `main' followed by the total number of non-recursive calls to `report'. This ratio is used to determine how much of `report''s `self' and `children' time gets credited to `main'. *Note Estimating `children' Times: Assumptions. `name' The name of the subroutine of `main' to which this line applies, followed by the subroutine's index number. If the caller is part of a recursion cycle, the cycle number is printed between the name and the index number.  File: gprof.info, Node: Cycles, Prev: Subroutines, Up: Call Graph 5.2.4 How Mutually Recursive Functions Are Described ---------------------------------------------------- The graph may be complicated by the presence of "cycles of recursion" in the call graph. A cycle exists if a function calls another function that (directly or indirectly) calls (or appears to call) the original function. For example: if `a' calls `b', and `b' calls `a', then `a' and `b' form a cycle. Whenever there are call paths both ways between a pair of functions, they belong to the same cycle. If `a' and `b' call each other and `b' and `c' call each other, all three make one cycle. Note that even if `b' only calls `a' if it was not called from `a', `gprof' cannot determine this, so `a' and `b' are still considered a cycle. The cycles are numbered with consecutive integers. When a function belongs to a cycle, each time the function name appears in the call graph it is followed by `'. The reason cycles matter is that they make the time values in the call graph paradoxical. The "time spent in children" of `a' should include the time spent in its subroutine `b' and in `b''s subroutines--but one of `b''s subroutines is `a'! How much of `a''s time should be included in the children of `a', when `a' is indirectly recursive? The way `gprof' resolves this paradox is by creating a single entry for the cycle as a whole. The primary line of this entry describes the total time spent directly in the functions of the cycle. The "subroutines" of the cycle are the individual functions of the cycle, and all other functions that were called directly by them. The "callers" of the cycle are the functions, outside the cycle, that called functions in the cycle. Here is an example portion of a call graph which shows a cycle containing functions `a' and `b'. The cycle was entered by a call to `a' from `main'; both `a' and `b' called `c'. index % time self children called name ---------------------------------------- 1.77 0 1/1 main [2] [3] 91.71 1.77 0 1+5 [3] 1.02 0 3 b [4] 0.75 0 2 a [5] ---------------------------------------- 3 a [5] [4] 52.85 1.02 0 0 b [4] 2 a [5] 0 0 3/6 c [6] ---------------------------------------- 1.77 0 1/1 main [2] 2 b [4] [5] 38.86 0.75 0 1 a [5] 3 b [4] 0 0 3/6 c [6] ---------------------------------------- (The entire call graph for this program contains in addition an entry for `main', which calls `a', and an entry for `c', with callers `a' and `b'.) index % time self children called name [1] 100.00 0 1.93 0 start [1] 0.16 1.77 1/1 main [2] ---------------------------------------- 0.16 1.77 1/1 start [1] [2] 100.00 0.16 1.77 1 main [2] 1.77 0 1/1 a [5] ---------------------------------------- 1.77 0 1/1 main [2] [3] 91.71 1.77 0 1+5 [3] 1.02 0 3 b [4] 0.75 0 2 a [5] 0 0 6/6 c [6] ---------------------------------------- 3 a [5] [4] 52.85 1.02 0 0 b [4] 2 a [5] 0 0 3/6 c [6] ---------------------------------------- 1.77 0 1/1 main [2] 2 b [4] [5] 38.86 0.75 0 1 a [5] 3 b [4] 0 0 3/6 c [6] ---------------------------------------- 0 0 3/6 b [4] 0 0 3/6 a [5] [6] 0.00 0 0 6 c [6] ---------------------------------------- The `self' field of the cycle's primary line is the total time spent in all the functions of the cycle. It equals the sum of the `self' fields for the individual functions in the cycle, found in the entry in the subroutine lines for these functions. The `children' fields of the cycle's primary line and subroutine lines count only subroutines outside the cycle. Even though `a' calls `b', the time spent in those calls to `b' is not counted in `a''s `children' time. Thus, we do not encounter the problem of what to do when the time in those calls to `b' includes indirect recursive calls back to `a'. The `children' field of a caller-line in the cycle's entry estimates the amount of time spent _in the whole cycle_, and its other subroutines, on the times when that caller called a function in the cycle. The `called' field in the primary line for the cycle has two numbers: first, the number of times functions in the cycle were called by functions outside the cycle; second, the number of times they were called by functions in the cycle (including times when a function in the cycle calls itself). This is a generalization of the usual split into non-recursive and recursive calls. The `called' field of a subroutine-line for a cycle member in the cycle's entry says how many time that function was called from functions in the cycle. The total of all these is the second number in the primary line's `called' field. In the individual entry for a function in a cycle, the other functions in the same cycle can appear as subroutines and as callers. These lines show how many times each function in the cycle called or was called from each other function in the cycle. The `self' and `children' fields in these lines are blank because of the difficulty of defining meanings for them when recursion is going on.  File: gprof.info, Node: Line-by-line, Next: Annotated Source, Prev: Call Graph, Up: Output 5.3 Line-by-line Profiling ========================== `gprof''s `-l' option causes the program to perform "line-by-line" profiling. In this mode, histogram samples are assigned not to functions, but to individual lines of source code. This only works with programs compiled with older versions of the `gcc' compiler. Newer versions of `gcc' use a different program - `gcov' - to display line-by-line profiling information. With the older versions of `gcc' the program usually has to be compiled with a `-g' option, in addition to `-pg', in order to generate debugging symbols for tracking source code lines. Note, in much older versions of `gcc' the program had to be compiled with the `-a' command line option as well. The flat profile is the most useful output table in line-by-line mode. The call graph isn't as useful as normal, since the current version of `gprof' does not propagate call graph arcs from source code lines to the enclosing function. The call graph does, however, show each line of code that called each function, along with a count. Here is a section of `gprof''s output, without line-by-line profiling. Note that `ct_init' accounted for four histogram hits, and 13327 calls to `init_block'. Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls us/call us/call name 30.77 0.13 0.04 6335 6.31 6.31 ct_init Call graph (explanation follows) granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds index % time self children called name 0.00 0.00 1/13496 name_too_long 0.00 0.00 40/13496 deflate 0.00 0.00 128/13496 deflate_fast 0.00 0.00 13327/13496 ct_init [7] 0.0 0.00 0.00 13496 init_block Now let's look at some of `gprof''s output from the same program run, this time with line-by-line profiling enabled. Note that `ct_init''s four histogram hits are broken down into four lines of source code--one hit occurred on each of lines 349, 351, 382 and 385. In the call graph, note how `ct_init''s 13327 calls to `init_block' are broken down into one call from line 396, 3071 calls from line 384, 3730 calls from line 385, and 6525 calls from 387. Flat profile: Each sample counts as 0.01 seconds. % cumulative self time seconds seconds calls name 7.69 0.10 0.01 ct_init (trees.c:349) 7.69 0.11 0.01 ct_init (trees.c:351) 7.69 0.12 0.01 ct_init (trees.c:382) 7.69 0.13 0.01 ct_init (trees.c:385) Call graph (explanation follows) granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds % time self children called name 0.00 0.00 1/13496 name_too_long (gzip.c:1440) 0.00 0.00 1/13496 deflate (deflate.c:763) 0.00 0.00 1/13496 ct_init (trees.c:396) 0.00 0.00 2/13496 deflate (deflate.c:727) 0.00 0.00 4/13496 deflate (deflate.c:686) 0.00 0.00 5/13496 deflate (deflate.c:675) 0.00 0.00 12/13496 deflate (deflate.c:679) 0.00 0.00 16/13496 deflate (deflate.c:730) 0.00 0.00 128/13496 deflate_fast (deflate.c:654) 0.00 0.00 3071/13496 ct_init (trees.c:384) 0.00 0.00 3730/13496 ct_init (trees.c:385) 0.00 0.00 6525/13496 ct_init (trees.c:387) [6] 0.0 0.00 0.00 13496 init_block (trees.c:408)  File: gprof.info, Node: Annotated Source, Prev: Line-by-line, Up: Output 5.4 The Annotated Source Listing ================================ `gprof''s `-A' option triggers an annotated source listing, which lists the program's source code, each function labeled with the number of times it was called. You may also need to specify the `-I' option, if `gprof' can't find the source code files. With older versions of `gcc' compiling with `gcc ... -g -pg -a' augments your program with basic-block counting code, in addition to function counting code. This enables `gprof' to determine how many times each line of code was executed. With newer versions of `gcc' support for displaying basic-block counts is provided by the `gcov' program. For example, consider the following function, taken from gzip, with line numbers added: 1 ulg updcrc(s, n) 2 uch *s; 3 unsigned n;