1 1.1 skrll README for GPROF 2 1.1 skrll 3 1.1.1.2 christos This is the GNU profiler. It is distributed with other "binary 4 1.1.1.2 christos utilities" which should be in ../binutils. See ../binutils/README for 5 1.1 skrll more general notes, including where to send bug reports. 6 1.1 skrll 7 1.1 skrll This file documents the changes and new features available with this 8 1.1 skrll version of GNU gprof. 9 1.1 skrll 10 1.1 skrll * New Features 11 1.1 skrll 12 1.1 skrll o Long options 13 1.1 skrll 14 1.1 skrll o Supports generalized file format, without breaking backward compatibility: 15 1.1 skrll new file format supports basic-block execution counts and non-realtime 16 1.1 skrll histograms (see below) 17 1.1 skrll 18 1.1 skrll o Supports profiling at the line level: flat profiles, call-graph profiles, 19 1.1 skrll and execution-counts can all be displayed at a level that identifies 20 1.1 skrll individual lines rather than just functions 21 1.1 skrll 22 1.1 skrll o Test-coverage support (similar to Sun tcov program): source files 23 1.1 skrll can be annotated with the number of times a function was invoked 24 1.1 skrll or with the number of times each basic-block in a function was 25 1.1 skrll executed 26 1.1 skrll 27 1.1 skrll o Generalized histograms: not just execution-time, but arbitrary 28 1.1 skrll histograms are support (for example, performance counter based 29 1.1 skrll profiles) 30 1.1 skrll 31 1.1 skrll o Powerful mechanism to select data to be included/excluded from 32 1.1 skrll analysis and/or output 33 1.1 skrll 34 1.1 skrll o Support for DEC OSF/1 v3.0 35 1.1 skrll 36 1.1 skrll o Full cross-platform profiling support: gprof uses BFD to support 37 1.1 skrll arbitrary, non-native object file formats and non-native byte-orders 38 1.1 skrll (this feature has not been tested yet) 39 1.1 skrll 40 1.1 skrll o In the call-graph function index, static function names are now 41 1.1 skrll printed together with the filename in which the function was defined 42 1.1 skrll (required bfd_find_nearest_line() support and symbolic debugging 43 1.1 skrll information to be present in the executable file) 44 1.1 skrll 45 1.1 skrll o Major overhaul of source code (compiles cleanly with -Wall, etc.) 46 1.1 skrll 47 1.1 skrll * Supported Platforms 48 1.1 skrll 49 1.1 skrll The current version is known to work on: 50 1.1 skrll 51 1.1 skrll o DEC OSF/1 v3.0 52 1.1 skrll All features supported. 53 1.1 skrll 54 1.1 skrll o SunOS 4.1.x 55 1.1 skrll All features supported. 56 1.1 skrll 57 1.1 skrll o Solaris 2.3 58 1.1 skrll Line-level profiling unsupported because bfd_find_nearest_line() 59 1.1 skrll is not fully implemented for Elf binaries. 60 1.1 skrll 61 1.1 skrll o HP-UX 9.01 62 1.1 skrll Line-level profiling unsupported because bfd_find_nearest_line() 63 1.1 skrll is not fully implemented for SOM binaries. 64 1.1 skrll 65 1.1 skrll * Detailed Description 66 1.1 skrll 67 1.1 skrll ** User Interface Changes 68 1.1 skrll 69 1.1 skrll The command-line interface is backwards compatible with earlier 70 1.1 skrll versions of GNU gprof and Berkeley gprof. The only exception is 71 1.1 skrll the option to delete arcs from the call graph. The old syntax 72 1.1 skrll was: 73 1.1 skrll 74 1.1 skrll -k fromname toname 75 1.1 skrll 76 1.1 skrll while the new syntax is: 77 1.1 skrll 78 1.1 skrll -k fromname/toname 79 1.1 skrll 80 1.1 skrll This change was necessary to be compatible with long-option parsing. 81 1.1 skrll Also, "fromname" and "toname" can now be arbitrary symspecs rather 82 1.1 skrll than just function names (see below for an explanation of symspecs). 83 1.1 skrll For example, option "-k gprof.c/" suppresses all arcs due to calls out 84 1.1 skrll of file "gprof.c". 85 1.1 skrll 86 1.1 skrll *** Sym Specs 87 1.1 skrll 88 1.1 skrll It is often necessary to apply gprof only to specific parts of a 89 1.1 skrll program. GNU gprof has a simple but powerful mechanism to achieve 90 1.1 skrll this. So called {\em symspecs\/} provide the foundation for this 91 1.1 skrll mechanism. A symspec selects the parts of a profiled program to which 92 1.1 skrll an operation should be applied to. The syntax of a symspec is 93 1.1 skrll simple: 94 1.1 skrll 95 1.1 skrll filename_containing_a_dot 96 1.1 skrll | funcname_not_containing_a_dot 97 1.1 skrll | linenumber 98 1.1 skrll | ( [ any_filename ] `:' ( any_funcname | linenumber ) ) 99 1.1 skrll 100 1.1 skrll Here are some examples: 101 1.1 skrll 102 1.1 skrll main.c Selects everything in file "main.c"---the 103 1.1 skrll dot in the string tells gprof to interpret 104 1.1 skrll the string as a filename, rather than as 105 1.1 skrll a function name. To select a file whose 106 1.1 skrll name does contain a dot, a trailing colon 107 1.1 skrll should be specified. For example, "odd:" is 108 1.1 skrll interpreted as the file named "odd". 109 1.1 skrll 110 1.1 skrll main Selects all functions named "main". Notice 111 1.1 skrll that there may be multiple instances of the 112 1.1 skrll same function name because some of the 113 1.1 skrll definitions may be local (i.e., static). 114 1.1 skrll Unless a function name is unique in a program, 115 1.1 skrll you must use the colon notation explained 116 1.1 skrll below to specify a function from a specific 117 1.1 skrll source file. Sometimes, functionnames contain 118 1.1 skrll dots. In such cases, it is necessary to 119 1.1 skrll add a leading colon to the name. For example, 120 1.1 skrll ":.mul" selects function ".mul". 121 1.1.1.2 christos 122 1.1 skrll main.c:main Selects function "main" in file "main.c". 123 1.1 skrll 124 1.1 skrll main.c:134 Selects line 134 in file "main.c". 125 1.1 skrll 126 1.1 skrll IMPLEMENTATION NOTE: The source code uses the type sym_id for symspecs. 127 1.1 skrll At some point, this probably ought to be changed to "sym_spec" to make 128 1.1 skrll reading the code easier. 129 1.1 skrll 130 1.1 skrll *** Long options 131 1.1 skrll 132 1.1 skrll GNU gprof now supports long options. The following is a list of all 133 1.1 skrll supported options. Options that are listed without description 134 1.1 skrll operate in the same manner as the corresponding option in older 135 1.1 skrll versions of gprof. 136 1.1 skrll 137 1.1 skrll Short Form: Long Form: 138 1.1 skrll ----------- ---------- 139 1.1 skrll -l --line 140 1.1 skrll Request profiling at the line-level rather 141 1.1 skrll than just at the function level. Source 142 1.1 skrll lines are identified by symbols of the form: 143 1.1 skrll 144 1.1 skrll func (file:line) 145 1.1 skrll 146 1.1 skrll where "func" is the function name, "file" is the 147 1.1 skrll file name and "line" is the line-number that 148 1.1 skrll corresponds to the line. 149 1.1 skrll 150 1.1 skrll To work properly, the binary must contain symbolic 151 1.1 skrll debugging information. This means that the source 152 1.1 skrll have to be translated with option "-g" specified. 153 1.1 skrll Functions for which there is no symbolic debugging 154 1.1 skrll information available are treated as if "--line" 155 1.1 skrll had not been specified. However, the line number 156 1.1 skrll printed with such symbols is usually incorrect 157 1.1 skrll and should be ignored. 158 1.1 skrll 159 1.1 skrll -a --no-static 160 1.1 skrll -A[symspec] --annotated-source[=symspec] 161 1.1 skrll Request output in the form of annotated source 162 1.1 skrll files. If "symspec" is specified, print output only 163 1.1 skrll for symbols selected by "symspec". If the option 164 1.1 skrll is specified multiple times, annotated output is 165 1.1 skrll generated for the union of all symspecs. 166 1.1 skrll 167 1.1 skrll Examples: 168 1.1 skrll 169 1.1 skrll -A Prints annotated source for all 170 1.1 skrll source files. 171 1.1 skrll -Agprof.c Prints annotated source for file 172 1.1 skrll gprof.c. 173 1.1 skrll -Afoobar Prints annotated source for files 174 1.1 skrll containing a function named "foobar". 175 1.1 skrll The entire file will be printed, but 176 1.1 skrll only the function itself will be 177 1.1 skrll annotated with profile data. 178 1.1 skrll 179 1.1 skrll -J[symspec] --no-annotated-source[=symspec] 180 1.1 skrll Suppress annotated source output. If specified 181 1.1 skrll without argument, annotated output is suppressed 182 1.1 skrll completely. With an argument, annotated output 183 1.1 skrll is suppressed only for the symbols selected by 184 1.1 skrll "symspec". If the option is specified multiple 185 1.1 skrll times, annotated output is suppressed for the 186 1.1 skrll union of all symspecs. This option has lower 187 1.1 skrll precedence than --annotated-source 188 1.1 skrll 189 1.1 skrll -p[symspec] --flat-profile[=symspec] 190 1.1 skrll Request output in the form of a flat profile 191 1.1 skrll (unless any other output-style option is specified, 192 1.1 skrll this option is turned on by default). If 193 1.1 skrll "symspec" is specified, include only symbols 194 1.1 skrll selected by "symspec" in flat profile. If the 195 1.1 skrll option is specified multiple times, the flat 196 1.1 skrll profile includes symbols selected by the union 197 1.1 skrll of all symspecs. 198 1.1.1.2 christos 199 1.1 skrll -P[symspec] --no-flat-profile[=symspec] 200 1.1 skrll Suppress output in the flat profile. If given 201 1.1 skrll without an argument, the flat profile is suppressed 202 1.1 skrll completely. If "symspec" is specified, suppress 203 1.1 skrll the selected symbols in the flat profile. If the 204 1.1 skrll option is specified multiple times, the union of 205 1.1 skrll the selected symbols is suppressed. This option 206 1.1 skrll has lower precedence than --flat-profile. 207 1.1 skrll 208 1.1 skrll -q[symspec] --graph[=symspec] 209 1.1 skrll Request output in the form of a call-graph 210 1.1 skrll (unless any other output-style option is specified, 211 1.1 skrll this option is turned on by default). If "symspec" 212 1.1 skrll is specified, include only symbols selected by 213 1.1 skrll "symspec" in the call-graph. If the option is 214 1.1 skrll specified multiple times, the call-graph includes 215 1.1 skrll symbols selected by the union of all symspecs. 216 1.1 skrll 217 1.1 skrll -Q[symspec] --no-graph[=symspec] 218 1.1 skrll Suppress output in the call-graph. If given without 219 1.1 skrll an argument, the call-graph is suppressed completely. 220 1.1 skrll With a "symspec", suppress the selected symbols 221 1.1 skrll from the call-graph. If the option is specified 222 1.1 skrll multiple times, the union of the selected symbols 223 1.1 skrll is suppressed. This option has lower precedence 224 1.1 skrll than --graph. 225 1.1 skrll 226 1.1 skrll -C[symspec] --exec-counts[=symspec] 227 1.1 skrll Request output in the form of execution counts. 228 1.1 skrll If "symspec" is present, include only symbols 229 1.1 skrll selected by "symspec" in the execution count 230 1.1 skrll listing. If the option is specified multiple 231 1.1 skrll times, the execution count listing includes 232 1.1 skrll symbols selected by the union of all symspecs. 233 1.1 skrll 234 1.1 skrll -Z[symspec] --no-exec-counts[=symspec] 235 1.1 skrll Suppress output in the execution count listing. 236 1.1 skrll If given without an argument, the listing is 237 1.1 skrll suppressed completely. With a "symspec", suppress 238 1.1 skrll the selected symbols from the call-graph. If the 239 1.1 skrll option is specified multiple times, the union of 240 1.1 skrll the selected symbols is suppressed. This option 241 1.1 skrll has lower precedence than --exec-counts. 242 1.1 skrll 243 1.1 skrll -i --file-info 244 1.1 skrll Print information about the profile files that 245 1.1 skrll are read. The information consists of the 246 1.1 skrll number and types of records present in the 247 1.1 skrll profile file. Currently, a profile file can 248 1.1 skrll contain any number and any combination of histogram, 249 1.1 skrll call-graph, or basic-block count records. 250 1.1 skrll 251 1.1 skrll -s --sum 252 1.1 skrll 253 1.1 skrll -x --all-lines 254 1.1 skrll This option affects annotated source output only. 255 1.1 skrll By default, only the lines at the beginning of 256 1.1 skrll a basic-block are annotated. If this option is 257 1.1 skrll specified, every line in a basic-block is annotated 258 1.1 skrll by repeating the annotation for the first line. 259 1.1 skrll This option is identical to tcov's "-a". 260 1.1 skrll 261 1.1 skrll -I dirs --directory-path=dirs 262 1.1 skrll This option affects annotated source output only. 263 1.1 skrll Specifies the list of directories to be searched 264 1.1 skrll for source files. The argument "dirs" is a colon 265 1.1 skrll separated list of directories. By default, gprof 266 1.1 skrll searches for source files relative to the current 267 1.1 skrll working directory only. 268 1.1 skrll 269 1.1 skrll -z --display-unused-functions 270 1.1 skrll 271 1.1 skrll -m num --min-count=num 272 1.1 skrll This option affects annotated source and execution 273 1.1 skrll count output only. Symbols that are executed 274 1.1 skrll less than "num" times are suppressed. For annotated 275 1.1 skrll source output, suppressed symbols are marked 276 1.1 skrll by five hash-marks (#####). In an execution count 277 1.1 skrll output, suppressed symbols do not appear at all. 278 1.1 skrll 279 1.1 skrll -L --print-path 280 1.1 skrll Normally, source filenames are printed with the path 281 1.1 skrll component suppressed. With this option, gprof 282 1.1 skrll can be forced to print the full pathname of 283 1.1 skrll source filenames. The full pathname is determined 284 1.1 skrll from symbolic debugging information in the image file 285 1.1 skrll and is relative to the directory in which the compiler 286 1.1 skrll was invoked. 287 1.1 skrll 288 1.1 skrll -y --separate-files 289 1.1 skrll This option affects annotated source output only. 290 1.1 skrll Normally, gprof prints annotated source files 291 1.1 skrll to standard-output. If this option is specified, 292 1.1 skrll annotated source for a file named "path/filename" 293 1.1 skrll is generated in the file "filename-ann". That is, 294 1.1 skrll annotated output is {\em always\/} generated in 295 1.1 skrll gprof's current working directory. Care has to 296 1.1 skrll be taken if a program consists of files that have 297 1.1 skrll identical filenames, but distinct paths. 298 1.1 skrll 299 1.1 skrll -c --static-call-graph 300 1.1 skrll 301 1.1 skrll -t num --table-length=num 302 1.1 skrll This option affects annotated source output only. 303 1.1 skrll After annotating a source file, gprof generates 304 1.1 skrll an execution count summary consisting of a table 305 1.1 skrll of lines with the top execution counts. By 306 1.1 skrll default, this table is ten entries long. 307 1.1 skrll This option can be used to change the table length 308 1.1 skrll or, by specifying an argument value of 0, it can be 309 1.1 skrll suppressed completely. 310 1.1 skrll 311 1.1 skrll -n symspec --time=symspec 312 1.1 skrll Only symbols selected by "symspec" are considered 313 1.1 skrll in total and percentage time computations. 314 1.1 skrll However, this option does not affect percentage time 315 1.1 skrll computation for the flat profile. 316 1.1 skrll If the option is specified multiple times, the union 317 1.1 skrll of all selected symbols is used in time computations. 318 1.1 skrll 319 1.1 skrll -N --no-time=symspec 320 1.1 skrll Exclude the symbols selected by "symspec" from 321 1.1 skrll total and percentage time computations. 322 1.1 skrll However, this option does not affect percentage time 323 1.1 skrll computation for the flat profile. 324 1.1 skrll This option is ignored if any --time options are 325 1.1 skrll specified. 326 1.1 skrll 327 1.1 skrll -w num --width=num 328 1.1 skrll Sets the output line width. Currently, this option 329 1.1 skrll affects the printing of the call-graph function index 330 1.1 skrll only. 331 1.1 skrll 332 1.1 skrll -e <no long form---for backwards compatibility only> 333 1.1 skrll -E <no long form---for backwards compatibility only> 334 1.1 skrll -f <no long form---for backwards compatibility only> 335 1.1 skrll -F <no long form---for backwards compatibility only> 336 1.1 skrll -k <no long form---for backwards compatibility only> 337 1.1 skrll -b --brief 338 1.1 skrll -dnum --debug[=num] 339 1.1 skrll 340 1.1 skrll -h --help 341 1.1 skrll Prints a usage message. 342 1.1 skrll 343 1.1 skrll -O name --file-format=name 344 1.1 skrll Selects the format of the profile data files. 345 1.1 skrll Recognized formats are "auto", "bsd", "magic", 346 1.1 skrll and "prof". The last one is not yet supported. 347 1.1 skrll Format "auto" attempts to detect the file format 348 1.1 skrll automatically (this is the default behavior). 349 1.1 skrll It attempts to read the profile data files as 350 1.1 skrll "magic" files and if this fails, falls back to 351 1.1 skrll the "bsd" format. "bsd" forces gprof to read 352 1.1 skrll the data files in the BSD format. "magic" forces 353 1.1 skrll gprof to read the data files in the "magic" format. 354 1.1 skrll 355 1.1 skrll -T --traditional 356 1.1 skrll -v --version 357 1.1 skrll 358 1.1 skrll ** File Format Changes 359 1.1 skrll 360 1.1 skrll The old BSD-derived format used for profile data does not contain a 361 1.1.1.6 christos magic cookie that allows one to check whether a data file really is a 362 1.1 skrll gprof file. Furthermore, it does not provide a version number, thus 363 1.1 skrll rendering changes to the file format almost impossible. GNU gprof 364 1.1 skrll uses a new file format that provides these features. For backward 365 1.1 skrll compatibility, GNU gprof continues to support the old BSD-derived 366 1.1 skrll format, but not all features are supported with it. For example, 367 1.1 skrll basic-block execution counts cannot be accommodated by the old file 368 1.1 skrll format. 369 1.1 skrll 370 1.1 skrll The new file format is defined in header file \file{gmon_out.h}. It 371 1.1 skrll consists of a header containing the magic cookie and a version number, 372 1.1 skrll as well as some spare bytes available for future extensions. All data 373 1.1 skrll in a profile data file is in the native format of the host on which 374 1.1 skrll the profile was collected. GNU gprof adapts automatically to the 375 1.1 skrll byte-order in use. 376 1.1 skrll 377 1.1 skrll In the new file format, the header is followed by a sequence of 378 1.1 skrll records. Currently, there are three different record types: histogram 379 1.1 skrll records, call-graph arc records, and basic-block execution count 380 1.1 skrll records. Each file can contain any number of each record type. When 381 1.1 skrll reading a file, GNU gprof will ensure records of the same type are 382 1.1 skrll compatible with each other and compute the union of all records. For 383 1.1 skrll example, for basic-block execution counts, the union is simply the sum 384 1.1 skrll of all execution counts for each basic-block. 385 1.1 skrll 386 1.1 skrll *** Histogram Records 387 1.1 skrll 388 1.1 skrll Histogram records consist of a header that is followed by an array of 389 1.1 skrll bins. The header contains the text-segment range that the histogram 390 1.1 skrll spans, the size of the histogram in bytes (unlike in the old BSD 391 1.1 skrll format, this does not include the size of the header), the rate of the 392 1.1 skrll profiling clock, and the physical dimension that the bin counts 393 1.1 skrll represent after being scaled by the profiling clock rate. The 394 1.1 skrll physical dimension is specified in two parts: a long name of up to 15 395 1.1 skrll characters and a single character abbreviation. For example, a 396 1.1 skrll histogram representing real-time would specify the long name as 397 1.1 skrll "seconds" and the abbreviation as "s". This feature is useful for 398 1.1 skrll architectures that support performance monitor hardware (which, 399 1.1 skrll fortunately, is becoming increasingly common). For example, under DEC 400 1.1 skrll OSF/1, the "uprofile" command can be used to produce a histogram of, 401 1.1 skrll say, instruction cache misses. In this case, the dimension in the 402 1.1 skrll histogram header could be set to "i-cache misses" and the abbreviation 403 1.1 skrll could be set to "1" (because it is simply a count, not a physical 404 1.1 skrll dimension). Also, the profiling rate would have to be set to 1 in 405 1.1 skrll this case. 406 1.1 skrll 407 1.1 skrll Histogram bins are 16-bit numbers and each bin represent an equal 408 1.1 skrll amount of text-space. For example, if the text-segment is one 409 1.1 skrll thousand bytes long and if there are ten bins in the histogram, each 410 1.1 skrll bin represents one hundred bytes. 411 1.1 skrll 412 1.1 skrll 413 1.1 skrll *** Call-Graph Records 414 1.1 skrll 415 1.1 skrll Call-graph records have a format that is identical to the one used in 416 1.1 skrll the BSD-derived file format. It consists of an arc in the call graph 417 1.1 skrll and a count indicating the number of times the arc was traversed 418 1.1 skrll during program execution. Arcs are specified by a pair of addresses: 419 1.1 skrll the first must be within caller's function and the second must be 420 1.1 skrll within the callee's function. When performing profiling at the 421 1.1 skrll function level, these addresses can point anywhere within the 422 1.1 skrll respective function. However, when profiling at the line-level, it is 423 1.1 skrll better if the addresses are as close to the call-site/entry-point as 424 1.1 skrll possible. This will ensure that the line-level call-graph is able to 425 1.1 skrll identify exactly which line of source code performed calls to a 426 1.1 skrll function. 427 1.1 skrll 428 1.1 skrll *** Basic-Block Execution Count Records 429 1.1 skrll 430 1.1 skrll Basic-block execution count records consist of a header followed by a 431 1.1 skrll sequence of address/count pairs. The header simply specifies the 432 1.1 skrll length of the sequence. In an address/count pair, the address 433 1.1 skrll identifies a basic-block and the count specifies the number of times 434 1.1 skrll that basic-block was executed. Any address within the basic-address can 435 1.1 skrll be used. 436 1.1 skrll 437 1.1 skrll IMPLEMENTATION NOTE: gcc -a can be used to instrument a program to 438 1.1 skrll record basic-block execution counts. However, the __bb_exit_func() 439 1.1 skrll that is currently present in libgcc2.c does not generate a gmon.out 440 1.1 skrll file in a suitable format. This should be fixed for future releases 441 1.1 skrll of gcc. In the meantime, contact davidm (a] cs.arizona.edu for a version 442 1.1 skrll of __bb_exit_func() to is appropriate. 443 1.1.1.2 christos 445 1.1.1.2 christos Copyright (C) 2012-2026 Free Software Foundation, Inc. 446 1.1.1.2 christos 447 1.1.1.2 christos Copying and distribution of this file, with or without modification, 448 1.1.1.2 christos are permitted in any medium without royalty provided the copyright 449 notice and this notice are preserved. 450