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