xref: /freebsd/usr.bin/gprof/gprof.1 (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"	@(#)gprof.1	8.1 (Berkeley) 6/6/93
29.\" $FreeBSD$
30.\"
31.Dd November 27, 2017
32.Dt GPROF 1
33.Os
34.Sh NAME
35.Nm gprof
36.Nd display call graph profile data
37.Sh SYNOPSIS
38.Nm
39.Op Fl abKlLsuz
40.Op Fl C Ar count
41.Op Fl e Ar name
42.Op Fl E Ar name
43.Op Fl f Ar name
44.Op Fl F Ar name
45.Op Fl k Ar fromname toname
46.Op Ar a.out Op Ar a.out.gmon ...
47.Sh DESCRIPTION
48The
49.Nm
50utility produces an execution profile of C, Pascal, or Fortran77 programs.
51The effect of called routines is incorporated in the profile of each caller.
52The profile data is taken from the call graph profile file
53which is created by programs that are compiled with the
54.Fl pg
55option of
56.Xr cc 1 ,
57.Xr pc 1 ,
58and
59.Xr f77 1 .
60The
61.Fl pg
62option also links in versions of the library routines
63that are compiled for profiling.
64By convention these libraries have their name suffixed with
65.Pa _p ,
66i.e., the profiled version of
67.Pa libc.a
68is
69.Pa libc_p.a
70and if you specify libraries directly to the
71compiler or linker you can use
72.Fl l Ns Ar c_p
73instead of
74.Fl l Ns Ar c .
75Read the given object file (the default is
76.Pa a.out )
77and establishes the relation between its symbol table
78and the call graph profile.
79The default graph profile file name is the name
80of the executable with the suffix
81.Pa .gmon
82appended.
83If more than one profile file is specified,
84the
85.Nm
86output shows the sum of the profile information in the given profile files.
87.Pp
88The
89.Nm
90utility calculates the amount of time spent in each routine.
91Next, these times are propagated along the edges of the call graph.
92Cycles are discovered, and calls into a cycle are made to share the time
93of the cycle.
94The first listing shows the functions
95sorted according to the time they represent
96including the time of their call graph descendants.
97Below each function entry is shown its (direct) call graph children,
98and how their times are propagated to this function.
99A similar display above the function shows how this function's time and the
100time of its descendants is propagated to its (direct) call graph parents.
101.Pp
102Cycles are also shown, with an entry for the cycle as a whole and
103a listing of the members of the cycle and their contributions to the
104time and call counts of the cycle.
105.Pp
106Second, a flat profile is given,
107similar to that provided by
108.Xr prof 1 .
109This listing gives the total execution times, the call counts,
110the time that the call spent in the routine itself, and
111the time that the call spent in the routine itself including
112its descendants.
113The units for the per-call times are normally milliseconds,
114but they are nanoseconds if the profiling clock frequency
115is 10 million or larger,
116and if a function appears to be never called then its total self time
117is printed as a percentage in the self time per call column.
118The very high profiling clock frequencies needed to get sufficient
119accuracy in the per-call times for short-lived programs are only
120implemented for
121.Dq high resolution
122(non-statistical) kernel profiling.
123.Pp
124Finally, an index of the function names is provided.
125.Pp
126The following options are available:
127.Bl -tag -width indent
128.It Fl a
129Suppress the printing of statically declared functions.
130If this option is given, all relevant information about the static function
131(e.g., time samples, calls to other functions, calls from other functions)
132belongs to the function loaded just before the static function in the
133.Pa a.out
134file.
135.It Fl b
136Suppress the printing of a description of each field in the profile.
137.It Fl C Ar count
138Find a minimal set of arcs that can be broken to eliminate all cycles with
139.Ar count
140or more members.
141Caution: the algorithm used to break cycles is exponential,
142so using this option may cause
143.Nm
144to run for a very long time.
145.It Fl e Ar name
146Suppress the printing of the graph profile entry for routine
147.Ar name
148and all its descendants
149(unless they have other ancestors that are not suppressed).
150More than one
151.Fl e
152option may be given.
153Only one
154.Ar name
155may be given with each
156.Fl e
157option.
158.It Fl E Ar name
159Suppress the printing of the graph profile entry for routine
160.Ar name
161(and its descendants) as
162.Fl e ,
163above, 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
171is the default.)
172.It Fl f Ar name
173Print the graph profile entry of only the specified routine
174.Ar name
175and its descendants.
176More than one
177.Fl f
178option may be given.
179Only one
180.Ar name
181may be given with each
182.Fl f
183option.
184.It Fl F Ar name
185Print the graph profile entry of only the routine
186.Ar name
187and its descendants (as
188.Fl f ,
189above) and also uses only the times of the printed routines
190in total time and percentage computations.
191More than one
192.Fl F
193option may be given.
194Only one
195.Ar name
196may be given with each
197.Fl F
198option.
199The
200.Fl F
201option
202overrides
203the
204.Fl E
205option.
206.It Fl k Ar fromname Ar toname
207Will delete any arcs from routine
208.Ar fromname
209to routine
210.Ar toname .
211This can be used to break undesired cycles.
212More than one
213.Fl k
214option may be given.
215Only one pair of routine names may be given with each
216.Fl k
217option.
218.It Fl K
219Gather information about symbols from the currently-running kernel using the
220.Xr sysctl 3
221and
222.Xr kldsym 2
223interfaces.
224This forces the
225.Pa a.out
226argument to be ignored, and allows for symbols in
227.Xr kld 4
228modules to be used.
229.It Fl l
230Suppress the printing of the call-graph profile.
231.It Fl L
232Suppress the printing of the flat profile.
233.It Fl s
234A profile file
235.Pa gmon.sum
236is produced that represents
237the sum of the profile information in all the specified profile files.
238This summary profile file may be given to later
239executions of gprof (probably also with a
240.Fl s )
241to accumulate profile data across several runs of an
242.Pa a.out
243file.
244.It Fl u
245Suppress the printing of functions whose names are not visible to
246C programs.
247For the ELF object format, this means names that
248contain the
249.Ql .\&
250character.
251For the a.out object format, it means names that do not
252begin with a
253.Ql _
254character.
255All relevant information about such functions belongs to the
256(non-suppressed) function with the next lowest address.
257This is useful for eliminating "functions" that are just labels
258inside other functions.
259.It Fl z
260Display routines that have zero usage (as shown by call counts
261and accumulated time).
262.El
263.Sh FILES
264.Bl -tag -width a.out.gmon -compact
265.It Pa a.out
266The namelist and text space.
267.It Pa a.out.gmon
268Dynamic call graph and profile.
269.It Pa gmon.sum
270Summarized dynamic call graph and profile.
271.El
272.Sh SEE ALSO
273.Xr cc 1 ,
274.Xr profil 2 ,
275.Xr clocks 7 ,
276.Xr pmcstat 8
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
301The
302.Nm
303profiler
304appeared in
305.Bx 4.2 .
306.Sh BUGS
307The granularity of the sampling is shown, but remains
308statistical at best.
309We assume that the time for each execution of a function
310can be expressed by the total time for the function divided
311by the number of times the function is called.
312Thus the time propagated along the call graph arcs to the function's
313parents is directly proportional to the number of times that
314arc is traversed.
315.Pp
316Parents that are not themselves profiled will have the time of
317their profiled children propagated to them, but they will appear
318to be spontaneously invoked in the call graph listing, and will
319not have their time propagated further.
320Similarly, signal catchers, even though profiled, will appear
321to be spontaneous (although for more obscure reasons).
322Any profiled children of signal catchers should have their times
323propagated properly, unless the signal catcher was invoked during
324the execution of the profiling routine, in which case all is lost.
325.Pp
326The profiled program must call
327.Xr exit 3
328or return normally for the profiling information to be saved
329in the graph profile file.
330