1This is gprof.info, produced by makeinfo version 4.8 from gprof.texi. 2 3INFO-DIR-SECTION Software development 4START-INFO-DIR-ENTRY 5* gprof: (gprof). Profiling your program's execution 6END-INFO-DIR-ENTRY 7 8 This file documents the gprof profiler of the GNU system. 9 10 Copyright (C) 1988-2016 Free Software Foundation, Inc. 11 12 Permission is granted to copy, distribute and/or modify this document 13under the terms of the GNU Free Documentation License, Version 1.3 or 14any later version published by the Free Software Foundation; with no 15Invariant Sections, with no Front-Cover Texts, and with no Back-Cover 16Texts. A copy of the license is included in the section entitled "GNU 17Free Documentation License". 18 19 20File: gprof.info, Node: Top, Next: Introduction, Up: (dir) 21 22Profiling a Program: Where Does It Spend Its Time? 23************************************************** 24 25This manual describes the GNU profiler, `gprof', and how you can use it 26to determine which parts of a program are taking most of the execution 27time. We assume that you know how to write, compile, and execute 28programs. GNU `gprof' was written by Jay Fenlason. 29 30 This manual is for `gprof' (GNU Binutils) version 2.27. 31 32 This document is distributed under the terms of the GNU Free 33Documentation License version 1.3. A copy of the license is included 34in the section entitled "GNU Free Documentation License". 35 36* Menu: 37 38* Introduction:: What profiling means, and why it is useful. 39 40* Compiling:: How to compile your program for profiling. 41* Executing:: Executing your program to generate profile data 42* Invoking:: How to run `gprof', and its options 43 44* Output:: Interpreting `gprof''s output 45 46* Inaccuracy:: Potential problems you should be aware of 47* How do I?:: Answers to common questions 48* Incompatibilities:: (between GNU `gprof' and Unix `gprof'.) 49* Details:: Details of how profiling is done 50* GNU Free Documentation License:: GNU Free Documentation License 51 52 53File: gprof.info, Node: Introduction, Next: Compiling, Prev: Top, Up: Top 54 551 Introduction to Profiling 56*************************** 57 58Profiling allows you to learn where your program spent its time and 59which functions called which other functions while it was executing. 60This information can show you which pieces of your program are slower 61than you expected, and might be candidates for rewriting to make your 62program execute faster. It can also tell you which functions are being 63called more or less often than you expected. This may help you spot 64bugs that had otherwise been unnoticed. 65 66 Since the profiler uses information collected during the actual 67execution of your program, it can be used on programs that are too 68large or too complex to analyze by reading the source. However, how 69your program is run will affect the information that shows up in the 70profile data. If you don't use some feature of your program while it 71is being profiled, no profile information will be generated for that 72feature. 73 74 Profiling has several steps: 75 76 * You must compile and link your program with profiling enabled. 77 *Note Compiling a Program for Profiling: Compiling. 78 79 * You must execute your program to generate a profile data file. 80 *Note Executing the Program: Executing. 81 82 * You must run `gprof' to analyze the profile data. *Note `gprof' 83 Command Summary: Invoking. 84 85 The next three chapters explain these steps in greater detail. 86 87 Several forms of output are available from the analysis. 88 89 The "flat profile" shows how much time your program spent in each 90function, and how many times that function was called. If you simply 91want to know which functions burn most of the cycles, it is stated 92concisely here. *Note The Flat Profile: Flat Profile. 93 94 The "call graph" shows, for each function, which functions called 95it, which other functions it called, and how many times. There is also 96an estimate of how much time was spent in the subroutines of each 97function. This can suggest places where you might try to eliminate 98function calls that use a lot of time. *Note The Call Graph: Call 99Graph. 100 101 The "annotated source" listing is a copy of the program's source 102code, labeled with the number of times each line of the program was 103executed. *Note The Annotated Source Listing: Annotated Source. 104 105 To better understand how profiling works, you may wish to read a 106description of its implementation. *Note Implementation of Profiling: 107Implementation. 108 109 110File: gprof.info, Node: Compiling, Next: Executing, Prev: Introduction, Up: Top 111 1122 Compiling a Program for Profiling 113*********************************** 114 115The first step in generating profile information for your program is to 116compile and link it with profiling enabled. 117 118 To compile a source file for profiling, specify the `-pg' option when 119you run the compiler. (This is in addition to the options you normally 120use.) 121 122 To link the program for profiling, if you use a compiler such as `cc' 123to do the linking, simply specify `-pg' in addition to your usual 124options. The same option, `-pg', alters either compilation or linking 125to do what is necessary for profiling. Here are examples: 126 127 cc -g -c myprog.c utils.c -pg 128 cc -o myprog myprog.o utils.o -pg 129 130 The `-pg' option also works with a command that both compiles and 131links: 132 133 cc -o myprog myprog.c utils.c -g -pg 134 135 Note: The `-pg' option must be part of your compilation options as 136well as your link options. If it is not then no call-graph data will 137be gathered and when you run `gprof' you will get an error message like 138this: 139 140 gprof: gmon.out file is missing call-graph data 141 142 If you add the `-Q' switch to suppress the printing of the call 143graph data you will still be able to see the time samples: 144 145 Flat profile: 146 147 Each sample counts as 0.01 seconds. 148 % cumulative self self total 149 time seconds seconds calls Ts/call Ts/call name 150 44.12 0.07 0.07 zazLoop 151 35.29 0.14 0.06 main 152 20.59 0.17 0.04 bazMillion 153 154 If you run the linker `ld' directly instead of through a compiler 155such as `cc', you may have to specify a profiling startup file 156`gcrt0.o' as the first input file instead of the usual startup file 157`crt0.o'. In addition, you would probably want to specify the 158profiling C library, `libc_p.a', by writing `-lc_p' instead of the 159usual `-lc'. This is not absolutely necessary, but doing this gives 160you number-of-calls information for standard library functions such as 161`read' and `open'. For example: 162 163 ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p 164 165 If you are running the program on a system which supports shared 166libraries you may run into problems with the profiling support code in 167a shared library being called before that library has been fully 168initialised. This is usually detected by the program encountering a 169segmentation fault as soon as it is run. The solution is to link 170against a static version of the library containing the profiling 171support code, which for `gcc' users can be done via the `-static' or 172`-static-libgcc' command line option. For example: 173 174 gcc -g -pg -static-libgcc myprog.c utils.c -o myprog 175 176 If you compile only some of the modules of the program with `-pg', 177you can still profile the program, but you won't get complete 178information about the modules that were compiled without `-pg'. The 179only information you get for the functions in those modules is the 180total time spent in them; there is no record of how many times they 181were called, or from where. This will not affect the flat profile 182(except that the `calls' field for the functions will be blank), but 183will greatly reduce the usefulness of the call graph. 184 185 If you wish to perform line-by-line profiling you should use the 186`gcov' tool instead of `gprof'. See that tool's manual or info pages 187for more details of how to do this. 188 189 Note, older versions of `gcc' produce line-by-line profiling 190information that works with `gprof' rather than `gcov' so there is 191still support for displaying this kind of information in `gprof'. *Note 192Line-by-line Profiling: Line-by-line. 193 194 It also worth noting that `gcc' implements a 195`-finstrument-functions' command line option which will insert calls to 196special user supplied instrumentation routines at the entry and exit of 197every function in their program. This can be used to implement an 198alternative profiling scheme. 199 200 201File: gprof.info, Node: Executing, Next: Invoking, Prev: Compiling, Up: Top 202 2033 Executing the Program 204*********************** 205 206Once the program is compiled for profiling, you must run it in order to 207generate the information that `gprof' needs. Simply run the program as 208usual, using the normal arguments, file names, etc. The program should 209run normally, producing the same output as usual. It will, however, run 210somewhat slower than normal because of the time spent collecting and 211writing the profile data. 212 213 The way you run the program--the arguments and input that you give 214it--may have a dramatic effect on what the profile information shows. 215The profile data will describe the parts of the program that were 216activated for the particular input you use. For example, if the first 217command you give to your program is to quit, the profile data will show 218the time used in initialization and in cleanup, but not much else. 219 220 Your program will write the profile data into a file called 221`gmon.out' just before exiting. If there is already a file called 222`gmon.out', its contents are overwritten. There is currently no way to 223tell the program to write the profile data under a different name, but 224you can rename the file afterwards if you are concerned that it may be 225overwritten. 226 227 In order to write the `gmon.out' file properly, your program must 228exit normally: by returning from `main' or by calling `exit'. Calling 229the low-level function `_exit' does not write the profile data, and 230neither does abnormal termination due to an unhandled signal. 231 232 The `gmon.out' file is written in the program's _current working 233directory_ at the time it exits. This means that if your program calls 234`chdir', the `gmon.out' file will be left in the last directory your 235program `chdir''d to. If you don't have permission to write in this 236directory, the file is not written, and you will get an error message. 237 238 Older versions of the GNU profiling library may also write a file 239called `bb.out'. This file, if present, contains an human-readable 240listing of the basic-block execution counts. Unfortunately, the 241appearance of a human-readable `bb.out' means the basic-block counts 242didn't get written into `gmon.out'. The Perl script `bbconv.pl', 243included with the `gprof' source distribution, will convert a `bb.out' 244file into a format readable by `gprof'. Invoke it like this: 245 246 bbconv.pl < bb.out > BH-DATA 247 248 This translates the information in `bb.out' into a form that `gprof' 249can understand. But you still need to tell `gprof' about the existence 250of this translated information. To do that, include BB-DATA on the 251`gprof' command line, _along with `gmon.out'_, like this: 252 253 gprof OPTIONS EXECUTABLE-FILE gmon.out BB-DATA [YET-MORE-PROFILE-DATA-FILES...] [> OUTFILE] 254 255 256File: gprof.info, Node: Invoking, Next: Output, Prev: Executing, Up: Top 257 2584 `gprof' Command Summary 259************************* 260 261After you have a profile data file `gmon.out', you can run `gprof' to 262interpret the information in it. The `gprof' program prints a flat 263profile and a call graph on standard output. Typically you would 264redirect the output of `gprof' into a file with `>'. 265 266 You run `gprof' like this: 267 268 gprof OPTIONS [EXECUTABLE-FILE [PROFILE-DATA-FILES...]] [> OUTFILE] 269 270Here square-brackets indicate optional arguments. 271 272 If you omit the executable file name, the file `a.out' is used. If 273you give no profile data file name, the file `gmon.out' is used. If 274any file is not in the proper format, or if the profile data file does 275not appear to belong to the executable file, an error message is 276printed. 277 278 You can give more than one profile data file by entering all their 279names after the executable file name; then the statistics in all the 280data files are summed together. 281 282 The order of these options does not matter. 283 284* Menu: 285 286* Output Options:: Controlling `gprof''s output style 287* Analysis Options:: Controlling how `gprof' analyzes its data 288* Miscellaneous Options:: 289* Deprecated Options:: Options you no longer need to use, but which 290 have been retained for compatibility 291* Symspecs:: Specifying functions to include or exclude 292 293 294File: gprof.info, Node: Output Options, Next: Analysis Options, Up: Invoking 295 2964.1 Output Options 297================== 298 299These options specify which of several output formats `gprof' should 300produce. 301 302 Many of these options take an optional "symspec" to specify 303functions to be included or excluded. These options can be specified 304multiple times, with different symspecs, to include or exclude sets of 305symbols. *Note Symspecs: Symspecs. 306 307 Specifying any of these options overrides the default (`-p -q'), 308which prints a flat profile and call graph analysis for all functions. 309 310`-A[SYMSPEC]' 311`--annotated-source[=SYMSPEC]' 312 The `-A' option causes `gprof' to print annotated source code. If 313 SYMSPEC is specified, print output only for matching symbols. 314 *Note The Annotated Source Listing: Annotated Source. 315 316`-b' 317`--brief' 318 If the `-b' option is given, `gprof' doesn't print the verbose 319 blurbs that try to explain the meaning of all of the fields in the 320 tables. This is useful if you intend to print out the output, or 321 are tired of seeing the blurbs. 322 323`-C[SYMSPEC]' 324`--exec-counts[=SYMSPEC]' 325 The `-C' option causes `gprof' to print a tally of functions and 326 the number of times each was called. If SYMSPEC is specified, 327 print tally only for matching symbols. 328 329 If the profile data file contains basic-block count records, 330 specifying the `-l' option, along with `-C', will cause basic-block 331 execution counts to be tallied and displayed. 332 333`-i' 334`--file-info' 335 The `-i' option causes `gprof' to display summary information 336 about the profile data file(s) and then exit. The number of 337 histogram, call graph, and basic-block count records is displayed. 338 339`-I DIRS' 340`--directory-path=DIRS' 341 The `-I' option specifies a list of search directories in which to 342 find source files. Environment variable GPROF_PATH can also be 343 used to convey this information. Used mostly for annotated source 344 output. 345 346`-J[SYMSPEC]' 347`--no-annotated-source[=SYMSPEC]' 348 The `-J' option causes `gprof' not to print annotated source code. 349 If SYMSPEC is specified, `gprof' prints annotated source, but 350 excludes matching symbols. 351 352`-L' 353`--print-path' 354 Normally, source filenames are printed with the path component 355 suppressed. The `-L' option causes `gprof' to print the full 356 pathname of source filenames, which is determined from symbolic 357 debugging information in the image file and is relative to the 358 directory in which the compiler was invoked. 359 360`-p[SYMSPEC]' 361`--flat-profile[=SYMSPEC]' 362 The `-p' option causes `gprof' to print a flat profile. If 363 SYMSPEC is specified, print flat profile only for matching symbols. 364 *Note The Flat Profile: Flat Profile. 365 366`-P[SYMSPEC]' 367`--no-flat-profile[=SYMSPEC]' 368 The `-P' option causes `gprof' to suppress printing a flat profile. 369 If SYMSPEC is specified, `gprof' prints a flat profile, but 370 excludes matching symbols. 371 372`-q[SYMSPEC]' 373`--graph[=SYMSPEC]' 374 The `-q' option causes `gprof' to print the call graph analysis. 375 If SYMSPEC is specified, print call graph only for matching symbols 376 and their children. *Note The Call Graph: Call Graph. 377 378`-Q[SYMSPEC]' 379`--no-graph[=SYMSPEC]' 380 The `-Q' option causes `gprof' to suppress printing the call graph. 381 If SYMSPEC is specified, `gprof' prints a call graph, but excludes 382 matching symbols. 383 384`-t' 385`--table-length=NUM' 386 The `-t' option causes the NUM most active source lines in each 387 source file to be listed when source annotation is enabled. The 388 default is 10. 389 390`-y' 391`--separate-files' 392 This option affects annotated source output only. Normally, 393 `gprof' prints annotated source files to standard-output. If this 394 option is specified, annotated source for a file named 395 `path/FILENAME' is generated in the file `FILENAME-ann'. If the 396 underlying file system would truncate `FILENAME-ann' so that it 397 overwrites the original `FILENAME', `gprof' generates annotated 398 source in the file `FILENAME.ann' instead (if the original file 399 name has an extension, that extension is _replaced_ with `.ann'). 400 401`-Z[SYMSPEC]' 402`--no-exec-counts[=SYMSPEC]' 403 The `-Z' option causes `gprof' not to print a tally of functions 404 and the number of times each was called. If SYMSPEC is specified, 405 print tally, but exclude matching symbols. 406 407`-r' 408`--function-ordering' 409 The `--function-ordering' option causes `gprof' to print a 410 suggested function ordering for the program based on profiling 411 data. This option suggests an ordering which may improve paging, 412 tlb and cache behavior for the program on systems which support 413 arbitrary ordering of functions in an executable. 414 415 The exact details of how to force the linker to place functions in 416 a particular order is system dependent and out of the scope of this 417 manual. 418 419`-R MAP_FILE' 420`--file-ordering MAP_FILE' 421 The `--file-ordering' option causes `gprof' to print a suggested 422 .o link line ordering for the program based on profiling data. 423 This option suggests an ordering which may improve paging, tlb and 424 cache behavior for the program on systems which do not support 425 arbitrary ordering of functions in an executable. 426 427 Use of the `-a' argument is highly recommended with this option. 428 429 The MAP_FILE argument is a pathname to a file which provides 430 function name to object file mappings. The format of the file is 431 similar to the output of the program `nm'. 432 433 c-parse.o:00000000 T yyparse 434 c-parse.o:00000004 C yyerrflag 435 c-lang.o:00000000 T maybe_objc_method_name 436 c-lang.o:00000000 T print_lang_statistics 437 c-lang.o:00000000 T recognize_objc_keyword 438 c-decl.o:00000000 T print_lang_identifier 439 c-decl.o:00000000 T print_lang_type 440 ... 441 442 To create a MAP_FILE with GNU `nm', type a command like `nm 443 --extern-only --defined-only -v --print-file-name program-name'. 444 445`-T' 446`--traditional' 447 The `-T' option causes `gprof' to print its output in 448 "traditional" BSD style. 449 450`-w WIDTH' 451`--width=WIDTH' 452 Sets width of output lines to WIDTH. Currently only used when 453 printing the function index at the bottom of the call graph. 454 455`-x' 456`--all-lines' 457 This option affects annotated source output only. By default, 458 only the lines at the beginning of a basic-block are annotated. 459 If this option is specified, every line in a basic-block is 460 annotated by repeating the annotation for the first line. This 461 behavior is similar to `tcov''s `-a'. 462 463`--demangle[=STYLE]' 464`--no-demangle' 465 These options control whether C++ symbol names should be demangled 466 when printing output. The default is to demangle symbols. The 467 `--no-demangle' option may be used to turn off demangling. 468 Different compilers have different mangling styles. The optional 469 demangling style argument can be used to choose an appropriate 470 demangling style for your compiler. 471 472 473File: gprof.info, Node: Analysis Options, Next: Miscellaneous Options, Prev: Output Options, Up: Invoking 474 4754.2 Analysis Options 476==================== 477 478`-a' 479`--no-static' 480 The `-a' option causes `gprof' to suppress the printing of 481 statically declared (private) functions. (These are functions 482 whose names are not listed as global, and which are not visible 483 outside the file/function/block where they were defined.) Time 484 spent in these functions, calls to/from them, etc., will all be 485 attributed to the function that was loaded directly before it in 486 the executable file. This option affects both the flat profile 487 and the call graph. 488 489`-c' 490`--static-call-graph' 491 The `-c' option causes the call graph of the program to be 492 augmented by a heuristic which examines the text space of the 493 object file and identifies function calls in the binary machine 494 code. Since normal call graph records are only generated when 495 functions are entered, this option identifies children that could 496 have been called, but never were. Calls to functions that were 497 not compiled with profiling enabled are also identified, but only 498 if symbol table entries are present for them. Calls to dynamic 499 library routines are typically _not_ found by this option. 500 Parents or children identified via this heuristic are indicated in 501 the call graph with call counts of `0'. 502 503`-D' 504`--ignore-non-functions' 505 The `-D' option causes `gprof' to ignore symbols which are not 506 known to be functions. This option will give more accurate 507 profile data on systems where it is supported (Solaris and HPUX for 508 example). 509 510`-k FROM/TO' 511 The `-k' option allows you to delete from the call graph any arcs 512 from symbols matching symspec FROM to those matching symspec TO. 513 514`-l' 515`--line' 516 The `-l' option enables line-by-line profiling, which causes 517 histogram hits to be charged to individual source code lines, 518 instead of functions. This feature only works with programs 519 compiled by older versions of the `gcc' compiler. Newer versions 520 of `gcc' are designed to work with the `gcov' tool instead. 521 522 If the program was compiled with basic-block counting enabled, 523 this option will also identify how many times each line of code 524 was executed. While line-by-line profiling can help isolate where 525 in a large function a program is spending its time, it also 526 significantly increases the running time of `gprof', and magnifies 527 statistical inaccuracies. *Note Statistical Sampling Error: 528 Sampling Error. 529 530`--inline-file-names' 531 This option causes `gprof' to print the source file after each 532 symbol in both the flat profile and the call graph. The full path 533 to the file is printed if used with the `-L' option. 534 535`-m NUM' 536`--min-count=NUM' 537 This option affects execution count output only. Symbols that are 538 executed less than NUM times are suppressed. 539 540`-nSYMSPEC' 541`--time=SYMSPEC' 542 The `-n' option causes `gprof', in its call graph analysis, to 543 only propagate times for symbols matching SYMSPEC. 544 545`-NSYMSPEC' 546`--no-time=SYMSPEC' 547 The `-n' option causes `gprof', in its call graph analysis, not to 548 propagate times for symbols matching SYMSPEC. 549 550`-SFILENAME' 551`--external-symbol-table=FILENAME' 552 The `-S' option causes `gprof' to read an external symbol table 553 file, such as `/proc/kallsyms', rather than read the symbol table 554 from the given object file (the default is `a.out'). This is useful 555 for profiling kernel modules. 556 557`-z' 558`--display-unused-functions' 559 If you give the `-z' option, `gprof' will mention all functions in 560 the flat profile, even those that were never called, and that had 561 no time spent in them. This is useful in conjunction with the 562 `-c' option for discovering which routines were never called. 563 564 565 566File: gprof.info, Node: Miscellaneous Options, Next: Deprecated Options, Prev: Analysis Options, Up: Invoking 567 5684.3 Miscellaneous Options 569========================= 570 571`-d[NUM]' 572`--debug[=NUM]' 573 The `-d NUM' option specifies debugging options. If NUM is not 574 specified, enable all debugging. *Note Debugging `gprof': 575 Debugging. 576 577`-h' 578`--help' 579 The `-h' option prints command line usage. 580 581`-ONAME' 582`--file-format=NAME' 583 Selects the format of the profile data files. Recognized formats 584 are `auto' (the default), `bsd', `4.4bsd', `magic', and `prof' 585 (not yet supported). 586 587`-s' 588`--sum' 589 The `-s' option causes `gprof' to summarize the information in the 590 profile data files it read in, and write out a profile data file 591 called `gmon.sum', which contains all the information from the 592 profile data files that `gprof' read in. The file `gmon.sum' may 593 be one of the specified input files; the effect of this is to 594 merge the data in the other input files into `gmon.sum'. 595 596 Eventually you can run `gprof' again without `-s' to analyze the 597 cumulative data in the file `gmon.sum'. 598 599`-v' 600`--version' 601 The `-v' flag causes `gprof' to print the current version number, 602 and then exit. 603 604 605 606File: gprof.info, Node: Deprecated Options, Next: Symspecs, Prev: Miscellaneous Options, Up: Invoking 607 6084.4 Deprecated Options 609====================== 610 611These options have been replaced with newer versions that use symspecs. 612 613`-e FUNCTION_NAME' 614 The `-e FUNCTION' option tells `gprof' to not print information 615 about the function FUNCTION_NAME (and its children...) in the call 616 graph. The function will still be listed as a child of any 617 functions that call it, but its index number will be shown as 618 `[not printed]'. More than one `-e' option may be given; only one 619 FUNCTION_NAME may be indicated with each `-e' option. 620 621`-E FUNCTION_NAME' 622 The `-E FUNCTION' option works like the `-e' option, but time 623 spent in the function (and children who were not called from 624 anywhere else), will not be used to compute the 625 percentages-of-time for the call graph. More than one `-E' option 626 may be given; only one FUNCTION_NAME may be indicated with each 627 `-E' option. 628 629`-f FUNCTION_NAME' 630 The `-f FUNCTION' option causes `gprof' to limit the call graph to 631 the function FUNCTION_NAME and its children (and their 632 children...). More than one `-f' option may be given; only one 633 FUNCTION_NAME may be indicated with each `-f' option. 634 635`-F FUNCTION_NAME' 636 The `-F FUNCTION' option works like the `-f' option, but only time 637 spent in the function and its children (and their children...) 638 will be used to determine total-time and percentages-of-time for 639 the call graph. More than one `-F' option may be given; only one 640 FUNCTION_NAME may be indicated with each `-F' option. The `-F' 641 option overrides the `-E' option. 642 643 644 Note that only one function can be specified with each `-e', `-E', 645`-f' or `-F' option. To specify more than one function, use multiple 646options. For example, this command: 647 648 gprof -e boring -f foo -f bar myprogram > gprof.output 649 650lists in the call graph all functions that were reached from either 651`foo' or `bar' and were not reachable from `boring'. 652 653 654File: gprof.info, Node: Symspecs, Prev: Deprecated Options, Up: Invoking 655 6564.5 Symspecs 657============ 658 659Many of the output options allow functions to be included or excluded 660using "symspecs" (symbol specifications), which observe the following 661syntax: 662 663 filename_containing_a_dot 664 | funcname_not_containing_a_dot 665 | linenumber 666 | ( [ any_filename ] `:' ( any_funcname | linenumber ) ) 667 668 Here are some sample symspecs: 669 670`main.c' 671 Selects everything in file `main.c'--the dot in the string tells 672 `gprof' to interpret the string as a filename, rather than as a 673 function name. To select a file whose name does not contain a 674 dot, a trailing colon should be specified. For example, `odd:' is 675 interpreted as the file named `odd'. 676 677`main' 678 Selects all functions named `main'. 679 680 Note that there may be multiple instances of the same function name 681 because some of the definitions may be local (i.e., static). 682 Unless a function name is unique in a program, you must use the 683 colon notation explained below to specify a function from a 684 specific source file. 685 686 Sometimes, function names contain dots. In such cases, it is 687 necessary to add a leading colon to the name. For example, 688 `:.mul' selects function `.mul'. 689 690 In some object file formats, symbols have a leading underscore. 691 `gprof' will normally not print these underscores. When you name a 692 symbol in a symspec, you should type it exactly as `gprof' prints 693 it in its output. For example, if the compiler produces a symbol 694 `_main' from your `main' function, `gprof' still prints it as 695 `main' in its output, so you should use `main' in symspecs. 696 697`main.c:main' 698 Selects function `main' in file `main.c'. 699 700`main.c:134' 701 Selects line 134 in file `main.c'. 702 703 704File: gprof.info, Node: Output, Next: Inaccuracy, Prev: Invoking, Up: Top 705 7065 Interpreting `gprof''s Output 707******************************* 708 709`gprof' can produce several different output styles, the most important 710of which are described below. The simplest output styles (file 711information, execution count, and function and file ordering) are not 712described here, but are documented with the respective options that 713trigger them. *Note Output Options: Output Options. 714 715* Menu: 716 717* Flat Profile:: The flat profile shows how much time was spent 718 executing directly in each function. 719* Call Graph:: The call graph shows which functions called which 720 others, and how much time each function used 721 when its subroutine calls are included. 722* Line-by-line:: `gprof' can analyze individual source code lines 723* Annotated Source:: The annotated source listing displays source code 724 labeled with execution counts 725 726 727File: gprof.info, Node: Flat Profile, Next: Call Graph, Up: Output 728 7295.1 The Flat Profile 730==================== 731 732The "flat profile" shows the total amount of time your program spent 733executing each function. Unless the `-z' option is given, functions 734with no apparent time spent in them, and no apparent calls to them, are 735not mentioned. Note that if a function was not compiled for profiling, 736and didn't run long enough to show up on the program counter histogram, 737it will be indistinguishable from a function that was never called. 738 739 This is part of a flat profile for a small program: 740 741 Flat profile: 742 743 Each sample counts as 0.01 seconds. 744 % cumulative self self total 745 time seconds seconds calls ms/call ms/call name 746 33.34 0.02 0.02 7208 0.00 0.00 open 747 16.67 0.03 0.01 244 0.04 0.12 offtime 748 16.67 0.04 0.01 8 1.25 1.25 memccpy 749 16.67 0.05 0.01 7 1.43 1.43 write 750 16.67 0.06 0.01 mcount 751 0.00 0.06 0.00 236 0.00 0.00 tzset 752 0.00 0.06 0.00 192 0.00 0.00 tolower 753 0.00 0.06 0.00 47 0.00 0.00 strlen 754 0.00 0.06 0.00 45 0.00 0.00 strchr 755 0.00 0.06 0.00 1 0.00 50.00 main 756 0.00 0.06 0.00 1 0.00 0.00 memcpy 757 0.00 0.06 0.00 1 0.00 10.11 print 758 0.00 0.06 0.00 1 0.00 0.00 profil 759 0.00 0.06 0.00 1 0.00 50.00 report 760 ... 761 762The functions are sorted first by decreasing run-time spent in them, 763then by decreasing number of calls, then alphabetically by name. The 764functions `mcount' and `profil' are part of the profiling apparatus and 765appear in every flat profile; their time gives a measure of the amount 766of overhead due to profiling. 767 768 Just before the column headers, a statement appears indicating how 769much time each sample counted as. This "sampling period" estimates the 770margin of error in each of the time figures. A time figure that is not 771much larger than this is not reliable. In this example, each sample 772counted as 0.01 seconds, suggesting a 100 Hz sampling rate. The 773program's total execution time was 0.06 seconds, as indicated by the 774`cumulative seconds' field. Since each sample counted for 0.01 775seconds, this means only six samples were taken during the run. Two of 776the samples occurred while the program was in the `open' function, as 777indicated by the `self seconds' field. Each of the other four samples 778occurred one each in `offtime', `memccpy', `write', and `mcount'. 779Since only six samples were taken, none of these values can be regarded 780as particularly reliable. In another run, the `self seconds' field for 781`mcount' might well be `0.00' or `0.02'. *Note Statistical Sampling 782Error: Sampling Error, for a complete discussion. 783 784 The remaining functions in the listing (those whose `self seconds' 785field is `0.00') didn't appear in the histogram samples at all. 786However, the call graph indicated that they were called, so therefore 787they are listed, sorted in decreasing order by the `calls' field. 788Clearly some time was spent executing these functions, but the paucity 789of histogram samples prevents any determination of how much time each 790took. 791 792 Here is what the fields in each line mean: 793 794`% time' 795 This is the percentage of the total execution time your program 796 spent in this function. These should all add up to 100%. 797 798`cumulative seconds' 799 This is the cumulative total number of seconds the computer spent 800 executing this functions, plus the time spent in all the functions 801 above this one in this table. 802 803`self seconds' 804 This is the number of seconds accounted for by this function alone. 805 The flat profile listing is sorted first by this number. 806 807`calls' 808 This is the total number of times the function was called. If the 809 function was never called, or the number of times it was called 810 cannot be determined (probably because the function was not 811 compiled with profiling enabled), the "calls" field is blank. 812 813`self ms/call' 814 This represents the average number of milliseconds spent in this 815 function per call, if this function is profiled. Otherwise, this 816 field is blank for this function. 817 818`total ms/call' 819 This represents the average number of milliseconds spent in this 820 function and its descendants per call, if this function is 821 profiled. Otherwise, this field is blank for this function. This 822 is the only field in the flat profile that uses call graph 823 analysis. 824 825`name' 826 This is the name of the function. The flat profile is sorted by 827 this field alphabetically after the "self seconds" and "calls" 828 fields are sorted. 829 830 831File: gprof.info, Node: Call Graph, Next: Line-by-line, Prev: Flat Profile, Up: Output 832 8335.2 The Call Graph 834================== 835 836The "call graph" shows how much time was spent in each function and its 837children. From this information, you can find functions that, while 838they themselves may not have used much time, called other functions 839that did use unusual amounts of time. 840 841 Here is a sample call from a small program. This call came from the 842same `gprof' run as the flat profile example in the previous section. 843 844 granularity: each sample hit covers 2 byte(s) for 20.00% of 0.05 seconds 845 846 index % time self children called name 847 <spontaneous> 848 [1] 100.0 0.00 0.05 start [1] 849 0.00 0.05 1/1 main [2] 850 0.00 0.00 1/2 on_exit [28] 851 0.00 0.00 1/1 exit [59] 852 ----------------------------------------------- 853 0.00 0.05 1/1 start [1] 854 [2] 100.0 0.00 0.05 1 main [2] 855 0.00 0.05 1/1 report [3] 856 ----------------------------------------------- 857 0.00 0.05 1/1 main [2] 858 [3] 100.0 0.00 0.05 1 report [3] 859 0.00 0.03 8/8 timelocal [6] 860 0.00 0.01 1/1 print [9] 861 0.00 0.01 9/9 fgets [12] 862 0.00 0.00 12/34 strncmp <cycle 1> [40] 863 0.00 0.00 8/8 lookup [20] 864 0.00 0.00 1/1 fopen [21] 865 0.00 0.00 8/8 chewtime [24] 866 0.00 0.00 8/16 skipspace [44] 867 ----------------------------------------------- 868 [4] 59.8 0.01 0.02 8+472 <cycle 2 as a whole> [4] 869 0.01 0.02 244+260 offtime <cycle 2> [7] 870 0.00 0.00 236+1 tzset <cycle 2> [26] 871 ----------------------------------------------- 872 873 The lines full of dashes divide this table into "entries", one for 874each function. Each entry has one or more lines. 875 876 In each entry, the primary line is the one that starts with an index 877number in square brackets. The end of this line says which function 878the entry is for. The preceding lines in the entry describe the 879callers of this function and the following lines describe its 880subroutines (also called "children" when we speak of the call graph). 881 882 The entries are sorted by time spent in the function and its 883subroutines. 884 885 The internal profiling function `mcount' (*note The Flat Profile: 886Flat Profile.) is never mentioned in the call graph. 887 888* Menu: 889 890* Primary:: Details of the primary line's contents. 891* Callers:: Details of caller-lines' contents. 892* Subroutines:: Details of subroutine-lines' contents. 893* Cycles:: When there are cycles of recursion, 894 such as `a' calls `b' calls `a'... 895 896 897File: gprof.info, Node: Primary, Next: Callers, Up: Call Graph 898 8995.2.1 The Primary Line 900---------------------- 901 902The "primary line" in a call graph entry is the line that describes the 903function which the entry is about and gives the overall statistics for 904this function. 905 906 For reference, we repeat the primary line from the entry for function 907`report' in our main example, together with the heading line that shows 908the names of the fields: 909 910 index % time self children called name 911 ... 912 [3] 100.0 0.00 0.05 1 report [3] 913 914 Here is what the fields in the primary line mean: 915 916`index' 917 Entries are numbered with consecutive integers. Each function 918 therefore has an index number, which appears at the beginning of 919 its primary line. 920 921 Each cross-reference to a function, as a caller or subroutine of 922 another, gives its index number as well as its name. The index 923 number guides you if you wish to look for the entry for that 924 function. 925 926`% time' 927 This is the percentage of the total time that was spent in this 928 function, including time spent in subroutines called from this 929 function. 930 931 The time spent in this function is counted again for the callers of 932 this function. Therefore, adding up these percentages is 933 meaningless. 934 935`self' 936 This is the total amount of time spent in this function. This 937 should be identical to the number printed in the `seconds' field 938 for this function in the flat profile. 939 940`children' 941 This is the total amount of time spent in the subroutine calls 942 made by this function. This should be equal to the sum of all the 943 `self' and `children' entries of the children listed directly 944 below this function. 945 946`called' 947 This is the number of times the function was called. 948 949 If the function called itself recursively, there are two numbers, 950 separated by a `+'. The first number counts non-recursive calls, 951 and the second counts recursive calls. 952 953 In the example above, the function `report' was called once from 954 `main'. 955 956`name' 957 This is the name of the current function. The index number is 958 repeated after it. 959 960 If the function is part of a cycle of recursion, the cycle number 961 is printed between the function's name and the index number (*note 962 How Mutually Recursive Functions Are Described: Cycles.). For 963 example, if function `gnurr' is part of cycle number one, and has 964 index number twelve, its primary line would be end like this: 965 966 gnurr <cycle 1> [12] 967 968 969File: gprof.info, Node: Callers, Next: Subroutines, Prev: Primary, Up: Call Graph 970 9715.2.2 Lines for a Function's Callers 972------------------------------------ 973 974A function's entry has a line for each function it was called by. 975These lines' fields correspond to the fields of the primary line, but 976their meanings are different because of the difference in context. 977 978 For reference, we repeat two lines from the entry for the function 979`report', the primary line and one caller-line preceding it, together 980with the heading line that shows the names of the fields: 981 982 index % time self children called name 983 ... 984 0.00 0.05 1/1 main [2] 985 [3] 100.0 0.00 0.05 1 report [3] 986 987 Here are the meanings of the fields in the caller-line for `report' 988called from `main': 989 990`self' 991 An estimate of the amount of time spent in `report' itself when it 992 was called from `main'. 993 994`children' 995 An estimate of the amount of time spent in subroutines of `report' 996 when `report' was called from `main'. 997 998 The sum of the `self' and `children' fields is an estimate of the 999 amount of time spent within calls to `report' from `main'. 1000 1001`called' 1002 Two numbers: the number of times `report' was called from `main', 1003 followed by the total number of non-recursive calls to `report' 1004 from all its callers. 1005 1006`name and index number' 1007 The name of the caller of `report' to which this line applies, 1008 followed by the caller's index number. 1009 1010 Not all functions have entries in the call graph; some options to 1011 `gprof' request the omission of certain functions. When a caller 1012 has no entry of its own, it still has caller-lines in the entries 1013 of the functions it calls. 1014 1015 If the caller is part of a recursion cycle, the cycle number is 1016 printed between the name and the index number. 1017 1018 If the identity of the callers of a function cannot be determined, a 1019dummy caller-line is printed which has `<spontaneous>' as the "caller's 1020name" and all other fields blank. This can happen for signal handlers. 1021 1022 1023File: gprof.info, Node: Subroutines, Next: Cycles, Prev: Callers, Up: Call Graph 1024 10255.2.3 Lines for a Function's Subroutines 1026---------------------------------------- 1027 1028A function's entry has a line for each of its subroutines--in other 1029words, a line for each other function that it called. These lines' 1030fields correspond to the fields of the primary line, but their meanings 1031are different because of the difference in context. 1032 1033 For reference, we repeat two lines from the entry for the function 1034`main', the primary line and a line for a subroutine, together with the 1035heading line that shows the names of the fields: 1036 1037 index % time self children called name 1038 ... 1039 [2] 100.0 0.00 0.05 1 main [2] 1040 0.00 0.05 1/1 report [3] 1041 1042 Here are the meanings of the fields in the subroutine-line for `main' 1043calling `report': 1044 1045`self' 1046 An estimate of the amount of time spent directly within `report' 1047 when `report' was called from `main'. 1048 1049`children' 1050 An estimate of the amount of time spent in subroutines of `report' 1051 when `report' was called from `main'. 1052 1053 The sum of the `self' and `children' fields is an estimate of the 1054 total time spent in calls to `report' from `main'. 1055 1056`called' 1057 Two numbers, the number of calls to `report' from `main' followed 1058 by the total number of non-recursive calls to `report'. This 1059 ratio is used to determine how much of `report''s `self' and 1060 `children' time gets credited to `main'. *Note Estimating 1061 `children' Times: Assumptions. 1062 1063`name' 1064 The name of the subroutine of `main' to which this line applies, 1065 followed by the subroutine's index number. 1066 1067 If the caller is part of a recursion cycle, the cycle number is 1068 printed between the name and the index number. 1069 1070 1071File: gprof.info, Node: Cycles, Prev: Subroutines, Up: Call Graph 1072 10735.2.4 How Mutually Recursive Functions Are Described 1074---------------------------------------------------- 1075 1076The graph may be complicated by the presence of "cycles of recursion" 1077in the call graph. A cycle exists if a function calls another function 1078that (directly or indirectly) calls (or appears to call) the original 1079function. For example: if `a' calls `b', and `b' calls `a', then `a' 1080and `b' form a cycle. 1081 1082 Whenever there are call paths both ways between a pair of functions, 1083they belong to the same cycle. If `a' and `b' call each other and `b' 1084and `c' call each other, all three make one cycle. Note that even if 1085`b' only calls `a' if it was not called from `a', `gprof' cannot 1086determine this, so `a' and `b' are still considered a cycle. 1087 1088 The cycles are numbered with consecutive integers. When a function 1089belongs to a cycle, each time the function name appears in the call 1090graph it is followed by `<cycle NUMBER>'. 1091 1092 The reason cycles matter is that they make the time values in the 1093call graph paradoxical. The "time spent in children" of `a' should 1094include the time spent in its subroutine `b' and in `b''s 1095subroutines--but one of `b''s subroutines is `a'! How much of `a''s 1096time should be included in the children of `a', when `a' is indirectly 1097recursive? 1098 1099 The way `gprof' resolves this paradox is by creating a single entry 1100for the cycle as a whole. The primary line of this entry describes the 1101total time spent directly in the functions of the cycle. The 1102"subroutines" of the cycle are the individual functions of the cycle, 1103and all other functions that were called directly by them. The 1104"callers" of the cycle are the functions, outside the cycle, that 1105called functions in the cycle. 1106 1107 Here is an example portion of a call graph which shows a cycle 1108containing functions `a' and `b'. The cycle was entered by a call to 1109`a' from `main'; both `a' and `b' called `c'. 1110 1111 index % time self children called name 1112 ---------------------------------------- 1113 1.77 0 1/1 main [2] 1114 [3] 91.71 1.77 0 1+5 <cycle 1 as a whole> [3] 1115 1.02 0 3 b <cycle 1> [4] 1116 0.75 0 2 a <cycle 1> [5] 1117 ---------------------------------------- 1118 3 a <cycle 1> [5] 1119 [4] 52.85 1.02 0 0 b <cycle 1> [4] 1120 2 a <cycle 1> [5] 1121 0 0 3/6 c [6] 1122 ---------------------------------------- 1123 1.77 0 1/1 main [2] 1124 2 b <cycle 1> [4] 1125 [5] 38.86 0.75 0 1 a <cycle 1> [5] 1126 3 b <cycle 1> [4] 1127 0 0 3/6 c [6] 1128 ---------------------------------------- 1129 1130(The entire call graph for this program contains in addition an entry 1131for `main', which calls `a', and an entry for `c', with callers `a' and 1132`b'.) 1133 1134 index % time self children called name 1135 <spontaneous> 1136 [1] 100.00 0 1.93 0 start [1] 1137 0.16 1.77 1/1 main [2] 1138 ---------------------------------------- 1139 0.16 1.77 1/1 start [1] 1140 [2] 100.00 0.16 1.77 1 main [2] 1141 1.77 0 1/1 a <cycle 1> [5] 1142 ---------------------------------------- 1143 1.77 0 1/1 main [2] 1144 [3] 91.71 1.77 0 1+5 <cycle 1 as a whole> [3] 1145 1.02 0 3 b <cycle 1> [4] 1146 0.75 0 2 a <cycle 1> [5] 1147 0 0 6/6 c [6] 1148 ---------------------------------------- 1149 3 a <cycle 1> [5] 1150 [4] 52.85 1.02 0 0 b <cycle 1> [4] 1151 2 a <cycle 1> [5] 1152 0 0 3/6 c [6] 1153 ---------------------------------------- 1154 1.77 0 1/1 main [2] 1155 2 b <cycle 1> [4] 1156 [5] 38.86 0.75 0 1 a <cycle 1> [5] 1157 3 b <cycle 1> [4] 1158 0 0 3/6 c [6] 1159 ---------------------------------------- 1160 0 0 3/6 b <cycle 1> [4] 1161 0 0 3/6 a <cycle 1> [5] 1162 [6] 0.00 0 0 6 c [6] 1163 ---------------------------------------- 1164 1165 The `self' field of the cycle's primary line is the total time spent 1166in all the functions of the cycle. It equals the sum of the `self' 1167fields for the individual functions in the cycle, found in the entry in 1168the subroutine lines for these functions. 1169 1170 The `children' fields of the cycle's primary line and subroutine 1171lines count only subroutines outside the cycle. Even though `a' calls 1172`b', the time spent in those calls to `b' is not counted in `a''s 1173`children' time. Thus, we do not encounter the problem of what to do 1174when the time in those calls to `b' includes indirect recursive calls 1175back to `a'. 1176 1177 The `children' field of a caller-line in the cycle's entry estimates 1178the amount of time spent _in the whole cycle_, and its other 1179subroutines, on the times when that caller called a function in the 1180cycle. 1181 1182 The `called' field in the primary line for the cycle has two numbers: 1183first, the number of times functions in the cycle were called by 1184functions outside the cycle; second, the number of times they were 1185called by functions in the cycle (including times when a function in 1186the cycle calls itself). This is a generalization of the usual split 1187into non-recursive and recursive calls. 1188 1189 The `called' field of a subroutine-line for a cycle member in the 1190cycle's entry says how many time that function was called from 1191functions in the cycle. The total of all these is the second number in 1192the primary line's `called' field. 1193 1194 In the individual entry for a function in a cycle, the other 1195functions in the same cycle can appear as subroutines and as callers. 1196These lines show how many times each function in the cycle called or 1197was called from each other function in the cycle. The `self' and 1198`children' fields in these lines are blank because of the difficulty of 1199defining meanings for them when recursion is going on. 1200 1201 1202File: gprof.info, Node: Line-by-line, Next: Annotated Source, Prev: Call Graph, Up: Output 1203 12045.3 Line-by-line Profiling 1205========================== 1206 1207`gprof''s `-l' option causes the program to perform "line-by-line" 1208profiling. In this mode, histogram samples are assigned not to 1209functions, but to individual lines of source code. This only works 1210with programs compiled with older versions of the `gcc' compiler. 1211Newer versions of `gcc' use a different program - `gcov' - to display 1212line-by-line profiling information. 1213 1214 With the older versions of `gcc' the program usually has to be 1215compiled with a `-g' option, in addition to `-pg', in order to generate 1216debugging symbols for tracking source code lines. Note, in much older 1217versions of `gcc' the program had to be compiled with the `-a' command 1218line option as well. 1219 1220 The flat profile is the most useful output table in line-by-line 1221mode. The call graph isn't as useful as normal, since the current 1222version of `gprof' does not propagate call graph arcs from source code 1223lines to the enclosing function. The call graph does, however, show 1224each line of code that called each function, along with a count. 1225 1226 Here is a section of `gprof''s output, without line-by-line 1227profiling. Note that `ct_init' accounted for four histogram hits, and 122813327 calls to `init_block'. 1229 1230 Flat profile: 1231 1232 Each sample counts as 0.01 seconds. 1233 % cumulative self self total 1234 time seconds seconds calls us/call us/call name 1235 30.77 0.13 0.04 6335 6.31 6.31 ct_init 1236 1237 1238 Call graph (explanation follows) 1239 1240 1241 granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds 1242 1243 index % time self children called name 1244 1245 0.00 0.00 1/13496 name_too_long 1246 0.00 0.00 40/13496 deflate 1247 0.00 0.00 128/13496 deflate_fast 1248 0.00 0.00 13327/13496 ct_init 1249 [7] 0.0 0.00 0.00 13496 init_block 1250 1251 Now let's look at some of `gprof''s output from the same program run, 1252this time with line-by-line profiling enabled. Note that `ct_init''s 1253four histogram hits are broken down into four lines of source code--one 1254hit occurred on each of lines 349, 351, 382 and 385. In the call graph, 1255note how `ct_init''s 13327 calls to `init_block' are broken down into 1256one call from line 396, 3071 calls from line 384, 3730 calls from line 1257385, and 6525 calls from 387. 1258 1259 Flat profile: 1260 1261 Each sample counts as 0.01 seconds. 1262 % cumulative self 1263 time seconds seconds calls name 1264 7.69 0.10 0.01 ct_init (trees.c:349) 1265 7.69 0.11 0.01 ct_init (trees.c:351) 1266 7.69 0.12 0.01 ct_init (trees.c:382) 1267 7.69 0.13 0.01 ct_init (trees.c:385) 1268 1269 1270 Call graph (explanation follows) 1271 1272 1273 granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds 1274 1275 % time self children called name 1276 1277 0.00 0.00 1/13496 name_too_long (gzip.c:1440) 1278 0.00 0.00 1/13496 deflate (deflate.c:763) 1279 0.00 0.00 1/13496 ct_init (trees.c:396) 1280 0.00 0.00 2/13496 deflate (deflate.c:727) 1281 0.00 0.00 4/13496 deflate (deflate.c:686) 1282 0.00 0.00 5/13496 deflate (deflate.c:675) 1283 0.00 0.00 12/13496 deflate (deflate.c:679) 1284 0.00 0.00 16/13496 deflate (deflate.c:730) 1285 0.00 0.00 128/13496 deflate_fast (deflate.c:654) 1286 0.00 0.00 3071/13496 ct_init (trees.c:384) 1287 0.00 0.00 3730/13496 ct_init (trees.c:385) 1288 0.00 0.00 6525/13496 ct_init (trees.c:387) 1289 [6] 0.0 0.00 0.00 13496 init_block (trees.c:408) 1290 1291 1292File: gprof.info, Node: Annotated Source, Prev: Line-by-line, Up: Output 1293 12945.4 The Annotated Source Listing 1295================================ 1296 1297`gprof''s `-A' option triggers an annotated source listing, which lists 1298the program's source code, each function labeled with the number of 1299times it was called. You may also need to specify the `-I' option, if 1300`gprof' can't find the source code files. 1301 1302 With older versions of `gcc' compiling with `gcc ... -g -pg -a' 1303augments your program with basic-block counting code, in addition to 1304function counting code. This enables `gprof' to determine how many 1305times each line of code was executed. With newer versions of `gcc' 1306support for displaying basic-block counts is provided by the `gcov' 1307program. 1308 1309 For example, consider the following function, taken from gzip, with 1310line numbers added: 1311 1312 1 ulg updcrc(s, n) 1313 2 uch *s; 1314 3 unsigned n; 1315 4 { 1316 5 register ulg c; 1317 6 1318 7 static ulg crc = (ulg)0xffffffffL; 1319 8 1320 9 if (s == NULL) { 1321 10 c = 0xffffffffL; 1322 11 } else { 1323 12 c = crc; 1324 13 if (n) do { 1325 14 c = crc_32_tab[...]; 1326 15 } while (--n); 1327 16 } 1328 17 crc = c; 1329 18 return c ^ 0xffffffffL; 1330 19 } 1331 1332 `updcrc' has at least five basic-blocks. One is the function 1333itself. The `if' statement on line 9 generates two more basic-blocks, 1334one for each branch of the `if'. A fourth basic-block results from the 1335`if' on line 13, and the contents of the `do' loop form the fifth 1336basic-block. The compiler may also generate additional basic-blocks to 1337handle various special cases. 1338 1339 A program augmented for basic-block counting can be analyzed with 1340`gprof -l -A'. The `-x' option is also helpful, to ensure that each 1341line of code is labeled at least once. Here is `updcrc''s annotated 1342source listing for a sample `gzip' run: 1343 1344 ulg updcrc(s, n) 1345 uch *s; 1346 unsigned n; 1347 2 ->{ 1348 register ulg c; 1349 1350 static ulg crc = (ulg)0xffffffffL; 1351 1352 2 -> if (s == NULL) { 1353 1 -> c = 0xffffffffL; 1354 1 -> } else { 1355 1 -> c = crc; 1356 1 -> if (n) do { 1357 26312 -> c = crc_32_tab[...]; 1358 26312,1,26311 -> } while (--n); 1359 } 1360 2 -> crc = c; 1361 2 -> return c ^ 0xffffffffL; 1362 2 ->} 1363 1364 In this example, the function was called twice, passing once through 1365each branch of the `if' statement. The body of the `do' loop was 1366executed a total of 26312 times. Note how the `while' statement is 1367annotated. It began execution 26312 times, once for each iteration 1368through the loop. One of those times (the last time) it exited, while 1369it branched back to the beginning of the loop 26311 times. 1370 1371 1372File: gprof.info, Node: Inaccuracy, Next: How do I?, Prev: Output, Up: Top 1373 13746 Inaccuracy of `gprof' Output 1375****************************** 1376 1377* Menu: 1378 1379* Sampling Error:: Statistical margins of error 1380* Assumptions:: Estimating children times 1381 1382 1383File: gprof.info, Node: Sampling Error, Next: Assumptions, Up: Inaccuracy 1384 13856.1 Statistical Sampling Error 1386============================== 1387 1388The run-time figures that `gprof' gives you are based on a sampling 1389process, so they are subject to statistical inaccuracy. If a function 1390runs only a small amount of time, so that on the average the sampling 1391process ought to catch that function in the act only once, there is a 1392pretty good chance it will actually find that function zero times, or 1393twice. 1394 1395 By contrast, the number-of-calls and basic-block figures are derived 1396by counting, not sampling. They are completely accurate and will not 1397vary from run to run if your program is deterministic and single 1398threaded. In multi-threaded applications, or single threaded 1399applications that link with multi-threaded libraries, the counts are 1400only deterministic if the counting function is thread-safe. (Note: 1401beware that the mcount counting function in glibc is _not_ 1402thread-safe). *Note Implementation of Profiling: Implementation. 1403 1404 The "sampling period" that is printed at the beginning of the flat 1405profile says how often samples are taken. The rule of thumb is that a 1406run-time figure is accurate if it is considerably bigger than the 1407sampling period. 1408 1409 The actual amount of error can be predicted. For N samples, the 1410_expected_ error is the square-root of N. For example, if the sampling 1411period is 0.01 seconds and `foo''s run-time is 1 second, N is 100 1412samples (1 second/0.01 seconds), sqrt(N) is 10 samples, so the expected 1413error in `foo''s run-time is 0.1 seconds (10*0.01 seconds), or ten 1414percent of the observed value. Again, if the sampling period is 0.01 1415seconds and `bar''s run-time is 100 seconds, N is 10000 samples, 1416sqrt(N) is 100 samples, so the expected error in `bar''s run-time is 1 1417second, or one percent of the observed value. It is likely to vary 1418this much _on the average_ from one profiling run to the next. 1419(_Sometimes_ it will vary more.) 1420 1421 This does not mean that a small run-time figure is devoid of 1422information. If the program's _total_ run-time is large, a small 1423run-time for one function does tell you that that function used an 1424insignificant fraction of the whole program's time. Usually this means 1425it is not worth optimizing. 1426 1427 One way to get more accuracy is to give your program more (but 1428similar) input data so it will take longer. Another way is to combine 1429the data from several runs, using the `-s' option of `gprof'. Here is 1430how: 1431 1432 1. Run your program once. 1433 1434 2. Issue the command `mv gmon.out gmon.sum'. 1435 1436 3. Run your program again, the same as before. 1437 1438 4. Merge the new data in `gmon.out' into `gmon.sum' with this command: 1439 1440 gprof -s EXECUTABLE-FILE gmon.out gmon.sum 1441 1442 5. Repeat the last two steps as often as you wish. 1443 1444 6. Analyze the cumulative data using this command: 1445 1446 gprof EXECUTABLE-FILE gmon.sum > OUTPUT-FILE 1447 1448 1449File: gprof.info, Node: Assumptions, Prev: Sampling Error, Up: Inaccuracy 1450 14516.2 Estimating `children' Times 1452=============================== 1453 1454Some of the figures in the call graph are estimates--for example, the 1455`children' time values and all the time figures in caller and 1456subroutine lines. 1457 1458 There is no direct information about these measurements in the 1459profile data itself. Instead, `gprof' estimates them by making an 1460assumption about your program that might or might not be true. 1461 1462 The assumption made is that the average time spent in each call to 1463any function `foo' is not correlated with who called `foo'. If `foo' 1464used 5 seconds in all, and 2/5 of the calls to `foo' came from `a', 1465then `foo' contributes 2 seconds to `a''s `children' time, by 1466assumption. 1467 1468 This assumption is usually true enough, but for some programs it is 1469far from true. Suppose that `foo' returns very quickly when its 1470argument is zero; suppose that `a' always passes zero as an argument, 1471while other callers of `foo' pass other arguments. In this program, 1472all the time spent in `foo' is in the calls from callers other than `a'. 1473But `gprof' has no way of knowing this; it will blindly and incorrectly 1474charge 2 seconds of time in `foo' to the children of `a'. 1475 1476 We hope some day to put more complete data into `gmon.out', so that 1477this assumption is no longer needed, if we can figure out how. For the 1478novice, the estimated figures are usually more useful than misleading. 1479 1480 1481File: gprof.info, Node: How do I?, Next: Incompatibilities, Prev: Inaccuracy, Up: Top 1482 14837 Answers to Common Questions 1484***************************** 1485 1486How can I get more exact information about hot spots in my program? 1487 Looking at the per-line call counts only tells part of the story. 1488 Because `gprof' can only report call times and counts by function, 1489 the best way to get finer-grained information on where the program 1490 is spending its time is to re-factor large functions into sequences 1491 of calls to smaller ones. Beware however that this can introduce 1492 artificial hot spots since compiling with `-pg' adds a significant 1493 overhead to function calls. An alternative solution is to use a 1494 non-intrusive profiler, e.g. oprofile. 1495 1496How do I find which lines in my program were executed the most times? 1497 Use the `gcov' program. 1498 1499How do I find which lines in my program called a particular function? 1500 Use `gprof -l' and lookup the function in the call graph. The 1501 callers will be broken down by function and line number. 1502 1503How do I analyze a program that runs for less than a second? 1504 Try using a shell script like this one: 1505 1506 for i in `seq 1 100`; do 1507 fastprog 1508 mv gmon.out gmon.out.$i 1509 done 1510 1511 gprof -s fastprog gmon.out.* 1512 1513 gprof fastprog gmon.sum 1514 1515 If your program is completely deterministic, all the call counts 1516 will be simple multiples of 100 (i.e., a function called once in 1517 each run will appear with a call count of 100). 1518 1519 1520 1521File: gprof.info, Node: Incompatibilities, Next: Details, Prev: How do I?, Up: Top 1522 15238 Incompatibilities with Unix `gprof' 1524************************************* 1525 1526GNU `gprof' and Berkeley Unix `gprof' use the same data file 1527`gmon.out', and provide essentially the same information. But there 1528are a few differences. 1529 1530 * GNU `gprof' uses a new, generalized file format with support for 1531 basic-block execution counts and non-realtime histograms. A magic 1532 cookie and version number allows `gprof' to easily identify new 1533 style files. Old BSD-style files can still be read. *Note 1534 Profiling Data File Format: File Format. 1535 1536 * For a recursive function, Unix `gprof' lists the function as a 1537 parent and as a child, with a `calls' field that lists the number 1538 of recursive calls. GNU `gprof' omits these lines and puts the 1539 number of recursive calls in the primary line. 1540 1541 * When a function is suppressed from the call graph with `-e', GNU 1542 `gprof' still lists it as a subroutine of functions that call it. 1543 1544 * GNU `gprof' accepts the `-k' with its argument in the form 1545 `from/to', instead of `from to'. 1546 1547 * In the annotated source listing, if there are multiple basic 1548 blocks on the same line, GNU `gprof' prints all of their counts, 1549 separated by commas. 1550 1551 * The blurbs, field widths, and output formats are different. GNU 1552 `gprof' prints blurbs after the tables, so that you can see the 1553 tables without skipping the blurbs. 1554 1555 1556File: gprof.info, Node: Details, Next: GNU Free Documentation License, Prev: Incompatibilities, Up: Top 1557 15589 Details of Profiling 1559********************** 1560 1561* Menu: 1562 1563* Implementation:: How a program collects profiling information 1564* File Format:: Format of `gmon.out' files 1565* Internals:: `gprof''s internal operation 1566* Debugging:: Using `gprof''s `-d' option 1567 1568 1569File: gprof.info, Node: Implementation, Next: File Format, Up: Details 1570 15719.1 Implementation of Profiling 1572=============================== 1573 1574Profiling works by changing how every function in your program is 1575compiled so that when it is called, it will stash away some information 1576about where it was called from. From this, the profiler can figure out 1577what function called it, and can count how many times it was called. 1578This change is made by the compiler when your program is compiled with 1579the `-pg' option, which causes every function to call `mcount' (or 1580`_mcount', or `__mcount', depending on the OS and compiler) as one of 1581its first operations. 1582 1583 The `mcount' routine, included in the profiling library, is 1584responsible for recording in an in-memory call graph table both its 1585parent routine (the child) and its parent's parent. This is typically 1586done by examining the stack frame to find both the address of the 1587child, and the return address in the original parent. Since this is a 1588very machine-dependent operation, `mcount' itself is typically a short 1589assembly-language stub routine that extracts the required information, 1590and then calls `__mcount_internal' (a normal C function) with two 1591arguments--`frompc' and `selfpc'. `__mcount_internal' is responsible 1592for maintaining the in-memory call graph, which records `frompc', 1593`selfpc', and the number of times each of these call arcs was traversed. 1594 1595 GCC Version 2 provides a magical function 1596(`__builtin_return_address'), which allows a generic `mcount' function 1597to extract the required information from the stack frame. However, on 1598some architectures, most notably the SPARC, using this builtin can be 1599very computationally expensive, and an assembly language version of 1600`mcount' is used for performance reasons. 1601 1602 Number-of-calls information for library routines is collected by 1603using a special version of the C library. The programs in it are the 1604same as in the usual C library, but they were compiled with `-pg'. If 1605you link your program with `gcc ... -pg', it automatically uses the 1606profiling version of the library. 1607 1608 Profiling also involves watching your program as it runs, and 1609keeping a histogram of where the program counter happens to be every 1610now and then. Typically the program counter is looked at around 100 1611times per second of run time, but the exact frequency may vary from 1612system to system. 1613 1614 This is done is one of two ways. Most UNIX-like operating systems 1615provide a `profil()' system call, which registers a memory array with 1616the kernel, along with a scale factor that determines how the program's 1617address space maps into the array. Typical scaling values cause every 16182 to 8 bytes of address space to map into a single array slot. On 1619every tick of the system clock (assuming the profiled program is 1620running), the value of the program counter is examined and the 1621corresponding slot in the memory array is incremented. Since this is 1622done in the kernel, which had to interrupt the process anyway to handle 1623the clock interrupt, very little additional system overhead is required. 1624 1625 However, some operating systems, most notably Linux 2.0 (and 1626earlier), do not provide a `profil()' system call. On such a system, 1627arrangements are made for the kernel to periodically deliver a signal 1628to the process (typically via `setitimer()'), which then performs the 1629same operation of examining the program counter and incrementing a slot 1630in the memory array. Since this method requires a signal to be 1631delivered to user space every time a sample is taken, it uses 1632considerably more overhead than kernel-based profiling. Also, due to 1633the added delay required to deliver the signal, this method is less 1634accurate as well. 1635 1636 A special startup routine allocates memory for the histogram and 1637either calls `profil()' or sets up a clock signal handler. This 1638routine (`monstartup') can be invoked in several ways. On Linux 1639systems, a special profiling startup file `gcrt0.o', which invokes 1640`monstartup' before `main', is used instead of the default `crt0.o'. 1641Use of this special startup file is one of the effects of using `gcc 1642... -pg' to link. On SPARC systems, no special startup files are used. 1643Rather, the `mcount' routine, when it is invoked for the first time 1644(typically when `main' is called), calls `monstartup'. 1645 1646 If the compiler's `-a' option was used, basic-block counting is also 1647enabled. Each object file is then compiled with a static array of 1648counts, initially zero. In the executable code, every time a new 1649basic-block begins (i.e., when an `if' statement appears), an extra 1650instruction is inserted to increment the corresponding count in the 1651array. At compile time, a paired array was constructed that recorded 1652the starting address of each basic-block. Taken together, the two 1653arrays record the starting address of every basic-block, along with the 1654number of times it was executed. 1655 1656 The profiling library also includes a function (`mcleanup') which is 1657typically registered using `atexit()' to be called as the program 1658exits, and is responsible for writing the file `gmon.out'. Profiling 1659is turned off, various headers are output, and the histogram is 1660written, followed by the call-graph arcs and the basic-block counts. 1661 1662 The output from `gprof' gives no indication of parts of your program 1663that are limited by I/O or swapping bandwidth. This is because samples 1664of the program counter are taken at fixed intervals of the program's 1665run time. Therefore, the time measurements in `gprof' output say 1666nothing about time that your program was not running. For example, a 1667part of the program that creates so much data that it cannot all fit in 1668physical memory at once may run very slowly due to thrashing, but 1669`gprof' will say it uses little time. On the other hand, sampling by 1670run time has the advantage that the amount of load due to other users 1671won't directly affect the output you get. 1672 1673 1674File: gprof.info, Node: File Format, Next: Internals, Prev: Implementation, Up: Details 1675 16769.2 Profiling Data File Format 1677============================== 1678 1679The old BSD-derived file format used for profile data does not contain a 1680magic cookie that allows to check whether a data file really is a 1681`gprof' file. Furthermore, it does not provide a version number, thus 1682rendering changes to the file format almost impossible. GNU `gprof' 1683uses a new file format that provides these features. For backward 1684compatibility, GNU `gprof' continues to support the old BSD-derived 1685format, but not all features are supported with it. For example, 1686basic-block execution counts cannot be accommodated by the old file 1687format. 1688 1689 The new file format is defined in header file `gmon_out.h'. It 1690consists of a header containing the magic cookie and a version number, 1691as well as some spare bytes available for future extensions. All data 1692in a profile data file is in the native format of the target for which 1693the profile was collected. GNU `gprof' adapts automatically to the 1694byte-order in use. 1695 1696 In the new file format, the header is followed by a sequence of 1697records. Currently, there are three different record types: histogram 1698records, call-graph arc records, and basic-block execution count 1699records. Each file can contain any number of each record type. When 1700reading a file, GNU `gprof' will ensure records of the same type are 1701compatible with each other and compute the union of all records. For 1702example, for basic-block execution counts, the union is simply the sum 1703of all execution counts for each basic-block. 1704 17059.2.1 Histogram Records 1706----------------------- 1707 1708Histogram records consist of a header that is followed by an array of 1709bins. The header contains the text-segment range that the histogram 1710spans, the size of the histogram in bytes (unlike in the old BSD 1711format, this does not include the size of the header), the rate of the 1712profiling clock, and the physical dimension that the bin counts 1713represent after being scaled by the profiling clock rate. The physical 1714dimension is specified in two parts: a long name of up to 15 characters 1715and a single character abbreviation. For example, a histogram 1716representing real-time would specify the long name as "seconds" and the 1717abbreviation as "s". This feature is useful for architectures that 1718support performance monitor hardware (which, fortunately, is becoming 1719increasingly common). For example, under DEC OSF/1, the "uprofile" 1720command can be used to produce a histogram of, say, instruction cache 1721misses. In this case, the dimension in the histogram header could be 1722set to "i-cache misses" and the abbreviation could be set to "1" 1723(because it is simply a count, not a physical dimension). Also, the 1724profiling rate would have to be set to 1 in this case. 1725 1726 Histogram bins are 16-bit numbers and each bin represent an equal 1727amount of text-space. For example, if the text-segment is one thousand 1728bytes long and if there are ten bins in the histogram, each bin 1729represents one hundred bytes. 1730 17319.2.2 Call-Graph Records 1732------------------------ 1733 1734Call-graph records have a format that is identical to the one used in 1735the BSD-derived file format. It consists of an arc in the call graph 1736and a count indicating the number of times the arc was traversed during 1737program execution. Arcs are specified by a pair of addresses: the 1738first must be within caller's function and the second must be within 1739the callee's function. When performing profiling at the function 1740level, these addresses can point anywhere within the respective 1741function. However, when profiling at the line-level, it is better if 1742the addresses are as close to the call-site/entry-point as possible. 1743This will ensure that the line-level call-graph is able to identify 1744exactly which line of source code performed calls to a function. 1745 17469.2.3 Basic-Block Execution Count Records 1747----------------------------------------- 1748 1749Basic-block execution count records consist of a header followed by a 1750sequence of address/count pairs. The header simply specifies the 1751length of the sequence. In an address/count pair, the address 1752identifies a basic-block and the count specifies the number of times 1753that basic-block was executed. Any address within the basic-address can 1754be used. 1755 1756 1757File: gprof.info, Node: Internals, Next: Debugging, Prev: File Format, Up: Details 1758 17599.3 `gprof''s Internal Operation 1760================================ 1761 1762Like most programs, `gprof' begins by processing its options. During 1763this stage, it may building its symspec list (`sym_ids.c:sym_id_add'), 1764if options are specified which use symspecs. `gprof' maintains a 1765single linked list of symspecs, which will eventually get turned into 176612 symbol tables, organized into six include/exclude pairs--one pair 1767each for the flat profile (INCL_FLAT/EXCL_FLAT), the call graph arcs 1768(INCL_ARCS/EXCL_ARCS), printing in the call graph 1769(INCL_GRAPH/EXCL_GRAPH), timing propagation in the call graph 1770(INCL_TIME/EXCL_TIME), the annotated source listing 1771(INCL_ANNO/EXCL_ANNO), and the execution count listing 1772(INCL_EXEC/EXCL_EXEC). 1773 1774 After option processing, `gprof' finishes building the symspec list 1775by adding all the symspecs in `default_excluded_list' to the exclude 1776lists EXCL_TIME and EXCL_GRAPH, and if line-by-line profiling is 1777specified, EXCL_FLAT as well. These default excludes are not added to 1778EXCL_ANNO, EXCL_ARCS, and EXCL_EXEC. 1779 1780 Next, the BFD library is called to open the object file, verify that 1781it is an object file, and read its symbol table (`core.c:core_init'), 1782using `bfd_canonicalize_symtab' after mallocing an appropriately sized 1783array of symbols. At this point, function mappings are read (if the 1784`--file-ordering' option has been specified), and the core text space 1785is read into memory (if the `-c' option was given). 1786 1787 `gprof''s own symbol table, an array of Sym structures, is now built. 1788This is done in one of two ways, by one of two routines, depending on 1789whether line-by-line profiling (`-l' option) has been enabled. For 1790normal profiling, the BFD canonical symbol table is scanned. For 1791line-by-line profiling, every text space address is examined, and a new 1792symbol table entry gets created every time the line number changes. In 1793either case, two passes are made through the symbol table--one to count 1794the size of the symbol table required, and the other to actually read 1795the symbols. In between the two passes, a single array of type `Sym' 1796is created of the appropriate length. Finally, 1797`symtab.c:symtab_finalize' is called to sort the symbol table and 1798remove duplicate entries (entries with the same memory address). 1799 1800 The symbol table must be a contiguous array for two reasons. First, 1801the `qsort' library function (which sorts an array) will be used to 1802sort the symbol table. Also, the symbol lookup routine 1803(`symtab.c:sym_lookup'), which finds symbols based on memory address, 1804uses a binary search algorithm which requires the symbol table to be a 1805sorted array. Function symbols are indicated with an `is_func' flag. 1806Line number symbols have no special flags set. Additionally, a symbol 1807can have an `is_static' flag to indicate that it is a local symbol. 1808 1809 With the symbol table read, the symspecs can now be translated into 1810Syms (`sym_ids.c:sym_id_parse'). Remember that a single symspec can 1811match multiple symbols. An array of symbol tables (`syms') is created, 1812each entry of which is a symbol table of Syms to be included or 1813excluded from a particular listing. The master symbol table and the 1814symspecs are examined by nested loops, and every symbol that matches a 1815symspec is inserted into the appropriate syms table. This is done 1816twice, once to count the size of each required symbol table, and again 1817to build the tables, which have been malloced between passes. From now 1818on, to determine whether a symbol is on an include or exclude symspec 1819list, `gprof' simply uses its standard symbol lookup routine on the 1820appropriate table in the `syms' array. 1821 1822 Now the profile data file(s) themselves are read 1823(`gmon_io.c:gmon_out_read'), first by checking for a new-style 1824`gmon.out' header, then assuming this is an old-style BSD `gmon.out' if 1825the magic number test failed. 1826 1827 New-style histogram records are read by `hist.c:hist_read_rec'. For 1828the first histogram record, allocate a memory array to hold all the 1829bins, and read them in. When multiple profile data files (or files 1830with multiple histogram records) are read, the memory ranges of each 1831pair of histogram records must be either equal, or non-overlapping. 1832For each pair of histogram records, the resolution (memory region size 1833divided by the number of bins) must be the same. The time unit must be 1834the same for all histogram records. If the above containts are met, all 1835histograms for the same memory range are merged. 1836 1837 As each call graph record is read (`call_graph.c:cg_read_rec'), the 1838parent and child addresses are matched to symbol table entries, and a 1839call graph arc is created by `cg_arcs.c:arc_add', unless the arc fails 1840a symspec check against INCL_ARCS/EXCL_ARCS. As each arc is added, a 1841linked list is maintained of the parent's child arcs, and of the child's 1842parent arcs. Both the child's call count and the arc's call count are 1843incremented by the record's call count. 1844 1845 Basic-block records are read (`basic_blocks.c:bb_read_rec'), but 1846only if line-by-line profiling has been selected. Each basic-block 1847address is matched to a corresponding line symbol in the symbol table, 1848and an entry made in the symbol's bb_addr and bb_calls arrays. Again, 1849if multiple basic-block records are present for the same address, the 1850call counts are cumulative. 1851 1852 A gmon.sum file is dumped, if requested (`gmon_io.c:gmon_out_write'). 1853 1854 If histograms were present in the data files, assign them to symbols 1855(`hist.c:hist_assign_samples') by iterating over all the sample bins 1856and assigning them to symbols. Since the symbol table is sorted in 1857order of ascending memory addresses, we can simple follow along in the 1858symbol table as we make our pass over the sample bins. This step 1859includes a symspec check against INCL_FLAT/EXCL_FLAT. Depending on the 1860histogram scale factor, a sample bin may span multiple symbols, in 1861which case a fraction of the sample count is allocated to each symbol, 1862proportional to the degree of overlap. This effect is rare for normal 1863profiling, but overlaps are more common during line-by-line profiling, 1864and can cause each of two adjacent lines to be credited with half a 1865hit, for example. 1866 1867 If call graph data is present, `cg_arcs.c:cg_assemble' is called. 1868First, if `-c' was specified, a machine-dependent routine (`find_call') 1869scans through each symbol's machine code, looking for subroutine call 1870instructions, and adding them to the call graph with a zero call count. 1871A topological sort is performed by depth-first numbering all the 1872symbols (`cg_dfn.c:cg_dfn'), so that children are always numbered less 1873than their parents, then making a array of pointers into the symbol 1874table and sorting it into numerical order, which is reverse topological 1875order (children appear before parents). Cycles are also detected at 1876this point, all members of which are assigned the same topological 1877number. Two passes are now made through this sorted array of symbol 1878pointers. The first pass, from end to beginning (parents to children), 1879computes the fraction of child time to propagate to each parent and a 1880print flag. The print flag reflects symspec handling of 1881INCL_GRAPH/EXCL_GRAPH, with a parent's include or exclude (print or no 1882print) property being propagated to its children, unless they 1883themselves explicitly appear in INCL_GRAPH or EXCL_GRAPH. A second 1884pass, from beginning to end (children to parents) actually propagates 1885the timings along the call graph, subject to a check against 1886INCL_TIME/EXCL_TIME. With the print flag, fractions, and timings now 1887stored in the symbol structures, the topological sort array is now 1888discarded, and a new array of pointers is assembled, this time sorted 1889by propagated time. 1890 1891 Finally, print the various outputs the user requested, which is now 1892fairly straightforward. The call graph (`cg_print.c:cg_print') and 1893flat profile (`hist.c:hist_print') are regurgitations of values already 1894computed. The annotated source listing 1895(`basic_blocks.c:print_annotated_source') uses basic-block information, 1896if present, to label each line of code with call counts, otherwise only 1897the function call counts are presented. 1898 1899 The function ordering code is marginally well documented in the 1900source code itself (`cg_print.c'). Basically, the functions with the 1901most use and the most parents are placed first, followed by other 1902functions with the most use, followed by lower use functions, followed 1903by unused functions at the end. 1904 1905 1906File: gprof.info, Node: Debugging, Prev: Internals, Up: Details 1907 19089.4 Debugging `gprof' 1909===================== 1910 1911If `gprof' was compiled with debugging enabled, the `-d' option 1912triggers debugging output (to stdout) which can be helpful in 1913understanding its operation. The debugging number specified is 1914interpreted as a sum of the following options: 1915 19162 - Topological sort 1917 Monitor depth-first numbering of symbols during call graph analysis 1918 19194 - Cycles 1920 Shows symbols as they are identified as cycle heads 1921 192216 - Tallying 1923 As the call graph arcs are read, show each arc and how the total 1924 calls to each function are tallied 1925 192632 - Call graph arc sorting 1927 Details sorting individual parents/children within each call graph 1928 entry 1929 193064 - Reading histogram and call graph records 1931 Shows address ranges of histograms as they are read, and each call 1932 graph arc 1933 1934128 - Symbol table 1935 Reading, classifying, and sorting the symbol table from the object 1936 file. For line-by-line profiling (`-l' option), also shows line 1937 numbers being assigned to memory addresses. 1938 1939256 - Static call graph 1940 Trace operation of `-c' option 1941 1942512 - Symbol table and arc table lookups 1943 Detail operation of lookup routines 1944 19451024 - Call graph propagation 1946 Shows how function times are propagated along the call graph 1947 19482048 - Basic-blocks 1949 Shows basic-block records as they are read from profile data (only 1950 meaningful with `-l' option) 1951 19524096 - Symspecs 1953 Shows symspec-to-symbol pattern matching operation 1954 19558192 - Annotate source 1956 Tracks operation of `-A' option 1957 1958 1959File: gprof.info, Node: GNU Free Documentation License, Prev: Details, Up: Top 1960 1961Appendix A GNU Free Documentation License 1962***************************************** 1963 1964 Version 1.3, 3 November 2008 1965 1966 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. 1967 `http://fsf.org/' 1968 1969 Everyone is permitted to copy and distribute verbatim copies 1970 of this license document, but changing it is not allowed. 1971 1972 0. PREAMBLE 1973 1974 The purpose of this License is to make a manual, textbook, or other 1975 functional and useful document "free" in the sense of freedom: to 1976 assure everyone the effective freedom to copy and redistribute it, 1977 with or without modifying it, either commercially or 1978 noncommercially. Secondarily, this License preserves for the 1979 author and publisher a way to get credit for their work, while not 1980 being considered responsible for modifications made by others. 1981 1982 This License is a kind of "copyleft", which means that derivative 1983 works of the document must themselves be free in the same sense. 1984 It complements the GNU General Public License, which is a copyleft 1985 license designed for free software. 1986 1987 We have designed this License in order to use it for manuals for 1988 free software, because free software needs free documentation: a 1989 free program should come with manuals providing the same freedoms 1990 that the software does. But this License is not limited to 1991 software manuals; it can be used for any textual work, regardless 1992 of subject matter or whether it is published as a printed book. 1993 We recommend this License principally for works whose purpose is 1994 instruction or reference. 1995 1996 1. APPLICABILITY AND DEFINITIONS 1997 1998 This License applies to any manual or other work, in any medium, 1999 that contains a notice placed by the copyright holder saying it 2000 can be distributed under the terms of this License. Such a notice 2001 grants a world-wide, royalty-free license, unlimited in duration, 2002 to use that work under the conditions stated herein. The 2003 "Document", below, refers to any such manual or work. Any member 2004 of the public is a licensee, and is addressed as "you". You 2005 accept the license if you copy, modify or distribute the work in a 2006 way requiring permission under copyright law. 2007 2008 A "Modified Version" of the Document means any work containing the 2009 Document or a portion of it, either copied verbatim, or with 2010 modifications and/or translated into another language. 2011 2012 A "Secondary Section" is a named appendix or a front-matter section 2013 of the Document that deals exclusively with the relationship of the 2014 publishers or authors of the Document to the Document's overall 2015 subject (or to related matters) and contains nothing that could 2016 fall directly within that overall subject. (Thus, if the Document 2017 is in part a textbook of mathematics, a Secondary Section may not 2018 explain any mathematics.) The relationship could be a matter of 2019 historical connection with the subject or with related matters, or 2020 of legal, commercial, philosophical, ethical or political position 2021 regarding them. 2022 2023 The "Invariant Sections" are certain Secondary Sections whose 2024 titles are designated, as being those of Invariant Sections, in 2025 the notice that says that the Document is released under this 2026 License. If a section does not fit the above definition of 2027 Secondary then it is not allowed to be designated as Invariant. 2028 The Document may contain zero Invariant Sections. If the Document 2029 does not identify any Invariant Sections then there are none. 2030 2031 The "Cover Texts" are certain short passages of text that are 2032 listed, as Front-Cover Texts or Back-Cover Texts, in the notice 2033 that says that the Document is released under this License. A 2034 Front-Cover Text may be at most 5 words, and a Back-Cover Text may 2035 be at most 25 words. 2036 2037 A "Transparent" copy of the Document means a machine-readable copy, 2038 represented in a format whose specification is available to the 2039 general public, that is suitable for revising the document 2040 straightforwardly with generic text editors or (for images 2041 composed of pixels) generic paint programs or (for drawings) some 2042 widely available drawing editor, and that is suitable for input to 2043 text formatters or for automatic translation to a variety of 2044 formats suitable for input to text formatters. A copy made in an 2045 otherwise Transparent file format whose markup, or absence of 2046 markup, has been arranged to thwart or discourage subsequent 2047 modification by readers is not Transparent. An image format is 2048 not Transparent if used for any substantial amount of text. A 2049 copy that is not "Transparent" is called "Opaque". 2050 2051 Examples of suitable formats for Transparent copies include plain 2052 ASCII without markup, Texinfo input format, LaTeX input format, 2053 SGML or XML using a publicly available DTD, and 2054 standard-conforming simple HTML, PostScript or PDF designed for 2055 human modification. Examples of transparent image formats include 2056 PNG, XCF and JPG. Opaque formats include proprietary formats that 2057 can be read and edited only by proprietary word processors, SGML or 2058 XML for which the DTD and/or processing tools are not generally 2059 available, and the machine-generated HTML, PostScript or PDF 2060 produced by some word processors for output purposes only. 2061 2062 The "Title Page" means, for a printed book, the title page itself, 2063 plus such following pages as are needed to hold, legibly, the 2064 material this License requires to appear in the title page. For 2065 works in formats which do not have any title page as such, "Title 2066 Page" means the text near the most prominent appearance of the 2067 work's title, preceding the beginning of the body of the text. 2068 2069 The "publisher" means any person or entity that distributes copies 2070 of the Document to the public. 2071 2072 A section "Entitled XYZ" means a named subunit of the Document 2073 whose title either is precisely XYZ or contains XYZ in parentheses 2074 following text that translates XYZ in another language. (Here XYZ 2075 stands for a specific section name mentioned below, such as 2076 "Acknowledgements", "Dedications", "Endorsements", or "History".) 2077 To "Preserve the Title" of such a section when you modify the 2078 Document means that it remains a section "Entitled XYZ" according 2079 to this definition. 2080 2081 The Document may include Warranty Disclaimers next to the notice 2082 which states that this License applies to the Document. These 2083 Warranty Disclaimers are considered to be included by reference in 2084 this License, but only as regards disclaiming warranties: any other 2085 implication that these Warranty Disclaimers may have is void and 2086 has no effect on the meaning of this License. 2087 2088 2. VERBATIM COPYING 2089 2090 You may copy and distribute the Document in any medium, either 2091 commercially or noncommercially, provided that this License, the 2092 copyright notices, and the license notice saying this License 2093 applies to the Document are reproduced in all copies, and that you 2094 add no other conditions whatsoever to those of this License. You 2095 may not use technical measures to obstruct or control the reading 2096 or further copying of the copies you make or distribute. However, 2097 you may accept compensation in exchange for copies. If you 2098 distribute a large enough number of copies you must also follow 2099 the conditions in section 3. 2100 2101 You may also lend copies, under the same conditions stated above, 2102 and you may publicly display copies. 2103 2104 3. COPYING IN QUANTITY 2105 2106 If you publish printed copies (or copies in media that commonly 2107 have printed covers) of the Document, numbering more than 100, and 2108 the Document's license notice requires Cover Texts, you must 2109 enclose the copies in covers that carry, clearly and legibly, all 2110 these Cover Texts: Front-Cover Texts on the front cover, and 2111 Back-Cover Texts on the back cover. Both covers must also clearly 2112 and legibly identify you as the publisher of these copies. The 2113 front cover must present the full title with all words of the 2114 title equally prominent and visible. You may add other material 2115 on the covers in addition. Copying with changes limited to the 2116 covers, as long as they preserve the title of the Document and 2117 satisfy these conditions, can be treated as verbatim copying in 2118 other respects. 2119 2120 If the required texts for either cover are too voluminous to fit 2121 legibly, you should put the first ones listed (as many as fit 2122 reasonably) on the actual cover, and continue the rest onto 2123 adjacent pages. 2124 2125 If you publish or distribute Opaque copies of the Document 2126 numbering more than 100, you must either include a 2127 machine-readable Transparent copy along with each Opaque copy, or 2128 state in or with each Opaque copy a computer-network location from 2129 which the general network-using public has access to download 2130 using public-standard network protocols a complete Transparent 2131 copy of the Document, free of added material. If you use the 2132 latter option, you must take reasonably prudent steps, when you 2133 begin distribution of Opaque copies in quantity, to ensure that 2134 this Transparent copy will remain thus accessible at the stated 2135 location until at least one year after the last time you 2136 distribute an Opaque copy (directly or through your agents or 2137 retailers) of that edition to the public. 2138 2139 It is requested, but not required, that you contact the authors of 2140 the Document well before redistributing any large number of 2141 copies, to give them a chance to provide you with an updated 2142 version of the Document. 2143 2144 4. MODIFICATIONS 2145 2146 You may copy and distribute a Modified Version of the Document 2147 under the conditions of sections 2 and 3 above, provided that you 2148 release the Modified Version under precisely this License, with 2149 the Modified Version filling the role of the Document, thus 2150 licensing distribution and modification of the Modified Version to 2151 whoever possesses a copy of it. In addition, you must do these 2152 things in the Modified Version: 2153 2154 A. Use in the Title Page (and on the covers, if any) a title 2155 distinct from that of the Document, and from those of 2156 previous versions (which should, if there were any, be listed 2157 in the History section of the Document). You may use the 2158 same title as a previous version if the original publisher of 2159 that version gives permission. 2160 2161 B. List on the Title Page, as authors, one or more persons or 2162 entities responsible for authorship of the modifications in 2163 the Modified Version, together with at least five of the 2164 principal authors of the Document (all of its principal 2165 authors, if it has fewer than five), unless they release you 2166 from this requirement. 2167 2168 C. State on the Title page the name of the publisher of the 2169 Modified Version, as the publisher. 2170 2171 D. Preserve all the copyright notices of the Document. 2172 2173 E. Add an appropriate copyright notice for your modifications 2174 adjacent to the other copyright notices. 2175 2176 F. Include, immediately after the copyright notices, a license 2177 notice giving the public permission to use the Modified 2178 Version under the terms of this License, in the form shown in 2179 the Addendum below. 2180 2181 G. Preserve in that license notice the full lists of Invariant 2182 Sections and required Cover Texts given in the Document's 2183 license notice. 2184 2185 H. Include an unaltered copy of this License. 2186 2187 I. Preserve the section Entitled "History", Preserve its Title, 2188 and add to it an item stating at least the title, year, new 2189 authors, and publisher of the Modified Version as given on 2190 the Title Page. If there is no section Entitled "History" in 2191 the Document, create one stating the title, year, authors, 2192 and publisher of the Document as given on its Title Page, 2193 then add an item describing the Modified Version as stated in 2194 the previous sentence. 2195 2196 J. Preserve the network location, if any, given in the Document 2197 for public access to a Transparent copy of the Document, and 2198 likewise the network locations given in the Document for 2199 previous versions it was based on. These may be placed in 2200 the "History" section. You may omit a network location for a 2201 work that was published at least four years before the 2202 Document itself, or if the original publisher of the version 2203 it refers to gives permission. 2204 2205 K. For any section Entitled "Acknowledgements" or "Dedications", 2206 Preserve the Title of the section, and preserve in the 2207 section all the substance and tone of each of the contributor 2208 acknowledgements and/or dedications given therein. 2209 2210 L. Preserve all the Invariant Sections of the Document, 2211 unaltered in their text and in their titles. Section numbers 2212 or the equivalent are not considered part of the section 2213 titles. 2214 2215 M. Delete any section Entitled "Endorsements". Such a section 2216 may not be included in the Modified Version. 2217 2218 N. Do not retitle any existing section to be Entitled 2219 "Endorsements" or to conflict in title with any Invariant 2220 Section. 2221 2222 O. Preserve any Warranty Disclaimers. 2223 2224 If the Modified Version includes new front-matter sections or 2225 appendices that qualify as Secondary Sections and contain no 2226 material copied from the Document, you may at your option 2227 designate some or all of these sections as invariant. To do this, 2228 add their titles to the list of Invariant Sections in the Modified 2229 Version's license notice. These titles must be distinct from any 2230 other section titles. 2231 2232 You may add a section Entitled "Endorsements", provided it contains 2233 nothing but endorsements of your Modified Version by various 2234 parties--for example, statements of peer review or that the text 2235 has been approved by an organization as the authoritative 2236 definition of a standard. 2237 2238 You may add a passage of up to five words as a Front-Cover Text, 2239 and a passage of up to 25 words as a Back-Cover Text, to the end 2240 of the list of Cover Texts in the Modified Version. Only one 2241 passage of Front-Cover Text and one of Back-Cover Text may be 2242 added by (or through arrangements made by) any one entity. If the 2243 Document already includes a cover text for the same cover, 2244 previously added by you or by arrangement made by the same entity 2245 you are acting on behalf of, you may not add another; but you may 2246 replace the old one, on explicit permission from the previous 2247 publisher that added the old one. 2248 2249 The author(s) and publisher(s) of the Document do not by this 2250 License give permission to use their names for publicity for or to 2251 assert or imply endorsement of any Modified Version. 2252 2253 5. COMBINING DOCUMENTS 2254 2255 You may combine the Document with other documents released under 2256 this License, under the terms defined in section 4 above for 2257 modified versions, provided that you include in the combination 2258 all of the Invariant Sections of all of the original documents, 2259 unmodified, and list them all as Invariant Sections of your 2260 combined work in its license notice, and that you preserve all 2261 their Warranty Disclaimers. 2262 2263 The combined work need only contain one copy of this License, and 2264 multiple identical Invariant Sections may be replaced with a single 2265 copy. If there are multiple Invariant Sections with the same name 2266 but different contents, make the title of each such section unique 2267 by adding at the end of it, in parentheses, the name of the 2268 original author or publisher of that section if known, or else a 2269 unique number. Make the same adjustment to the section titles in 2270 the list of Invariant Sections in the license notice of the 2271 combined work. 2272 2273 In the combination, you must combine any sections Entitled 2274 "History" in the various original documents, forming one section 2275 Entitled "History"; likewise combine any sections Entitled 2276 "Acknowledgements", and any sections Entitled "Dedications". You 2277 must delete all sections Entitled "Endorsements." 2278 2279 6. COLLECTIONS OF DOCUMENTS 2280 2281 You may make a collection consisting of the Document and other 2282 documents released under this License, and replace the individual 2283 copies of this License in the various documents with a single copy 2284 that is included in the collection, provided that you follow the 2285 rules of this License for verbatim copying of each of the 2286 documents in all other respects. 2287 2288 You may extract a single document from such a collection, and 2289 distribute it individually under this License, provided you insert 2290 a copy of this License into the extracted document, and follow 2291 this License in all other respects regarding verbatim copying of 2292 that document. 2293 2294 7. AGGREGATION WITH INDEPENDENT WORKS 2295 2296 A compilation of the Document or its derivatives with other 2297 separate and independent documents or works, in or on a volume of 2298 a storage or distribution medium, is called an "aggregate" if the 2299 copyright resulting from the compilation is not used to limit the 2300 legal rights of the compilation's users beyond what the individual 2301 works permit. When the Document is included in an aggregate, this 2302 License does not apply to the other works in the aggregate which 2303 are not themselves derivative works of the Document. 2304 2305 If the Cover Text requirement of section 3 is applicable to these 2306 copies of the Document, then if the Document is less than one half 2307 of the entire aggregate, the Document's Cover Texts may be placed 2308 on covers that bracket the Document within the aggregate, or the 2309 electronic equivalent of covers if the Document is in electronic 2310 form. Otherwise they must appear on printed covers that bracket 2311 the whole aggregate. 2312 2313 8. TRANSLATION 2314 2315 Translation is considered a kind of modification, so you may 2316 distribute translations of the Document under the terms of section 2317 4. Replacing Invariant Sections with translations requires special 2318 permission from their copyright holders, but you may include 2319 translations of some or all Invariant Sections in addition to the 2320 original versions of these Invariant Sections. You may include a 2321 translation of this License, and all the license notices in the 2322 Document, and any Warranty Disclaimers, provided that you also 2323 include the original English version of this License and the 2324 original versions of those notices and disclaimers. In case of a 2325 disagreement between the translation and the original version of 2326 this License or a notice or disclaimer, the original version will 2327 prevail. 2328 2329 If a section in the Document is Entitled "Acknowledgements", 2330 "Dedications", or "History", the requirement (section 4) to 2331 Preserve its Title (section 1) will typically require changing the 2332 actual title. 2333 2334 9. TERMINATION 2335 2336 You may not copy, modify, sublicense, or distribute the Document 2337 except as expressly provided under this License. Any attempt 2338 otherwise to copy, modify, sublicense, or distribute it is void, 2339 and will automatically terminate your rights under this License. 2340 2341 However, if you cease all violation of this License, then your 2342 license from a particular copyright holder is reinstated (a) 2343 provisionally, unless and until the copyright holder explicitly 2344 and finally terminates your license, and (b) permanently, if the 2345 copyright holder fails to notify you of the violation by some 2346 reasonable means prior to 60 days after the cessation. 2347 2348 Moreover, your license from a particular copyright holder is 2349 reinstated permanently if the copyright holder notifies you of the 2350 violation by some reasonable means, this is the first time you have 2351 received notice of violation of this License (for any work) from 2352 that copyright holder, and you cure the violation prior to 30 days 2353 after your receipt of the notice. 2354 2355 Termination of your rights under this section does not terminate 2356 the licenses of parties who have received copies or rights from 2357 you under this License. If your rights have been terminated and 2358 not permanently reinstated, receipt of a copy of some or all of 2359 the same material does not give you any rights to use it. 2360 2361 10. FUTURE REVISIONS OF THIS LICENSE 2362 2363 The Free Software Foundation may publish new, revised versions of 2364 the GNU Free Documentation License from time to time. Such new 2365 versions will be similar in spirit to the present version, but may 2366 differ in detail to address new problems or concerns. See 2367 `http://www.gnu.org/copyleft/'. 2368 2369 Each version of the License is given a distinguishing version 2370 number. If the Document specifies that a particular numbered 2371 version of this License "or any later version" applies to it, you 2372 have the option of following the terms and conditions either of 2373 that specified version or of any later version that has been 2374 published (not as a draft) by the Free Software Foundation. If 2375 the Document does not specify a version number of this License, 2376 you may choose any version ever published (not as a draft) by the 2377 Free Software Foundation. If the Document specifies that a proxy 2378 can decide which future versions of this License can be used, that 2379 proxy's public statement of acceptance of a version permanently 2380 authorizes you to choose that version for the Document. 2381 2382 11. RELICENSING 2383 2384 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any 2385 World Wide Web server that publishes copyrightable works and also 2386 provides prominent facilities for anybody to edit those works. A 2387 public wiki that anybody can edit is an example of such a server. 2388 A "Massive Multiauthor Collaboration" (or "MMC") contained in the 2389 site means any set of copyrightable works thus published on the MMC 2390 site. 2391 2392 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 2393 license published by Creative Commons Corporation, a not-for-profit 2394 corporation with a principal place of business in San Francisco, 2395 California, as well as future copyleft versions of that license 2396 published by that same organization. 2397 2398 "Incorporate" means to publish or republish a Document, in whole or 2399 in part, as part of another Document. 2400 2401 An MMC is "eligible for relicensing" if it is licensed under this 2402 License, and if all works that were first published under this 2403 License somewhere other than this MMC, and subsequently 2404 incorporated in whole or in part into the MMC, (1) had no cover 2405 texts or invariant sections, and (2) were thus incorporated prior 2406 to November 1, 2008. 2407 2408 The operator of an MMC Site may republish an MMC contained in the 2409 site under CC-BY-SA on the same site at any time before August 1, 2410 2009, provided the MMC is eligible for relicensing. 2411 2412 2413ADDENDUM: How to use this License for your documents 2414==================================================== 2415 2416To use this License in a document you have written, include a copy of 2417the License in the document and put the following copyright and license 2418notices just after the title page: 2419 2420 Copyright (C) YEAR YOUR NAME. 2421 Permission is granted to copy, distribute and/or modify this document 2422 under the terms of the GNU Free Documentation License, Version 1.3 2423 or any later version published by the Free Software Foundation; 2424 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover 2425 Texts. A copy of the license is included in the section entitled ``GNU 2426 Free Documentation License''. 2427 2428 If you have Invariant Sections, Front-Cover Texts and Back-Cover 2429Texts, replace the "with...Texts." line with this: 2430 2431 with the Invariant Sections being LIST THEIR TITLES, with 2432 the Front-Cover Texts being LIST, and with the Back-Cover Texts 2433 being LIST. 2434 2435 If you have Invariant Sections without Cover Texts, or some other 2436combination of the three, merge those two alternatives to suit the 2437situation. 2438 2439 If your document contains nontrivial examples of program code, we 2440recommend releasing these examples in parallel under your choice of 2441free software license, such as the GNU General Public License, to 2442permit their use in free software. 2443 2444 2445 2446Tag Table: 2447Node: Top722 2448Node: Introduction2045 2449Node: Compiling4537 2450Node: Executing8593 2451Node: Invoking11381 2452Node: Output Options12796 2453Node: Analysis Options19885 2454Node: Miscellaneous Options23803 2455Node: Deprecated Options25058 2456Node: Symspecs27127 2457Node: Output28953 2458Node: Flat Profile29993 2459Node: Call Graph34946 2460Node: Primary38178 2461Node: Callers40766 2462Node: Subroutines42883 2463Node: Cycles44724 2464Node: Line-by-line51501 2465Node: Annotated Source55574 2466Node: Inaccuracy58573 2467Node: Sampling Error58831 2468Node: Assumptions61735 2469Node: How do I?63205 2470Node: Incompatibilities64759 2471Node: Details66253 2472Node: Implementation66646 2473Node: File Format72543 2474Node: Internals76833 2475Node: Debugging85328 2476Node: GNU Free Documentation License86929 2477 2478End Tag Table 2479