xref: /openbsd/usr.bin/gprof/gprof.1 (revision 7b36286a)
1.\"	$OpenBSD: gprof.1,v 1.20 2007/05/31 19:20:10 jmc Exp $
2.\"	$NetBSD: gprof.1,v 1.6 1995/11/21 22:24:55 jtc Exp $
3.\"
4.\" Copyright (c) 1983, 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"	@(#)gprof.1	8.1 (Berkeley) 6/6/93
32.\"
33.Dd $Mdocdate: May 31 2007 $
34.Dt GPROF 1
35.Os
36.Sh NAME
37.Nm gprof
38.Nd display call graph profile data
39.Sh SYNOPSIS
40.Nm gprof
41.Bk -words
42.Op Fl abcsz
43.Op Fl C Ar count
44.Op Fl E Ar name
45.Op Fl e Ar name
46.Op Fl F Ar name
47.Op Fl f Ar name
48.Op Fl k Ar from-name to-name
49.Op Ar a.out Op Ar gmon.out ...
50.Ek
51.Sh DESCRIPTION
52.Nm
53produces an execution profile of C, Pascal, or Fortran77 programs.
54The effect of called routines is incorporated in the profile of each caller.
55The profile data is taken from the call graph profile file
56.Pf ( Pa gmon.out
57default) which is created by programs
58that are compiled with the
59.Fl pg
60option of
61.Xr cc 1 ,
62.Xr pc ,
63and
64.Xr f77 1 .
65The
66.Fl pg
67option also links in versions of the library routines
68that are compiled for profiling.
69.Nm
70reads the given object file (the default is
71.Pa a.out )
72and establishes the relation between its symbol table
73and the call graph profile from
74.Pa gmon.out .
75If more than one profile file is specified,
76the
77.Nm
78output shows the sum of the profile information in the given profile files.
79.Pp
80.Nm
81calculates the amount of time spent in each routine.
82Next, these times are propagated along the edges of the call graph.
83Cycles are discovered, and calls into a cycle are made to share the time
84of the cycle.
85The first listing shows the functions
86sorted according to the time they represent
87including the time of their call graph descendents.
88Below each function entry is shown its (direct) call graph children,
89and how their times are propagated to this function.
90A similar display above the function shows how this function's time and the
91time of its descendents is propagated to its (direct) call graph parents.
92.Pp
93Cycles are also shown, with an entry for the cycle as a whole and
94a listing of the members of the cycle and their contributions to the
95time and call counts of the cycle.
96.Pp
97Second, a flat profile is given,
98similar to that provided by
99.Xr prof .
100This listing gives the total execution times, the call counts,
101the time in milliseconds the call spent in the routine itself, and
102the time in milliseconds the call spent in the routine itself including
103its descendents.
104.Pp
105Finally, an index of the function names is provided.
106.Pp
107The options are as follows:
108.Bl -tag -width Ds
109.It Fl a
110Suppresses the printing of statically declared functions.
111If this option is given, all relevant information about the static function
112(e.g., time samples, calls to other functions, calls from other functions)
113belongs to the function loaded just before the static function in the
114.Pa a.out
115file.
116.It Fl b
117Suppresses the printing of a description of each field in the profile.
118.It Fl C Ar count
119Find a minimal set of arcs that can be broken to eliminate all cycles with
120.Ar count
121or more members.
122Caution: the algorithm used to break cycles is exponential,
123so using this option may cause
124.Nm
125to run for a very long time.
126.It Fl c
127The static call graph of the program is discovered by a heuristic
128that examines the text space of the object file.
129Static-only parents or children are shown
130with call counts of 0.
131.It Fl E Ar name
132Suppresses the printing of the graph profile entry for routine
133.Ar name
134(and its descendants) as
135.Fl e ,
136above, and also excludes the time spent in
137.Ar name
138(and its descendants) from the total and percentage time computations.
139(For example,
140.Fl E
141.Ar mcount
142.Fl E
143.Ar mcleanup
144is the default.)
145.It Fl e Ar name
146Suppresses the printing of the graph profile entry for routine
147.Ar name
148and all its descendants
149(unless they have other ancestors that aren't 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 F Ar name
159Prints the graph profile entry of only the routine
160.Ar name
161and its descendants (as
162.Fl f ,
163above) and also uses only the times of the printed routines
164in total time and percentage computations.
165More than one
166.Fl F
167option may be given.
168Only one
169.Ar name
170may be given with each
171.Fl F
172option.
173The
174.Fl F
175option
176overrides
177the
178.Fl E
179option.
180.It Fl f Ar name
181Prints the graph profile entry of only the specified routine
182.Ar name
183and its descendants.
184More than one
185.Fl f
186option may be given.
187Only one
188.Ar name
189may be given with each
190.Fl f
191option.
192.It Fl k Ar from-name Ar to-name
193Will delete any arcs from routine
194.Ar from-name
195to routine
196.Ar to-name .
197This can be used to break undesired cycles.
198More than one
199.Fl k
200option may be given.
201Only one pair of routine names may be given with each
202.Fl k
203option.
204.It Fl s
205A profile file
206.Pa gmon.sum
207is produced that represents
208the sum of the profile information in all the specified profile files.
209This summary profile file may be given to later
210executions of
211.Nm
212(probably also with a
213.Fl s )
214to accumulate profile data across several runs of an
215.Pa a.out
216file.
217.It Fl z
218Displays routines that have zero usage (as shown by call counts
219and accumulated time).
220This is useful with the
221.Fl c
222option for discovering which routines were never called.
223.El
224.Sh ENVIRONMENT
225.Bl -tag -width PROFDIR
226.It Ev PROFDIR
227Directory to place profiling information in a file named
228.Pa pid.progname .
229If it is set to a null value, no profiling information is output.
230Otherwise, profiling information is placed in the file
231.Pa gmon.out .
232.El
233.Sh FILES
234.Bl -tag -width gmon.sum -compact
235.It Pa a.out
236namelist and text space
237.It Pa gmon.out
238dynamic call graph and profile
239.It Pa gmon.sum
240summarized dynamic call graph and profile
241.El
242.Sh SEE ALSO
243.Xr cc 1 ,
244.Xr profil 2 ,
245.Xr moncontrol 3
246.Rs
247.%T "An Execution Profiler for Modular Programs"
248.%A S. Graham
249.%A P. Kessler
250.%A M. McKusick
251.%J "Software - Practice and Experience"
252.%V 13
253.%P pp. 671-685
254.%D 1983
255.Re
256.Rs
257.%T "gprof: A Call Graph Execution Profiler"
258.%A S. Graham
259.%A P. Kessler
260.%A M. McKusick
261.%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices"
262.%V 17
263.%N 6
264.%P pp. 120-126
265.%D June 1982
266.Re
267.Sh HISTORY
268The
269.Nm
270profiler
271appeared in
272.Bx 4.2 .
273.Sh BUGS
274The granularity of the sampling is shown, but remains
275statistical at best.
276We assume that the time for each execution of a function
277can be expressed by the total time for the function divided
278by the number of times the function is called.
279Thus the time propagated along the call graph arcs to the function's
280parents is directly proportional to the number of times that
281arc is traversed.
282.Pp
283Parents that are not themselves profiled will have the time of
284their profiled children propagated to them, but they will appear
285to be spontaneously invoked in the call graph listing, and will
286not have their time propagated further.
287Similarly, signal catchers, even though profiled, will appear
288to be spontaneous (although for more obscure reasons).
289Any profiled children of signal catchers should have their times
290propagated properly, unless the signal catcher was invoked during
291the execution of the profiling routine, in which case all is lost.
292.Pp
293The profiled program must call
294.Xr exit 3
295or return normally for the profiling information to be saved
296in the
297.Pa gmon.out
298file.
299