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