| 1 | \input texinfo @c -*-texinfo-*-
|
|---|
| 2 | @setfilename gprof.info
|
|---|
| 3 | @c Copyright 1988, 1992, 1993, 1998, 1999, 2000, 2001
|
|---|
| 4 | @c Free Software Foundation, Inc.
|
|---|
| 5 | @settitle GNU gprof
|
|---|
| 6 | @setchapternewpage odd
|
|---|
| 7 |
|
|---|
| 8 | @ifinfo
|
|---|
| 9 | @c This is a dir.info fragment to support semi-automated addition of
|
|---|
| 10 | @c manuals to an info tree. [email protected] is developing this facility.
|
|---|
| 11 | @format
|
|---|
| 12 | START-INFO-DIR-ENTRY
|
|---|
| 13 | * gprof: (gprof). Profiling your program's execution
|
|---|
| 14 | END-INFO-DIR-ENTRY
|
|---|
| 15 | @end format
|
|---|
| 16 | @end ifinfo
|
|---|
| 17 |
|
|---|
| 18 | @ifinfo
|
|---|
| 19 | This file documents the gprof profiler of the GNU system.
|
|---|
| 20 |
|
|---|
| 21 | @c man begin COPYRIGHT
|
|---|
| 22 | Copyright (C) 1988, 92, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 23 |
|
|---|
| 24 | Permission is granted to copy, distribute and/or modify this document
|
|---|
| 25 | under the terms of the GNU Free Documentation License, Version 1.1
|
|---|
| 26 | or any later version published by the Free Software Foundation;
|
|---|
| 27 | with no Invariant Sections, with no Front-Cover Texts, and with no
|
|---|
| 28 | Back-Cover Texts. A copy of the license is included in the
|
|---|
| 29 | section entitled "GNU Free Documentation License".
|
|---|
| 30 |
|
|---|
| 31 | @c man end
|
|---|
| 32 |
|
|---|
| 33 | @ignore
|
|---|
| 34 | Permission is granted to process this file through Tex and print the
|
|---|
| 35 | results, provided the printed document carries copying permission
|
|---|
| 36 | notice identical to this one except for the removal of this paragraph
|
|---|
| 37 | (this paragraph not being relevant to the printed manual).
|
|---|
| 38 |
|
|---|
| 39 | @end ignore
|
|---|
| 40 | @end ifinfo
|
|---|
| 41 |
|
|---|
| 42 | @finalout
|
|---|
| 43 | @smallbook
|
|---|
| 44 |
|
|---|
| 45 | @titlepage
|
|---|
| 46 | @title GNU gprof
|
|---|
| 47 | @subtitle The @sc{gnu} Profiler
|
|---|
| 48 | @author Jay Fenlason and Richard Stallman
|
|---|
| 49 |
|
|---|
| 50 | @page
|
|---|
| 51 |
|
|---|
| 52 | This manual describes the @sc{gnu} profiler, @code{gprof}, and how you
|
|---|
| 53 | can use it to determine which parts of a program are taking most of the
|
|---|
| 54 | execution time. We assume that you know how to write, compile, and
|
|---|
| 55 | execute programs. @sc{gnu} @code{gprof} was written by Jay Fenlason.
|
|---|
| 56 |
|
|---|
| 57 | @vskip 0pt plus 1filll
|
|---|
| 58 | Copyright @copyright{} 1988, 92, 97, 98, 99, 2000 Free Software Foundation, Inc.
|
|---|
| 59 |
|
|---|
| 60 | Permission is granted to copy, distribute and/or modify this document
|
|---|
| 61 | under the terms of the GNU Free Documentation License, Version 1.1
|
|---|
| 62 | or any later version published by the Free Software Foundation;
|
|---|
| 63 | with no Invariant Sections, with no Front-Cover Texts, and with no
|
|---|
| 64 | Back-Cover Texts. A copy of the license is included in the
|
|---|
| 65 | section entitled "GNU Free Documentation License".
|
|---|
| 66 |
|
|---|
| 67 | @end titlepage
|
|---|
| 68 |
|
|---|
| 69 | @ifnottex
|
|---|
| 70 | @node Top
|
|---|
| 71 | @top Profiling a Program: Where Does It Spend Its Time?
|
|---|
| 72 |
|
|---|
| 73 | This manual describes the @sc{gnu} profiler, @code{gprof}, and how you
|
|---|
| 74 | can use it to determine which parts of a program are taking most of the
|
|---|
| 75 | execution time. We assume that you know how to write, compile, and
|
|---|
| 76 | execute programs. @sc{gnu} @code{gprof} was written by Jay Fenlason.
|
|---|
| 77 |
|
|---|
| 78 | This document is distributed under the terms of the GNU Free
|
|---|
| 79 | Documentation License. A copy of the license is included in the
|
|---|
| 80 | section entitled "GNU Free Documentation License".
|
|---|
| 81 |
|
|---|
| 82 | @menu
|
|---|
| 83 | * Introduction:: What profiling means, and why it is useful.
|
|---|
| 84 |
|
|---|
| 85 | * Compiling:: How to compile your program for profiling.
|
|---|
| 86 | * Executing:: Executing your program to generate profile data
|
|---|
| 87 | * Invoking:: How to run @code{gprof}, and its options
|
|---|
| 88 |
|
|---|
| 89 | * Output:: Interpreting @code{gprof}'s output
|
|---|
| 90 |
|
|---|
| 91 | * Inaccuracy:: Potential problems you should be aware of
|
|---|
| 92 | * How do I?:: Answers to common questions
|
|---|
| 93 | * Incompatibilities:: (between @sc{gnu} @code{gprof} and Unix @code{gprof}.)
|
|---|
| 94 | * Details:: Details of how profiling is done
|
|---|
| 95 | * GNU Free Documentation License:: GNU Free Documentation License
|
|---|
| 96 | @end menu
|
|---|
| 97 | @end ifnottex
|
|---|
| 98 |
|
|---|
| 99 | @node Introduction
|
|---|
| 100 | @chapter Introduction to Profiling
|
|---|
| 101 |
|
|---|
| 102 | @ifset man
|
|---|
| 103 | @c man title gprof display call graph profile data
|
|---|
| 104 |
|
|---|
| 105 | @smallexample
|
|---|
| 106 | @c man begin SYNOPSIS
|
|---|
| 107 | gprof [ -[abcDhilLsTvwxyz] ] [ -[ACeEfFJnNOpPqQZ][@var{name}] ]
|
|---|
| 108 | [ -I @var{dirs} ] [ -d[@var{num}] ] [ -k @var{from/to} ]
|
|---|
| 109 | [ -m @var{min-count} ] [ -t @var{table-length} ]
|
|---|
| 110 | [ --[no-]annotated-source[=@var{name}] ]
|
|---|
| 111 | [ --[no-]exec-counts[=@var{name}] ]
|
|---|
| 112 | [ --[no-]flat-profile[=@var{name}] ] [ --[no-]graph[=@var{name}] ]
|
|---|
| 113 | [ --[no-]time=@var{name}] [ --all-lines ] [ --brief ]
|
|---|
| 114 | [ --debug[=@var{level}] ] [ --function-ordering ]
|
|---|
| 115 | [ --file-ordering ] [ --directory-path=@var{dirs} ]
|
|---|
| 116 | [ --display-unused-functions ] [ --file-format=@var{name} ]
|
|---|
| 117 | [ --file-info ] [ --help ] [ --line ] [ --min-count=@var{n} ]
|
|---|
| 118 | [ --no-static ] [ --print-path ] [ --separate-files ]
|
|---|
| 119 | [ --static-call-graph ] [ --sum ] [ --table-length=@var{len} ]
|
|---|
| 120 | [ --traditional ] [ --version ] [ --width=@var{n} ]
|
|---|
| 121 | [ --ignore-non-functions ] [ --demangle[=@var{STYLE}] ]
|
|---|
| 122 | [ --no-demangle ] [ @var{image-file} ] [ @var{profile-file} @dots{} ]
|
|---|
| 123 | @c man end
|
|---|
| 124 | @end smallexample
|
|---|
| 125 |
|
|---|
| 126 | @c man begin DESCRIPTION
|
|---|
| 127 | @code{gprof} produces an execution profile of C, Pascal, or Fortran77
|
|---|
| 128 | programs. The effect of called routines is incorporated in the profile
|
|---|
| 129 | of each caller. The profile data is taken from the call graph profile file
|
|---|
| 130 | (@file{gmon.out} default) which is created by programs
|
|---|
| 131 | that are compiled with the @samp{-pg} option of
|
|---|
| 132 | @code{cc}, @code{pc}, and @code{f77}.
|
|---|
| 133 | The @samp{-pg} option also links in versions of the library routines
|
|---|
| 134 | that are compiled for profiling. @code{Gprof} reads the given object
|
|---|
| 135 | file (the default is @code{a.out}) and establishes the relation between
|
|---|
| 136 | its symbol table and the call graph profile from @file{gmon.out}.
|
|---|
| 137 | If more than one profile file is specified, the @code{gprof}
|
|---|
| 138 | output shows the sum of the profile information in the given profile files.
|
|---|
| 139 |
|
|---|
| 140 | @code{Gprof} calculates the amount of time spent in each routine.
|
|---|
| 141 | Next, these times are propagated along the edges of the call graph.
|
|---|
| 142 | Cycles are discovered, and calls into a cycle are made to share the time
|
|---|
| 143 | of the cycle.
|
|---|
| 144 |
|
|---|
| 145 | @c man end
|
|---|
| 146 |
|
|---|
| 147 | @c man begin BUGS
|
|---|
| 148 | The granularity of the sampling is shown, but remains
|
|---|
| 149 | statistical at best.
|
|---|
| 150 | We assume that the time for each execution of a function
|
|---|
| 151 | can be expressed by the total time for the function divided
|
|---|
| 152 | by the number of times the function is called.
|
|---|
| 153 | Thus the time propagated along the call graph arcs to the function's
|
|---|
| 154 | parents is directly proportional to the number of times that
|
|---|
| 155 | arc is traversed.
|
|---|
| 156 |
|
|---|
| 157 | Parents that are not themselves profiled will have the time of
|
|---|
| 158 | their profiled children propagated to them, but they will appear
|
|---|
| 159 | to be spontaneously invoked in the call graph listing, and will
|
|---|
| 160 | not have their time propagated further.
|
|---|
| 161 | Similarly, signal catchers, even though profiled, will appear
|
|---|
| 162 | to be spontaneous (although for more obscure reasons).
|
|---|
| 163 | Any profiled children of signal catchers should have their times
|
|---|
| 164 | propagated properly, unless the signal catcher was invoked during
|
|---|
| 165 | the execution of the profiling routine, in which case all is lost.
|
|---|
| 166 |
|
|---|
| 167 | The profiled program must call @code{exit}(2)
|
|---|
| 168 | or return normally for the profiling information to be saved
|
|---|
| 169 | in the @file{gmon.out} file.
|
|---|
| 170 | @c man end
|
|---|
| 171 |
|
|---|
| 172 | @c man begin FILES
|
|---|
| 173 | @table @code
|
|---|
| 174 | @item @file{a.out}
|
|---|
| 175 | the namelist and text space.
|
|---|
| 176 | @item @file{gmon.out}
|
|---|
| 177 | dynamic call graph and profile.
|
|---|
| 178 | @item @file{gmon.sum}
|
|---|
| 179 | summarized dynamic call graph and profile.
|
|---|
| 180 | @end table
|
|---|
| 181 | @c man end
|
|---|
| 182 |
|
|---|
| 183 | @c man begin SEEALSO
|
|---|
| 184 | monitor(3), profil(2), cc(1), prof(1), and the Info entry for @file{gprof}.
|
|---|
| 185 |
|
|---|
| 186 | ``An Execution Profiler for Modular Programs'',
|
|---|
| 187 | by S. Graham, P. Kessler, M. McKusick;
|
|---|
| 188 | Software - Practice and Experience,
|
|---|
| 189 | Vol. 13, pp. 671-685, 1983.
|
|---|
| 190 |
|
|---|
| 191 | ``gprof: A Call Graph Execution Profiler'',
|
|---|
| 192 | by S. Graham, P. Kessler, M. McKusick;
|
|---|
| 193 | Proceedings of the SIGPLAN '82 Symposium on Compiler Construction,
|
|---|
| 194 | SIGPLAN Notices, Vol. 17, No 6, pp. 120-126, June 1982.
|
|---|
| 195 | @c man end
|
|---|
| 196 | @end ifset
|
|---|
| 197 |
|
|---|
| 198 | Profiling allows you to learn where your program spent its time and which
|
|---|
| 199 | functions called which other functions while it was executing. This
|
|---|
| 200 | information can show you which pieces of your program are slower than you
|
|---|
| 201 | expected, and might be candidates for rewriting to make your program
|
|---|
| 202 | execute faster. It can also tell you which functions are being called more
|
|---|
| 203 | or less often than you expected. This may help you spot bugs that had
|
|---|
| 204 | otherwise been unnoticed.
|
|---|
| 205 |
|
|---|
| 206 | Since the profiler uses information collected during the actual execution
|
|---|
| 207 | of your program, it can be used on programs that are too large or too
|
|---|
| 208 | complex to analyze by reading the source. However, how your program is run
|
|---|
| 209 | will affect the information that shows up in the profile data. If you
|
|---|
| 210 | don't use some feature of your program while it is being profiled, no
|
|---|
| 211 | profile information will be generated for that feature.
|
|---|
| 212 |
|
|---|
| 213 | Profiling has several steps:
|
|---|
| 214 |
|
|---|
| 215 | @itemize @bullet
|
|---|
| 216 | @item
|
|---|
| 217 | You must compile and link your program with profiling enabled.
|
|---|
| 218 | @xref{Compiling}.
|
|---|
| 219 |
|
|---|
| 220 | @item
|
|---|
| 221 | You must execute your program to generate a profile data file.
|
|---|
| 222 | @xref{Executing}.
|
|---|
| 223 |
|
|---|
| 224 | @item
|
|---|
| 225 | You must run @code{gprof} to analyze the profile data.
|
|---|
| 226 | @xref{Invoking}.
|
|---|
| 227 | @end itemize
|
|---|
| 228 |
|
|---|
| 229 | The next three chapters explain these steps in greater detail.
|
|---|
| 230 |
|
|---|
| 231 | @c man begin DESCRIPTION
|
|---|
| 232 |
|
|---|
| 233 | Several forms of output are available from the analysis.
|
|---|
| 234 |
|
|---|
| 235 | The @dfn{flat profile} shows how much time your program spent in each function,
|
|---|
| 236 | and how many times that function was called. If you simply want to know
|
|---|
| 237 | which functions burn most of the cycles, it is stated concisely here.
|
|---|
| 238 | @xref{Flat Profile}.
|
|---|
| 239 |
|
|---|
| 240 | The @dfn{call graph} shows, for each function, which functions called it, which
|
|---|
| 241 | other functions it called, and how many times. There is also an estimate
|
|---|
| 242 | of how much time was spent in the subroutines of each function. This can
|
|---|
| 243 | suggest places where you might try to eliminate function calls that use a
|
|---|
| 244 | lot of time. @xref{Call Graph}.
|
|---|
| 245 |
|
|---|
| 246 | The @dfn{annotated source} listing is a copy of the program's
|
|---|
| 247 | source code, labeled with the number of times each line of the
|
|---|
| 248 | program was executed. @xref{Annotated Source}.
|
|---|
| 249 | @c man end
|
|---|
| 250 |
|
|---|
| 251 | To better understand how profiling works, you may wish to read
|
|---|
| 252 | a description of its implementation.
|
|---|
| 253 | @xref{Implementation}.
|
|---|
| 254 |
|
|---|
| 255 | @node Compiling
|
|---|
| 256 | @chapter Compiling a Program for Profiling
|
|---|
| 257 |
|
|---|
| 258 | The first step in generating profile information for your program is
|
|---|
| 259 | to compile and link it with profiling enabled.
|
|---|
| 260 |
|
|---|
| 261 | To compile a source file for profiling, specify the @samp{-pg} option when
|
|---|
| 262 | you run the compiler. (This is in addition to the options you normally
|
|---|
| 263 | use.)
|
|---|
| 264 |
|
|---|
| 265 | To link the program for profiling, if you use a compiler such as @code{cc}
|
|---|
| 266 | to do the linking, simply specify @samp{-pg} in addition to your usual
|
|---|
| 267 | options. The same option, @samp{-pg}, alters either compilation or linking
|
|---|
| 268 | to do what is necessary for profiling. Here are examples:
|
|---|
| 269 |
|
|---|
| 270 | @example
|
|---|
| 271 | cc -g -c myprog.c utils.c -pg
|
|---|
| 272 | cc -o myprog myprog.o utils.o -pg
|
|---|
| 273 | @end example
|
|---|
| 274 |
|
|---|
| 275 | The @samp{-pg} option also works with a command that both compiles and links:
|
|---|
| 276 |
|
|---|
| 277 | @example
|
|---|
| 278 | cc -o myprog myprog.c utils.c -g -pg
|
|---|
| 279 | @end example
|
|---|
| 280 |
|
|---|
| 281 | If you run the linker @code{ld} directly instead of through a compiler
|
|---|
| 282 | such as @code{cc}, you may have to specify a profiling startup file
|
|---|
| 283 | @file{gcrt0.o} as the first input file instead of the usual startup
|
|---|
| 284 | file @file{crt0.o}. In addition, you would probably want to
|
|---|
| 285 | specify the profiling C library, @file{libc_p.a}, by writing
|
|---|
| 286 | @samp{-lc_p} instead of the usual @samp{-lc}. This is not absolutely
|
|---|
| 287 | necessary, but doing this gives you number-of-calls information for
|
|---|
| 288 | standard library functions such as @code{read} and @code{open}. For
|
|---|
| 289 | example:
|
|---|
| 290 |
|
|---|
| 291 | @example
|
|---|
| 292 | ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p
|
|---|
| 293 | @end example
|
|---|
| 294 |
|
|---|
| 295 | If you compile only some of the modules of the program with @samp{-pg}, you
|
|---|
| 296 | can still profile the program, but you won't get complete information about
|
|---|
| 297 | the modules that were compiled without @samp{-pg}. The only information
|
|---|
| 298 | you get for the functions in those modules is the total time spent in them;
|
|---|
| 299 | there is no record of how many times they were called, or from where. This
|
|---|
| 300 | will not affect the flat profile (except that the @code{calls} field for
|
|---|
| 301 | the functions will be blank), but will greatly reduce the usefulness of the
|
|---|
| 302 | call graph.
|
|---|
| 303 |
|
|---|
| 304 | If you wish to perform line-by-line profiling,
|
|---|
| 305 | you will also need to specify the @samp{-g} option,
|
|---|
| 306 | instructing the compiler to insert debugging symbols into the program
|
|---|
| 307 | that match program addresses to source code lines.
|
|---|
| 308 | @xref{Line-by-line}.
|
|---|
| 309 |
|
|---|
| 310 | In addition to the @samp{-pg} and @samp{-g} options,
|
|---|
| 311 | you may also wish to specify the @samp{-a} option when compiling.
|
|---|
| 312 | This will instrument
|
|---|
| 313 | the program to perform basic-block counting. As the program runs,
|
|---|
| 314 | it will count how many times it executed each branch of each @samp{if}
|
|---|
| 315 | statement, each iteration of each @samp{do} loop, etc. This will
|
|---|
| 316 | enable @code{gprof} to construct an annotated source code
|
|---|
| 317 | listing showing how many times each line of code was executed.
|
|---|
| 318 |
|
|---|
| 319 | @node Executing
|
|---|
| 320 | @chapter Executing the Program
|
|---|
| 321 |
|
|---|
| 322 | Once the program is compiled for profiling, you must run it in order to
|
|---|
| 323 | generate the information that @code{gprof} needs. Simply run the program
|
|---|
| 324 | as usual, using the normal arguments, file names, etc. The program should
|
|---|
| 325 | run normally, producing the same output as usual. It will, however, run
|
|---|
| 326 | somewhat slower than normal because of the time spent collecting and the
|
|---|
| 327 | writing the profile data.
|
|---|
| 328 |
|
|---|
| 329 | The way you run the program---the arguments and input that you give
|
|---|
| 330 | it---may have a dramatic effect on what the profile information shows. The
|
|---|
| 331 | profile data will describe the parts of the program that were activated for
|
|---|
| 332 | the particular input you use. For example, if the first command you give
|
|---|
| 333 | to your program is to quit, the profile data will show the time used in
|
|---|
| 334 | initialization and in cleanup, but not much else.
|
|---|
| 335 |
|
|---|
| 336 | Your program will write the profile data into a file called @file{gmon.out}
|
|---|
| 337 | just before exiting. If there is already a file called @file{gmon.out},
|
|---|
| 338 | its contents are overwritten. There is currently no way to tell the
|
|---|
| 339 | program to write the profile data under a different name, but you can rename
|
|---|
| 340 | the file afterward if you are concerned that it may be overwritten.
|
|---|
| 341 |
|
|---|
| 342 | In order to write the @file{gmon.out} file properly, your program must exit
|
|---|
| 343 | normally: by returning from @code{main} or by calling @code{exit}. Calling
|
|---|
| 344 | the low-level function @code{_exit} does not write the profile data, and
|
|---|
| 345 | neither does abnormal termination due to an unhandled signal.
|
|---|
| 346 |
|
|---|
| 347 | The @file{gmon.out} file is written in the program's @emph{current working
|
|---|
| 348 | directory} at the time it exits. This means that if your program calls
|
|---|
| 349 | @code{chdir}, the @file{gmon.out} file will be left in the last directory
|
|---|
| 350 | your program @code{chdir}'d to. If you don't have permission to write in
|
|---|
| 351 | this directory, the file is not written, and you will get an error message.
|
|---|
| 352 |
|
|---|
| 353 | Older versions of the @sc{gnu} profiling library may also write a file
|
|---|
| 354 | called @file{bb.out}. This file, if present, contains an human-readable
|
|---|
| 355 | listing of the basic-block execution counts. Unfortunately, the
|
|---|
| 356 | appearance of a human-readable @file{bb.out} means the basic-block
|
|---|
| 357 | counts didn't get written into @file{gmon.out}.
|
|---|
| 358 | The Perl script @code{bbconv.pl}, included with the @code{gprof}
|
|---|
| 359 | source distribution, will convert a @file{bb.out} file into
|
|---|
| 360 | a format readable by @code{gprof}. Invoke it like this:
|
|---|
| 361 |
|
|---|
| 362 | @smallexample
|
|---|
| 363 | bbconv.pl < bb.out > @var{bh-data}
|
|---|
| 364 | @end smallexample
|
|---|
| 365 |
|
|---|
| 366 | This translates the information in @file{bb.out} into a form that
|
|---|
| 367 | @code{gprof} can understand. But you still need to tell @code{gprof}
|
|---|
| 368 | about the existence of this translated information. To do that, include
|
|---|
| 369 | @var{bb-data} on the @code{gprof} command line, @emph{along with
|
|---|
| 370 | @file{gmon.out}}, like this:
|
|---|
| 371 |
|
|---|
| 372 | @smallexample
|
|---|
| 373 | gprof @var{options} @var{executable-file} gmon.out @var{bb-data} [@var{yet-more-profile-data-files}@dots{}] [> @var{outfile}]
|
|---|
| 374 | @end smallexample
|
|---|
| 375 |
|
|---|
| 376 | @node Invoking
|
|---|
| 377 | @chapter @code{gprof} Command Summary
|
|---|
| 378 |
|
|---|
| 379 | After you have a profile data file @file{gmon.out}, you can run @code{gprof}
|
|---|
| 380 | to interpret the information in it. The @code{gprof} program prints a
|
|---|
| 381 | flat profile and a call graph on standard output. Typically you would
|
|---|
| 382 | redirect the output of @code{gprof} into a file with @samp{>}.
|
|---|
| 383 |
|
|---|
| 384 | You run @code{gprof} like this:
|
|---|
| 385 |
|
|---|
| 386 | @smallexample
|
|---|
| 387 | gprof @var{options} [@var{executable-file} [@var{profile-data-files}@dots{}]] [> @var{outfile}]
|
|---|
| 388 | @end smallexample
|
|---|
| 389 |
|
|---|
| 390 | @noindent
|
|---|
| 391 | Here square-brackets indicate optional arguments.
|
|---|
| 392 |
|
|---|
| 393 | If you omit the executable file name, the file @file{a.out} is used. If
|
|---|
| 394 | you give no profile data file name, the file @file{gmon.out} is used. If
|
|---|
| 395 | any file is not in the proper format, or if the profile data file does not
|
|---|
| 396 | appear to belong to the executable file, an error message is printed.
|
|---|
| 397 |
|
|---|
| 398 | You can give more than one profile data file by entering all their names
|
|---|
| 399 | after the executable file name; then the statistics in all the data files
|
|---|
| 400 | are summed together.
|
|---|
| 401 |
|
|---|
| 402 | The order of these options does not matter.
|
|---|
| 403 |
|
|---|
| 404 | @menu
|
|---|
| 405 | * Output Options:: Controlling @code{gprof}'s output style
|
|---|
| 406 | * Analysis Options:: Controlling how @code{gprof} analyses its data
|
|---|
| 407 | * Miscellaneous Options::
|
|---|
| 408 | * Deprecated Options:: Options you no longer need to use, but which
|
|---|
| 409 | have been retained for compatibility
|
|---|
| 410 | * Symspecs:: Specifying functions to include or exclude
|
|---|
| 411 | @end menu
|
|---|
| 412 |
|
|---|
| 413 | @node Output Options,Analysis Options,,Invoking
|
|---|
| 414 | @section Output Options
|
|---|
| 415 |
|
|---|
| 416 | @c man begin OPTIONS
|
|---|
| 417 | These options specify which of several output formats
|
|---|
| 418 | @code{gprof} should produce.
|
|---|
| 419 |
|
|---|
| 420 | Many of these options take an optional @dfn{symspec} to specify
|
|---|
| 421 | functions to be included or excluded. These options can be
|
|---|
| 422 | specified multiple times, with different symspecs, to include
|
|---|
| 423 | or exclude sets of symbols. @xref{Symspecs}.
|
|---|
| 424 |
|
|---|
| 425 | Specifying any of these options overrides the default (@samp{-p -q}),
|
|---|
| 426 | which prints a flat profile and call graph analysis
|
|---|
| 427 | for all functions.
|
|---|
| 428 |
|
|---|
| 429 | @table @code
|
|---|
| 430 |
|
|---|
| 431 | @item -A[@var{symspec}]
|
|---|
| 432 | @itemx --annotated-source[=@var{symspec}]
|
|---|
| 433 | The @samp{-A} option causes @code{gprof} to print annotated source code.
|
|---|
| 434 | If @var{symspec} is specified, print output only for matching symbols.
|
|---|
| 435 | @xref{Annotated Source}.
|
|---|
| 436 |
|
|---|
| 437 | @item -b
|
|---|
| 438 | @itemx --brief
|
|---|
| 439 | If the @samp{-b} option is given, @code{gprof} doesn't print the
|
|---|
| 440 | verbose blurbs that try to explain the meaning of all of the fields in
|
|---|
| 441 | the tables. This is useful if you intend to print out the output, or
|
|---|
| 442 | are tired of seeing the blurbs.
|
|---|
| 443 |
|
|---|
| 444 | @item -C[@var{symspec}]
|
|---|
| 445 | @itemx --exec-counts[=@var{symspec}]
|
|---|
| 446 | The @samp{-C} option causes @code{gprof} to
|
|---|
| 447 | print a tally of functions and the number of times each was called.
|
|---|
| 448 | If @var{symspec} is specified, print tally only for matching symbols.
|
|---|
| 449 |
|
|---|
| 450 | If the profile data file contains basic-block count records, specifying
|
|---|
| 451 | the @samp{-l} option, along with @samp{-C}, will cause basic-block
|
|---|
| 452 | execution counts to be tallied and displayed.
|
|---|
| 453 |
|
|---|
| 454 | @item -i
|
|---|
| 455 | @itemx --file-info
|
|---|
| 456 | The @samp{-i} option causes @code{gprof} to display summary information
|
|---|
| 457 | about the profile data file(s) and then exit. The number of histogram,
|
|---|
| 458 | call graph, and basic-block count records is displayed.
|
|---|
| 459 |
|
|---|
| 460 | @item -I @var{dirs}
|
|---|
| 461 | @itemx --directory-path=@var{dirs}
|
|---|
| 462 | The @samp{-I} option specifies a list of search directories in
|
|---|
| 463 | which to find source files. Environment variable @var{GPROF_PATH}
|
|---|
| 464 | can also be used to convey this information.
|
|---|
| 465 | Used mostly for annotated source output.
|
|---|
| 466 |
|
|---|
| 467 | @item -J[@var{symspec}]
|
|---|
| 468 | @itemx --no-annotated-source[=@var{symspec}]
|
|---|
| 469 | The @samp{-J} option causes @code{gprof} not to
|
|---|
| 470 | print annotated source code.
|
|---|
| 471 | If @var{symspec} is specified, @code{gprof} prints annotated source,
|
|---|
| 472 | but excludes matching symbols.
|
|---|
| 473 |
|
|---|
| 474 | @item -L
|
|---|
| 475 | @itemx --print-path
|
|---|
| 476 | Normally, source filenames are printed with the path
|
|---|
| 477 | component suppressed. The @samp{-L} option causes @code{gprof}
|
|---|
| 478 | to print the full pathname of
|
|---|
| 479 | source filenames, which is determined
|
|---|
| 480 | from symbolic debugging information in the image file
|
|---|
| 481 | and is relative to the directory in which the compiler
|
|---|
| 482 | was invoked.
|
|---|
| 483 |
|
|---|
| 484 | @item -p[@var{symspec}]
|
|---|
| 485 | @itemx --flat-profile[=@var{symspec}]
|
|---|
| 486 | The @samp{-p} option causes @code{gprof} to print a flat profile.
|
|---|
| 487 | If @var{symspec} is specified, print flat profile only for matching symbols.
|
|---|
| 488 | @xref{Flat Profile}.
|
|---|
| 489 |
|
|---|
| 490 | @item -P[@var{symspec}]
|
|---|
| 491 | @itemx --no-flat-profile[=@var{symspec}]
|
|---|
| 492 | The @samp{-P} option causes @code{gprof} to suppress printing a flat profile.
|
|---|
| 493 | If @var{symspec} is specified, @code{gprof} prints a flat profile,
|
|---|
| 494 | but excludes matching symbols.
|
|---|
| 495 |
|
|---|
| 496 | @item -q[@var{symspec}]
|
|---|
| 497 | @itemx --graph[=@var{symspec}]
|
|---|
| 498 | The @samp{-q} option causes @code{gprof} to print the call graph analysis.
|
|---|
| 499 | If @var{symspec} is specified, print call graph only for matching symbols
|
|---|
| 500 | and their children.
|
|---|
| 501 | @xref{Call Graph}.
|
|---|
| 502 |
|
|---|
| 503 | @item -Q[@var{symspec}]
|
|---|
| 504 | @itemx --no-graph[=@var{symspec}]
|
|---|
| 505 | The @samp{-Q} option causes @code{gprof} to suppress printing the
|
|---|
| 506 | call graph.
|
|---|
| 507 | If @var{symspec} is specified, @code{gprof} prints a call graph,
|
|---|
| 508 | but excludes matching symbols.
|
|---|
| 509 |
|
|---|
| 510 | @item -y
|
|---|
| 511 | @itemx --separate-files
|
|---|
| 512 | This option affects annotated source output only.
|
|---|
| 513 | Normally, @code{gprof} prints annotated source files
|
|---|
| 514 | to standard-output. If this option is specified,
|
|---|
| 515 | annotated source for a file named @file{path/@var{filename}}
|
|---|
| 516 | is generated in the file @file{@var{filename}-ann}. If the underlying
|
|---|
| 517 | filesystem would truncate @file{@var{filename}-ann} so that it
|
|---|
| 518 | overwrites the original @file{@var{filename}}, @code{gprof} generates
|
|---|
| 519 | annotated source in the file @file{@var{filename}.ann} instead (if the
|
|---|
| 520 | original file name has an extension, that extension is @emph{replaced}
|
|---|
| 521 | with @file{.ann}).
|
|---|
| 522 |
|
|---|
| 523 | @item -Z[@var{symspec}]
|
|---|
| 524 | @itemx --no-exec-counts[=@var{symspec}]
|
|---|
| 525 | The @samp{-Z} option causes @code{gprof} not to
|
|---|
| 526 | print a tally of functions and the number of times each was called.
|
|---|
| 527 | If @var{symspec} is specified, print tally, but exclude matching symbols.
|
|---|
| 528 |
|
|---|
| 529 | @item --function-ordering
|
|---|
| 530 | The @samp{--function-ordering} option causes @code{gprof} to print a
|
|---|
| 531 | suggested function ordering for the program based on profiling data.
|
|---|
| 532 | This option suggests an ordering which may improve paging, tlb and
|
|---|
| 533 | cache behavior for the program on systems which support arbitrary
|
|---|
| 534 | ordering of functions in an executable.
|
|---|
| 535 |
|
|---|
| 536 | The exact details of how to force the linker to place functions
|
|---|
| 537 | in a particular order is system dependent and out of the scope of this
|
|---|
| 538 | manual.
|
|---|
| 539 |
|
|---|
| 540 | @item --file-ordering @var{map_file}
|
|---|
| 541 | The @samp{--file-ordering} option causes @code{gprof} to print a
|
|---|
| 542 | suggested .o link line ordering for the program based on profiling data.
|
|---|
| 543 | This option suggests an ordering which may improve paging, tlb and
|
|---|
| 544 | cache behavior for the program on systems which do not support arbitrary
|
|---|
| 545 | ordering of functions in an executable.
|
|---|
| 546 |
|
|---|
| 547 | Use of the @samp{-a} argument is highly recommended with this option.
|
|---|
| 548 |
|
|---|
| 549 | The @var{map_file} argument is a pathname to a file which provides
|
|---|
| 550 | function name to object file mappings. The format of the file is similar to
|
|---|
| 551 | the output of the program @code{nm}.
|
|---|
| 552 |
|
|---|
| 553 | @smallexample
|
|---|
| 554 | @group
|
|---|
| 555 | c-parse.o:00000000 T yyparse
|
|---|
| 556 | c-parse.o:00000004 C yyerrflag
|
|---|
| 557 | c-lang.o:00000000 T maybe_objc_method_name
|
|---|
| 558 | c-lang.o:00000000 T print_lang_statistics
|
|---|
| 559 | c-lang.o:00000000 T recognize_objc_keyword
|
|---|
| 560 | c-decl.o:00000000 T print_lang_identifier
|
|---|
| 561 | c-decl.o:00000000 T print_lang_type
|
|---|
| 562 | @dots{}
|
|---|
| 563 |
|
|---|
| 564 | @end group
|
|---|
| 565 | @end smallexample
|
|---|
| 566 |
|
|---|
| 567 | To create a @var{map_file} with @sc{gnu} @code{nm}, type a command like
|
|---|
| 568 | @kbd{nm --extern-only --defined-only -v --print-file-name program-name}.
|
|---|
| 569 |
|
|---|
| 570 | @item -T
|
|---|
| 571 | @itemx --traditional
|
|---|
| 572 | The @samp{-T} option causes @code{gprof} to print its output in
|
|---|
| 573 | ``traditional'' BSD style.
|
|---|
| 574 |
|
|---|
| 575 | @item -w @var{width}
|
|---|
| 576 | @itemx --width=@var{width}
|
|---|
| 577 | Sets width of output lines to @var{width}.
|
|---|
| 578 | Currently only used when printing the function index at the bottom
|
|---|
| 579 | of the call graph.
|
|---|
| 580 |
|
|---|
| 581 | @item -x
|
|---|
| 582 | @itemx --all-lines
|
|---|
| 583 | This option affects annotated source output only.
|
|---|
| 584 | By default, only the lines at the beginning of a basic-block
|
|---|
| 585 | are annotated. If this option is specified, every line in
|
|---|
| 586 | a basic-block is annotated by repeating the annotation for the
|
|---|
| 587 | first line. This behavior is similar to @code{tcov}'s @samp{-a}.
|
|---|
| 588 |
|
|---|
| 589 | @item --demangle[=@var{style}]
|
|---|
| 590 | @itemx --no-demangle
|
|---|
| 591 | These options control whether C++ symbol names should be demangled when
|
|---|
| 592 | printing output. The default is to demangle symbols. The
|
|---|
| 593 | @code{--no-demangle} option may be used to turn off demangling. Different
|
|---|
| 594 | compilers have different mangling styles. The optional demangling style
|
|---|
| 595 | argument can be used to choose an appropriate demangling style for your
|
|---|
| 596 | compiler.
|
|---|
| 597 | @end table
|
|---|
| 598 |
|
|---|
| 599 | @node Analysis Options,Miscellaneous Options,Output Options,Invoking
|
|---|
| 600 | @section Analysis Options
|
|---|
| 601 |
|
|---|
| 602 | @table @code
|
|---|
| 603 |
|
|---|
| 604 | @item -a
|
|---|
| 605 | @itemx --no-static
|
|---|
| 606 | The @samp{-a} option causes @code{gprof} to suppress the printing of
|
|---|
| 607 | statically declared (private) functions. (These are functions whose
|
|---|
| 608 | names are not listed as global, and which are not visible outside the
|
|---|
| 609 | file/function/block where they were defined.) Time spent in these
|
|---|
| 610 | functions, calls to/from them, etc, will all be attributed to the
|
|---|
| 611 | function that was loaded directly before it in the executable file.
|
|---|
| 612 | @c This is compatible with Unix @code{gprof}, but a bad idea.
|
|---|
| 613 | This option affects both the flat profile and the call graph.
|
|---|
| 614 |
|
|---|
| 615 | @item -c
|
|---|
| 616 | @itemx --static-call-graph
|
|---|
| 617 | The @samp{-c} option causes the call graph of the program to be
|
|---|
| 618 | augmented by a heuristic which examines the text space of the object
|
|---|
| 619 | file and identifies function calls in the binary machine code.
|
|---|
| 620 | Since normal call graph records are only generated when functions are
|
|---|
| 621 | entered, this option identifies children that could have been called,
|
|---|
| 622 | but never were. Calls to functions that were not compiled with
|
|---|
| 623 | profiling enabled are also identified, but only if symbol table
|
|---|
| 624 | entries are present for them.
|
|---|
| 625 | Calls to dynamic library routines are typically @emph{not} found
|
|---|
| 626 | by this option.
|
|---|
| 627 | Parents or children identified via this heuristic
|
|---|
| 628 | are indicated in the call graph with call counts of @samp{0}.
|
|---|
| 629 |
|
|---|
| 630 | @item -D
|
|---|
| 631 | @itemx --ignore-non-functions
|
|---|
| 632 | The @samp{-D} option causes @code{gprof} to ignore symbols which
|
|---|
| 633 | are not known to be functions. This option will give more accurate
|
|---|
| 634 | profile data on systems where it is supported (Solaris and HPUX for
|
|---|
| 635 | example).
|
|---|
| 636 |
|
|---|
| 637 | @item -k @var{from}/@var{to}
|
|---|
| 638 | The @samp{-k} option allows you to delete from the call graph any arcs from
|
|---|
| 639 | symbols matching symspec @var{from} to those matching symspec @var{to}.
|
|---|
| 640 |
|
|---|
| 641 | @item -l
|
|---|
| 642 | @itemx --line
|
|---|
| 643 | The @samp{-l} option enables line-by-line profiling, which causes
|
|---|
| 644 | histogram hits to be charged to individual source code lines,
|
|---|
| 645 | instead of functions.
|
|---|
| 646 | If the program was compiled with basic-block counting enabled,
|
|---|
| 647 | this option will also identify how many times each line of
|
|---|
| 648 | code was executed.
|
|---|
| 649 | While line-by-line profiling can help isolate where in a large function
|
|---|
| 650 | a program is spending its time, it also significantly increases
|
|---|
| 651 | the running time of @code{gprof}, and magnifies statistical
|
|---|
| 652 | inaccuracies.
|
|---|
| 653 | @xref{Sampling Error}.
|
|---|
| 654 |
|
|---|
| 655 | @item -m @var{num}
|
|---|
| 656 | @itemx --min-count=@var{num}
|
|---|
| 657 | This option affects execution count output only.
|
|---|
| 658 | Symbols that are executed less than @var{num} times are suppressed.
|
|---|
| 659 |
|
|---|
| 660 | @item -n[@var{symspec}]
|
|---|
| 661 | @itemx --time[=@var{symspec}]
|
|---|
| 662 | The @samp{-n} option causes @code{gprof}, in its call graph analysis,
|
|---|
| 663 | to only propagate times for symbols matching @var{symspec}.
|
|---|
| 664 |
|
|---|
| 665 | @item -N[@var{symspec}]
|
|---|
| 666 | @itemx --no-time[=@var{symspec}]
|
|---|
| 667 | The @samp{-n} option causes @code{gprof}, in its call graph analysis,
|
|---|
| 668 | not to propagate times for symbols matching @var{symspec}.
|
|---|
| 669 |
|
|---|
| 670 | @item -z
|
|---|
| 671 | @itemx --display-unused-functions
|
|---|
| 672 | If you give the @samp{-z} option, @code{gprof} will mention all
|
|---|
| 673 | functions in the flat profile, even those that were never called, and
|
|---|
| 674 | that had no time spent in them. This is useful in conjunction with the
|
|---|
| 675 | @samp{-c} option for discovering which routines were never called.
|
|---|
| 676 |
|
|---|
| 677 | @end table
|
|---|
| 678 |
|
|---|
| 679 | @node Miscellaneous Options,Deprecated Options,Analysis Options,Invoking
|
|---|
| 680 | @section Miscellaneous Options
|
|---|
| 681 |
|
|---|
| 682 | @table @code
|
|---|
| 683 |
|
|---|
| 684 | @item -d[@var{num}]
|
|---|
| 685 | @itemx --debug[=@var{num}]
|
|---|
| 686 | The @samp{-d @var{num}} option specifies debugging options.
|
|---|
| 687 | If @var{num} is not specified, enable all debugging.
|
|---|
| 688 | @xref{Debugging}.
|
|---|
| 689 |
|
|---|
| 690 | @item -O@var{name}
|
|---|
| 691 | @itemx --file-format=@var{name}
|
|---|
| 692 | Selects the format of the profile data files. Recognized formats are
|
|---|
| 693 | @samp{auto} (the default), @samp{bsd}, @samp{4.4bsd}, @samp{magic}, and
|
|---|
| 694 | @samp{prof} (not yet supported).
|
|---|
| 695 |
|
|---|
| 696 | @item -s
|
|---|
| 697 | @itemx --sum
|
|---|
| 698 | The @samp{-s} option causes @code{gprof} to summarize the information
|
|---|
| 699 | in the profile data files it read in, and write out a profile data
|
|---|
| 700 | file called @file{gmon.sum}, which contains all the information from
|
|---|
| 701 | the profile data files that @code{gprof} read in. The file @file{gmon.sum}
|
|---|
| 702 | may be one of the specified input files; the effect of this is to
|
|---|
| 703 | merge the data in the other input files into @file{gmon.sum}.
|
|---|
| 704 |
|
|---|
| 705 | Eventually you can run @code{gprof} again without @samp{-s} to analyze the
|
|---|
| 706 | cumulative data in the file @file{gmon.sum}.
|
|---|
| 707 |
|
|---|
| 708 | @item -v
|
|---|
| 709 | @itemx --version
|
|---|
| 710 | The @samp{-v} flag causes @code{gprof} to print the current version
|
|---|
| 711 | number, and then exit.
|
|---|
| 712 |
|
|---|
| 713 | @end table
|
|---|
| 714 |
|
|---|
| 715 | @node Deprecated Options,Symspecs,Miscellaneous Options,Invoking
|
|---|
| 716 | @section Deprecated Options
|
|---|
| 717 |
|
|---|
| 718 | @table @code
|
|---|
| 719 |
|
|---|
| 720 | These options have been replaced with newer versions that use symspecs.
|
|---|
| 721 |
|
|---|
| 722 | @item -e @var{function_name}
|
|---|
| 723 | The @samp{-e @var{function}} option tells @code{gprof} to not print
|
|---|
| 724 | information about the function @var{function_name} (and its
|
|---|
| 725 | children@dots{}) in the call graph. The function will still be listed
|
|---|
| 726 | as a child of any functions that call it, but its index number will be
|
|---|
| 727 | shown as @samp{[not printed]}. More than one @samp{-e} option may be
|
|---|
| 728 | given; only one @var{function_name} may be indicated with each @samp{-e}
|
|---|
| 729 | option.
|
|---|
| 730 |
|
|---|
| 731 | @item -E @var{function_name}
|
|---|
| 732 | The @code{-E @var{function}} option works like the @code{-e} option, but
|
|---|
| 733 | time spent in the function (and children who were not called from
|
|---|
| 734 | anywhere else), will not be used to compute the percentages-of-time for
|
|---|
| 735 | the call graph. More than one @samp{-E} option may be given; only one
|
|---|
| 736 | @var{function_name} may be indicated with each @samp{-E} option.
|
|---|
| 737 |
|
|---|
| 738 | @item -f @var{function_name}
|
|---|
| 739 | The @samp{-f @var{function}} option causes @code{gprof} to limit the
|
|---|
| 740 | call graph to the function @var{function_name} and its children (and
|
|---|
| 741 | their children@dots{}). More than one @samp{-f} option may be given;
|
|---|
| 742 | only one @var{function_name} may be indicated with each @samp{-f}
|
|---|
| 743 | option.
|
|---|
| 744 |
|
|---|
| 745 | @item -F @var{function_name}
|
|---|
| 746 | The @samp{-F @var{function}} option works like the @code{-f} option, but
|
|---|
| 747 | only time spent in the function and its children (and their
|
|---|
| 748 | children@dots{}) will be used to determine total-time and
|
|---|
| 749 | percentages-of-time for the call graph. More than one @samp{-F} option
|
|---|
| 750 | may be given; only one @var{function_name} may be indicated with each
|
|---|
| 751 | @samp{-F} option. The @samp{-F} option overrides the @samp{-E} option.
|
|---|
| 752 |
|
|---|
| 753 | @end table
|
|---|
| 754 |
|
|---|
| 755 | @c man end
|
|---|
| 756 |
|
|---|
| 757 | Note that only one function can be specified with each @code{-e},
|
|---|
| 758 | @code{-E}, @code{-f} or @code{-F} option. To specify more than one
|
|---|
| 759 | function, use multiple options. For example, this command:
|
|---|
| 760 |
|
|---|
| 761 | @example
|
|---|
| 762 | gprof -e boring -f foo -f bar myprogram > gprof.output
|
|---|
| 763 | @end example
|
|---|
| 764 |
|
|---|
| 765 | @noindent
|
|---|
| 766 | lists in the call graph all functions that were reached from either
|
|---|
| 767 | @code{foo} or @code{bar} and were not reachable from @code{boring}.
|
|---|
| 768 |
|
|---|
| 769 | @node Symspecs,,Deprecated Options,Invoking
|
|---|
| 770 | @section Symspecs
|
|---|
| 771 |
|
|---|
| 772 | Many of the output options allow functions to be included or excluded
|
|---|
| 773 | using @dfn{symspecs} (symbol specifications), which observe the
|
|---|
| 774 | following syntax:
|
|---|
| 775 |
|
|---|
| 776 | @example
|
|---|
| 777 | filename_containing_a_dot
|
|---|
| 778 | | funcname_not_containing_a_dot
|
|---|
| 779 | | linenumber
|
|---|
| 780 | | ( [ any_filename ] `:' ( any_funcname | linenumber ) )
|
|---|
| 781 | @end example
|
|---|
| 782 |
|
|---|
| 783 | Here are some sample symspecs:
|
|---|
| 784 |
|
|---|
| 785 | @table @samp
|
|---|
| 786 | @item main.c
|
|---|
| 787 | Selects everything in file @file{main.c}---the
|
|---|
| 788 | dot in the string tells @code{gprof} to interpret
|
|---|
| 789 | the string as a filename, rather than as
|
|---|
| 790 | a function name. To select a file whose
|
|---|
| 791 | name does not contain a dot, a trailing colon
|
|---|
| 792 | should be specified. For example, @samp{odd:} is
|
|---|
| 793 | interpreted as the file named @file{odd}.
|
|---|
| 794 |
|
|---|
| 795 | @item main
|
|---|
| 796 | Selects all functions named @samp{main}.
|
|---|
| 797 |
|
|---|
| 798 | Note that there may be multiple instances of the same function name
|
|---|
| 799 | because some of the definitions may be local (i.e., static). Unless a
|
|---|
| 800 | function name is unique in a program, you must use the colon notation
|
|---|
| 801 | explained below to specify a function from a specific source file.
|
|---|
| 802 |
|
|---|
| 803 | Sometimes, function names contain dots. In such cases, it is necessary
|
|---|
| 804 | to add a leading colon to the name. For example, @samp{:.mul} selects
|
|---|
| 805 | function @samp{.mul}.
|
|---|
| 806 |
|
|---|
| 807 | In some object file formats, symbols have a leading underscore.
|
|---|
| 808 | @code{gprof} will normally not print these underscores. When you name a
|
|---|
| 809 | symbol in a symspec, you should type it exactly as @code{gprof} prints
|
|---|
| 810 | it in its output. For example, if the compiler produces a symbol
|
|---|
| 811 | @samp{_main} from your @code{main} function, @code{gprof} still prints
|
|---|
| 812 | it as @samp{main} in its output, so you should use @samp{main} in
|
|---|
| 813 | symspecs.
|
|---|
| 814 |
|
|---|
| 815 | @item main.c:main
|
|---|
| 816 | Selects function @samp{main} in file @file{main.c}.
|
|---|
| 817 |
|
|---|
| 818 | @item main.c:134
|
|---|
| 819 | Selects line 134 in file @file{main.c}.
|
|---|
| 820 | @end table
|
|---|
| 821 |
|
|---|
| 822 | @node Output
|
|---|
| 823 | @chapter Interpreting @code{gprof}'s Output
|
|---|
| 824 |
|
|---|
| 825 | @code{gprof} can produce several different output styles, the
|
|---|
| 826 | most important of which are described below. The simplest output
|
|---|
| 827 | styles (file information, execution count, and function and file ordering)
|
|---|
| 828 | are not described here, but are documented with the respective options
|
|---|
| 829 | that trigger them.
|
|---|
| 830 | @xref{Output Options}.
|
|---|
| 831 |
|
|---|
| 832 | @menu
|
|---|
| 833 | * Flat Profile:: The flat profile shows how much time was spent
|
|---|
| 834 | executing directly in each function.
|
|---|
| 835 | * Call Graph:: The call graph shows which functions called which
|
|---|
| 836 | others, and how much time each function used
|
|---|
| 837 | when its subroutine calls are included.
|
|---|
| 838 | * Line-by-line:: @code{gprof} can analyze individual source code lines
|
|---|
| 839 | * Annotated Source:: The annotated source listing displays source code
|
|---|
| 840 | labeled with execution counts
|
|---|
| 841 | @end menu
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 | @node Flat Profile,Call Graph,,Output
|
|---|
| 845 | @section The Flat Profile
|
|---|
| 846 | @cindex flat profile
|
|---|
| 847 |
|
|---|
| 848 | The @dfn{flat profile} shows the total amount of time your program
|
|---|
| 849 | spent executing each function. Unless the @samp{-z} option is given,
|
|---|
| 850 | functions with no apparent time spent in them, and no apparent calls
|
|---|
| 851 | to them, are not mentioned. Note that if a function was not compiled
|
|---|
| 852 | for profiling, and didn't run long enough to show up on the program
|
|---|
| 853 | counter histogram, it will be indistinguishable from a function that
|
|---|
| 854 | was never called.
|
|---|
| 855 |
|
|---|
| 856 | This is part of a flat profile for a small program:
|
|---|
| 857 |
|
|---|
| 858 | @smallexample
|
|---|
| 859 | @group
|
|---|
| 860 | Flat profile:
|
|---|
| 861 |
|
|---|
| 862 | Each sample counts as 0.01 seconds.
|
|---|
| 863 | % cumulative self self total
|
|---|
| 864 | time seconds seconds calls ms/call ms/call name
|
|---|
| 865 | 33.34 0.02 0.02 7208 0.00 0.00 open
|
|---|
| 866 | 16.67 0.03 0.01 244 0.04 0.12 offtime
|
|---|
| 867 | 16.67 0.04 0.01 8 1.25 1.25 memccpy
|
|---|
| 868 | 16.67 0.05 0.01 7 1.43 1.43 write
|
|---|
| 869 | 16.67 0.06 0.01 mcount
|
|---|
| 870 | 0.00 0.06 0.00 236 0.00 0.00 tzset
|
|---|
| 871 | 0.00 0.06 0.00 192 0.00 0.00 tolower
|
|---|
| 872 | 0.00 0.06 0.00 47 0.00 0.00 strlen
|
|---|
| 873 | 0.00 0.06 0.00 45 0.00 0.00 strchr
|
|---|
| 874 | 0.00 0.06 0.00 1 0.00 50.00 main
|
|---|
| 875 | 0.00 0.06 0.00 1 0.00 0.00 memcpy
|
|---|
| 876 | 0.00 0.06 0.00 1 0.00 10.11 print
|
|---|
| 877 | 0.00 0.06 0.00 1 0.00 0.00 profil
|
|---|
| 878 | 0.00 0.06 0.00 1 0.00 50.00 report
|
|---|
| 879 | @dots{}
|
|---|
| 880 | @end group
|
|---|
| 881 | @end smallexample
|
|---|
| 882 |
|
|---|
| 883 | @noindent
|
|---|
| 884 | The functions are sorted by first by decreasing run-time spent in them,
|
|---|
| 885 | then by decreasing number of calls, then alphabetically by name. The
|
|---|
| 886 | functions @samp{mcount} and @samp{profil} are part of the profiling
|
|---|
| 887 | apparatus and appear in every flat profile; their time gives a measure of
|
|---|
| 888 | the amount of overhead due to profiling.
|
|---|
| 889 |
|
|---|
| 890 | Just before the column headers, a statement appears indicating
|
|---|
| 891 | how much time each sample counted as.
|
|---|
| 892 | This @dfn{sampling period} estimates the margin of error in each of the time
|
|---|
| 893 | figures. A time figure that is not much larger than this is not
|
|---|
| 894 | reliable. In this example, each sample counted as 0.01 seconds,
|
|---|
| 895 | suggesting a 100 Hz sampling rate.
|
|---|
| 896 | The program's total execution time was 0.06
|
|---|
| 897 | seconds, as indicated by the @samp{cumulative seconds} field. Since
|
|---|
| 898 | each sample counted for 0.01 seconds, this means only six samples
|
|---|
| 899 | were taken during the run. Two of the samples occurred while the
|
|---|
| 900 | program was in the @samp{open} function, as indicated by the
|
|---|
| 901 | @samp{self seconds} field. Each of the other four samples
|
|---|
| 902 | occurred one each in @samp{offtime}, @samp{memccpy}, @samp{write},
|
|---|
| 903 | and @samp{mcount}.
|
|---|
| 904 | Since only six samples were taken, none of these values can
|
|---|
| 905 | be regarded as particularly reliable.
|
|---|
| 906 | In another run,
|
|---|
| 907 | the @samp{self seconds} field for
|
|---|
| 908 | @samp{mcount} might well be @samp{0.00} or @samp{0.02}.
|
|---|
| 909 | @xref{Sampling Error}, for a complete discussion.
|
|---|
| 910 |
|
|---|
| 911 | The remaining functions in the listing (those whose
|
|---|
| 912 | @samp{self seconds} field is @samp{0.00}) didn't appear
|
|---|
| 913 | in the histogram samples at all. However, the call graph
|
|---|
| 914 | indicated that they were called, so therefore they are listed,
|
|---|
| 915 | sorted in decreasing order by the @samp{calls} field.
|
|---|
| 916 | Clearly some time was spent executing these functions,
|
|---|
| 917 | but the paucity of histogram samples prevents any
|
|---|
| 918 | determination of how much time each took.
|
|---|
| 919 |
|
|---|
| 920 | Here is what the fields in each line mean:
|
|---|
| 921 |
|
|---|
| 922 | @table @code
|
|---|
| 923 | @item % time
|
|---|
| 924 | This is the percentage of the total execution time your program spent
|
|---|
| 925 | in this function. These should all add up to 100%.
|
|---|
| 926 |
|
|---|
| 927 | @item cumulative seconds
|
|---|
| 928 | This is the cumulative total number of seconds the computer spent
|
|---|
| 929 | executing this functions, plus the time spent in all the functions
|
|---|
| 930 | above this one in this table.
|
|---|
| 931 |
|
|---|
| 932 | @item self seconds
|
|---|
| 933 | This is the number of seconds accounted for by this function alone.
|
|---|
| 934 | The flat profile listing is sorted first by this number.
|
|---|
| 935 |
|
|---|
| 936 | @item calls
|
|---|
| 937 | This is the total number of times the function was called. If the
|
|---|
| 938 | function was never called, or the number of times it was called cannot
|
|---|
| 939 | be determined (probably because the function was not compiled with
|
|---|
| 940 | profiling enabled), the @dfn{calls} field is blank.
|
|---|
| 941 |
|
|---|
| 942 | @item self ms/call
|
|---|
| 943 | This represents the average number of milliseconds spent in this
|
|---|
| 944 | function per call, if this function is profiled. Otherwise, this field
|
|---|
| 945 | is blank for this function.
|
|---|
| 946 |
|
|---|
| 947 | @item total ms/call
|
|---|
| 948 | This represents the average number of milliseconds spent in this
|
|---|
| 949 | function and its descendants per call, if this function is profiled.
|
|---|
| 950 | Otherwise, this field is blank for this function.
|
|---|
| 951 | This is the only field in the flat profile that uses call graph analysis.
|
|---|
| 952 |
|
|---|
| 953 | @item name
|
|---|
| 954 | This is the name of the function. The flat profile is sorted by this
|
|---|
| 955 | field alphabetically after the @dfn{self seconds} and @dfn{calls}
|
|---|
| 956 | fields are sorted.
|
|---|
| 957 | @end table
|
|---|
| 958 |
|
|---|
| 959 | @node Call Graph,Line-by-line,Flat Profile,Output
|
|---|
| 960 | @section The Call Graph
|
|---|
| 961 | @cindex call graph
|
|---|
| 962 |
|
|---|
| 963 | The @dfn{call graph} shows how much time was spent in each function
|
|---|
| 964 | and its children. From this information, you can find functions that,
|
|---|
| 965 | while they themselves may not have used much time, called other
|
|---|
| 966 | functions that did use unusual amounts of time.
|
|---|
| 967 |
|
|---|
| 968 | Here is a sample call from a small program. This call came from the
|
|---|
| 969 | same @code{gprof} run as the flat profile example in the previous
|
|---|
| 970 | chapter.
|
|---|
| 971 |
|
|---|
| 972 | @smallexample
|
|---|
| 973 | @group
|
|---|
| 974 | granularity: each sample hit covers 2 byte(s) for 20.00% of 0.05 seconds
|
|---|
| 975 |
|
|---|
| 976 | index % time self children called name
|
|---|
| 977 | <spontaneous>
|
|---|
| 978 | [1] 100.0 0.00 0.05 start [1]
|
|---|
| 979 | 0.00 0.05 1/1 main [2]
|
|---|
| 980 | 0.00 0.00 1/2 on_exit [28]
|
|---|
| 981 | 0.00 0.00 1/1 exit [59]
|
|---|
| 982 | -----------------------------------------------
|
|---|
| 983 | 0.00 0.05 1/1 start [1]
|
|---|
| 984 | [2] 100.0 0.00 0.05 1 main [2]
|
|---|
| 985 | 0.00 0.05 1/1 report [3]
|
|---|
| 986 | -----------------------------------------------
|
|---|
| 987 | 0.00 0.05 1/1 main [2]
|
|---|
| 988 | [3] 100.0 0.00 0.05 1 report [3]
|
|---|
| 989 | 0.00 0.03 8/8 timelocal [6]
|
|---|
| 990 | 0.00 0.01 1/1 print [9]
|
|---|
| 991 | 0.00 0.01 9/9 fgets [12]
|
|---|
| 992 | 0.00 0.00 12/34 strncmp <cycle 1> [40]
|
|---|
| 993 | 0.00 0.00 8/8 lookup [20]
|
|---|
| 994 | 0.00 0.00 1/1 fopen [21]
|
|---|
| 995 | 0.00 0.00 8/8 chewtime [24]
|
|---|
| 996 | 0.00 0.00 8/16 skipspace [44]
|
|---|
| 997 | -----------------------------------------------
|
|---|
| 998 | [4] 59.8 0.01 0.02 8+472 <cycle 2 as a whole> [4]
|
|---|
| 999 | 0.01 0.02 244+260 offtime <cycle 2> [7]
|
|---|
| 1000 | 0.00 0.00 236+1 tzset <cycle 2> [26]
|
|---|
| 1001 | -----------------------------------------------
|
|---|
| 1002 | @end group
|
|---|
| 1003 | @end smallexample
|
|---|
| 1004 |
|
|---|
|
|---|