Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / gprof / gprof.1
1 .\" Copyright (c) 1983, 1990, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)gprof.1     8.1 (Berkeley) 6/6/93
33 .\" $FreeBSD: src/usr.bin/gprof/gprof.1,v 1.12.2.8 2003/02/25 20:00:47 trhodes Exp $
34 .\" $DragonFly: src/usr.bin/gprof/gprof.1,v 1.2 2003/06/17 04:29:27 dillon Exp $
35 .\"
36 .Dd June 6, 1993
37 .Dt GPROF 1
38 .Os
39 .Sh NAME
40 .Nm gprof
41 .Nd display call graph profile data
42 .Sh SYNOPSIS
43 .Nm
44 .Op options
45 .Op Ar a.out Op Ar a.out.gmon ...
46 .Sh DESCRIPTION
47 The
48 .Nm
49 utility produces an execution profile of C, Pascal, or Fortran77 programs.
50 The effect of called routines is incorporated in the profile of each caller.
51 The profile data is taken from the call graph profile file
52 which is created by programs that are compiled with the
53 .Fl pg
54 option of
55 .Xr cc 1 ,
56 .Xr pc 1 ,
57 and
58 .Xr f77 1 .
59 The
60 .Fl pg
61 option also links in versions of the library routines
62 that are compiled for profiling.
63 By convention these libraries have their name suffixed with
64 .Pa _p ,
65 i.e. the profiled version of
66 .Pa libc.a
67 is
68 .Pa libc_p.a
69 and if you specify libraries directly to the
70 compiler or linker you can use
71 .Fl l Ns Ar c_p
72 instead of
73 .Fl l Ns Ar c .
74 Read the given object file (the default is
75 .Pa a.out)
76 and establishes the relation between its symbol table
77 and the call graph profile.
78 The default graph profile file name is the name
79 of the executable with the suffix
80 .Pa .gmon
81 appended.
82 If more than one profile file is specified,
83 the
84 .Nm
85 output shows the sum of the profile information in the given profile files.
86 .Pp
87 The
88 .Nm
89 utility calculates the amount of time spent in each routine.
90 Next, these times are propagated along the edges of the call graph.
91 Cycles are discovered, and calls into a cycle are made to share the time
92 of the cycle.
93 The first listing shows the functions
94 sorted according to the time they represent
95 including the time of their call graph descendants.
96 Below each function entry is shown its (direct) call graph children,
97 and how their times are propagated to this function.
98 A similar display above the function shows how this function's time and the
99 time of its descendants is propagated to its (direct) call graph parents.
100 .Pp
101 Cycles are also shown, with an entry for the cycle as a whole and
102 a listing of the members of the cycle and their contributions to the
103 time and call counts of the cycle.
104 .Pp
105 Second, a flat profile is given,
106 similar to that provided by
107 .Xr prof  1  .
108 This listing gives the total execution times, the call counts,
109 the time in msec or usec the call spent in the routine itself, and
110 the time in msec or usec the call spent in the routine itself including
111 its descendants.
112 .Pp
113 Finally, an index of the function names is provided.
114 .Pp
115 The following options are available:
116 .Bl -tag -width indent
117 .It Fl a
118 Suppress the printing of statically declared functions.
119 If this option is given, all relevant information about the static function
120 (e.g., time samples, calls to other functions, calls from other functions)
121 belongs to the function loaded just before the static function in the
122 .Pa a.out
123 file.
124 .It Fl b
125 Suppress the printing of a description of each field in the profile.
126 .It Fl c
127 The static call graph of the program is discovered by a heuristic
128 that examines the text space of the object file.
129 Static-only parents or children are shown
130 with call counts of 0.
131 This option is not supported on some architectures.
132 .It Fl C Ar count
133 Find a minimal set of arcs that can be broken to eliminate all cycles with
134 .Ar count
135 or more members.
136 Caution: the algorithm used to break cycles is exponential,
137 so using this option may cause
138 .Nm
139 to run for a very long time.
140 .It Fl e Ar name
141 Suppress the printing of the graph profile entry for routine
142 .Ar name
143 and all its descendants
144 (unless they have other ancestors that aren't suppressed).
145 More than one
146 .Fl e
147 option may be given.
148 Only one
149 .Ar name
150 may be given with each
151 .Fl e
152 option.
153 .It Fl E Ar name
154 Suppress the printing of the graph profile entry for routine
155 .Ar name
156 (and its descendants) as
157 .Fl e  ,
158 above, and also excludes the time spent in
159 .Ar name
160 (and its descendants) from the total and percentage time computations.
161 (For example,
162 .Fl E
163 .Ar mcount
164 .Fl E
165 .Ar mcleanup
166 is the default.)
167 .It Fl f Ar name
168 Print the graph profile entry of only the specified routine
169 .Ar name
170 and its descendants.
171 More than one
172 .Fl f
173 option may be given.
174 Only one
175 .Ar name
176 may be given with each
177 .Fl f
178 option.
179 .It Fl F Ar name
180 Print the graph profile entry of only the routine
181 .Ar name
182 and its descendants (as
183 .Fl f ,
184 above) and also uses only the times of the printed routines
185 in total time and percentage computations.
186 More than one
187 .Fl F
188 option may be given.
189 Only one
190 .Ar name
191 may be given with each
192 .Fl F
193 option.
194 The
195 .Fl F
196 option
197 overrides
198 the
199 .Fl E
200 option.
201 .It Fl k Ar fromname Ar toname
202 Will delete any arcs from routine
203 .Ar fromname
204 to routine
205 .Ar toname .
206 This can be used to break undesired cycles.
207 More than one
208 .Fl k
209 option may be given.
210 Only one pair of routine names may be given with each
211 .Fl k
212 option.
213 .It Fl l
214 Suppress the printing of the call-graph profile.
215 .It Fl L
216 Suppress the printing of the flat profile.
217 .It Fl s
218 A profile file
219 .Pa gmon.sum
220 is produced that represents
221 the sum of the profile information in all the specified profile files.
222 This summary profile file may be given to later
223 executions of gprof (probably also with a
224 .Fl s )
225 to accumulate profile data across several runs of an
226 .Pa a.out
227 file.
228 .It Fl u
229 Suppress the printing of functions whose names are not visible to
230 C programs.  For the ELF object format, this means names that
231 contain the
232 .Ql .\&
233 character.  For the a.out object format, it means names that do not
234 begin with a
235 .Ql _
236 character.
237 All relevant information about such functions belongs to the
238 (non-suppressed) function with the next lowest address.
239 This is useful for eliminating "functions" that are just labels
240 inside other functions.
241 .It Fl z
242 Display routines that have zero usage (as shown by call counts
243 and accumulated time).
244 This is useful with the
245 .Fl c
246 option for discovering which routines were never called.
247 .El
248 .Sh FILES
249 .Bl -tag -width a.out.gmon -compact
250 .It Pa a.out
251 The namelist and text space.
252 .It Pa a.out.gmon
253 Dynamic call graph and profile.
254 .It Pa gmon.sum
255 Summarized dynamic call graph and profile.
256 .El
257 .Sh SEE ALSO
258 .Xr cc 1 ,
259 .Xr profil 2 ,
260 .Xr clocks 7
261 .\" .Xr monitor 3 ,
262 .\" .Xr prof 1
263 .Rs
264 .%T "An Execution Profiler for Modular Programs"
265 .%A S. Graham
266 .%A P. Kessler
267 .%A M. McKusick
268 .%J "Software - Practice and Experience"
269 .%V 13
270 .%P pp. 671-685
271 .%D 1983
272 .Re
273 .Rs
274 .%T "gprof: A Call Graph Execution Profiler"
275 .%A S. Graham
276 .%A P. Kessler
277 .%A M. McKusick
278 .%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices"
279 .%V 17
280 .%N 6
281 .%P pp. 120-126
282 .%D June 1982
283 .Re
284 .Sh HISTORY
285 The
286 .Nm
287 profiler
288 appeared in
289 .Bx 4.2 .
290 .Sh BUGS
291 The granularity of the sampling is shown, but remains
292 statistical at best.
293 We assume that the time for each execution of a function
294 can be expressed by the total time for the function divided
295 by the number of times the function is called.
296 Thus the time propagated along the call graph arcs to the function's
297 parents is directly proportional to the number of times that
298 arc is traversed.
299 .Pp
300 Parents that are not themselves profiled will have the time of
301 their profiled children propagated to them, but they will appear
302 to be spontaneously invoked in the call graph listing, and will
303 not have their time propagated further.
304 Similarly, signal catchers, even though profiled, will appear
305 to be spontaneous (although for more obscure reasons).
306 Any profiled children of signal catchers should have their times
307 propagated properly, unless the signal catcher was invoked during
308 the execution of the profiling routine, in which case all is lost.
309 .Pp
310 The profiled program must call
311 .Xr exit  3
312 or return normally for the profiling information to be saved
313 in the graph profile file.