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