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