Initial import from FreeBSD RELENG_4:
[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 .\"
35 .Dd June 6, 1993
36 .Dt GPROF 1
37 .Os
38 .Sh NAME
39 .Nm gprof
40 .Nd display call graph profile data
41 .Sh SYNOPSIS
42 .Nm
43 .Op options
44 .Op Ar a.out Op Ar a.out.gmon ...
45 .Sh DESCRIPTION
46 The
47 .Nm
48 utility produces an execution profile of C, Pascal, or Fortran77 programs.
49 The effect of called routines is incorporated in the profile of each caller.
50 The profile data is taken from the call graph profile file
51 which is created by programs that are compiled with the
52 .Fl pg
53 option of
54 .Xr cc 1 ,
55 .Xr pc 1 ,
56 and
57 .Xr f77 1 .
58 The
59 .Fl pg
60 option also links in versions of the library routines
61 that are compiled for profiling.
62 By convention these libraries have their name suffixed with
63 .Pa _p ,
64 i.e. the profiled version of
65 .Pa libc.a
66 is
67 .Pa libc_p.a
68 and if you specify libraries directly to the
69 compiler or linker you can use
70 .Fl l Ns Ar c_p
71 instead of
72 .Fl l Ns Ar c .
73 Read the given object file (the default is
74 .Pa a.out)
75 and establishes the relation between its symbol table
76 and the call graph profile.
77 The default graph profile file name is the name
78 of the executable with the suffix
79 .Pa .gmon
80 appended.
81 If more than one profile file is specified,
82 the
83 .Nm
84 output shows the sum of the profile information in the given profile files.
85 .Pp
86 The
87 .Nm
88 utility calculates the amount of time spent in each routine.
89 Next, these times are propagated along the edges of the call graph.
90 Cycles are discovered, and calls into a cycle are made to share the time
91 of the cycle.
92 The first listing shows the functions
93 sorted according to the time they represent
94 including the time of their call graph descendants.
95 Below each function entry is shown its (direct) call graph children,
96 and how their times are propagated to this function.
97 A similar display above the function shows how this function's time and the
98 time of its descendants is propagated to its (direct) call graph parents.
99 .Pp
100 Cycles are also shown, with an entry for the cycle as a whole and
101 a listing of the members of the cycle and their contributions to the
102 time and call counts of the cycle.
103 .Pp
104 Second, a flat profile is given,
105 similar to that provided by
106 .Xr prof  1  .
107 This listing gives the total execution times, the call counts,
108 the time in msec or usec the call spent in the routine itself, and
109 the time in msec or usec the call spent in the routine itself including
110 its descendants.
111 .Pp
112 Finally, an index of the function names is provided.
113 .Pp
114 The following options are available:
115 .Bl -tag -width indent
116 .It Fl a
117 Suppress the printing of statically declared functions.
118 If this option is given, all relevant information about the static function
119 (e.g., time samples, calls to other functions, calls from other functions)
120 belongs to the function loaded just before the static function in the
121 .Pa a.out
122 file.
123 .It Fl b
124 Suppress the printing of a description of each field in the profile.
125 .It Fl c
126 The static call graph of the program is discovered by a heuristic
127 that examines the text space of the object file.
128 Static-only parents or children are shown
129 with call counts of 0.
130 This option is not supported on some architectures.
131 .It Fl C Ar count
132 Find a minimal set of arcs that can be broken to eliminate all cycles with
133 .Ar count
134 or more members.
135 Caution: the algorithm used to break cycles is exponential,
136 so using this option may cause
137 .Nm
138 to run for a very long time.
139 .It Fl e Ar name
140 Suppress the printing of the graph profile entry for routine
141 .Ar name
142 and all its descendants
143 (unless they have other ancestors that aren't suppressed).
144 More than one
145 .Fl e
146 option may be given.
147 Only one
148 .Ar name
149 may be given with each
150 .Fl e
151 option.
152 .It Fl E Ar name
153 Suppress the printing of the graph profile entry for routine
154 .Ar name
155 (and its descendants) as
156 .Fl e  ,
157 above, and also excludes the time spent in
158 .Ar name
159 (and its descendants) from the total and percentage time computations.
160 (For example,
161 .Fl E
162 .Ar mcount
163 .Fl E
164 .Ar mcleanup
165 is the default.)
166 .It Fl f Ar name
167 Print the graph profile entry of only the specified routine
168 .Ar name
169 and its descendants.
170 More than one
171 .Fl f
172 option may be given.
173 Only one
174 .Ar name
175 may be given with each
176 .Fl f
177 option.
178 .It Fl F Ar name
179 Print the graph profile entry of only the routine
180 .Ar name
181 and its descendants (as
182 .Fl f ,
183 above) and also uses only the times of the printed routines
184 in total time and percentage computations.
185 More than one
186 .Fl F
187 option may be given.
188 Only one
189 .Ar name
190 may be given with each
191 .Fl F
192 option.
193 The
194 .Fl F
195 option
196 overrides
197 the
198 .Fl E
199 option.
200 .It Fl k Ar fromname Ar toname
201 Will delete any arcs from routine
202 .Ar fromname
203 to routine
204 .Ar toname .
205 This can be used to break undesired cycles.
206 More than one
207 .Fl k
208 option may be given.
209 Only one pair of routine names may be given with each
210 .Fl k
211 option.
212 .It Fl l
213 Suppress the printing of the call-graph profile.
214 .It Fl L
215 Suppress the printing of the flat profile.
216 .It Fl s
217 A profile file
218 .Pa gmon.sum
219 is produced that represents
220 the sum of the profile information in all the specified profile files.
221 This summary profile file may be given to later
222 executions of gprof (probably also with a
223 .Fl s )
224 to accumulate profile data across several runs of an
225 .Pa a.out
226 file.
227 .It Fl u
228 Suppress the printing of functions whose names are not visible to
229 C programs.  For the ELF object format, this means names that
230 contain the
231 .Ql .\&
232 character.  For the a.out object format, it means names that do not
233 begin with a
234 .Ql _
235 character.
236 All relevant information about such functions belongs to the
237 (non-suppressed) function with the next lowest address.
238 This is useful for eliminating "functions" that are just labels
239 inside other functions.
240 .It Fl z
241 Display routines that have zero usage (as shown by call counts
242 and accumulated time).
243 This is useful with the
244 .Fl c
245 option for discovering which routines were never called.
246 .El
247 .Sh FILES
248 .Bl -tag -width a.out.gmon -compact
249 .It Pa a.out
250 The namelist and text space.
251 .It Pa a.out.gmon
252 Dynamic call graph and profile.
253 .It Pa gmon.sum
254 Summarized dynamic call graph and profile.
255 .El
256 .Sh SEE ALSO
257 .Xr cc 1 ,
258 .Xr profil 2 ,
259 .Xr clocks 7
260 .\" .Xr monitor 3 ,
261 .\" .Xr prof 1
262 .Rs
263 .%T "An Execution Profiler for Modular Programs"
264 .%A S. Graham
265 .%A P. Kessler
266 .%A M. McKusick
267 .%J "Software - Practice and Experience"
268 .%V 13
269 .%P pp. 671-685
270 .%D 1983
271 .Re
272 .Rs
273 .%T "gprof: A Call Graph Execution Profiler"
274 .%A S. Graham
275 .%A P. Kessler
276 .%A M. McKusick
277 .%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices"
278 .%V 17
279 .%N 6
280 .%P pp. 120-126
281 .%D June 1982
282 .Re
283 .Sh HISTORY
284 The
285 .Nm
286 profiler
287 appeared in
288 .Bx 4.2 .
289 .Sh BUGS
290 The granularity of the sampling is shown, but remains
291 statistical at best.
292 We assume that the time for each execution of a function
293 can be expressed by the total time for the function divided
294 by the number of times the function is called.
295 Thus the time propagated along the call graph arcs to the function's
296 parents is directly proportional to the number of times that
297 arc is traversed.
298 .Pp
299 Parents that are not themselves profiled will have the time of
300 their profiled children propagated to them, but they will appear
301 to be spontaneously invoked in the call graph listing, and will
302 not have their time propagated further.
303 Similarly, signal catchers, even though profiled, will appear
304 to be spontaneous (although for more obscure reasons).
305 Any profiled children of signal catchers should have their times
306 propagated properly, unless the signal catcher was invoked during
307 the execution of the profiling routine, in which case all is lost.
308 .Pp
309 The profiled program must call
310 .Xr exit  3
311 or return normally for the profiling information to be saved
312 in the graph profile file.