xref: /original-bsd/usr.bin/gprof/gprof.1 (revision 6ab384a1)
1.\" Copyright (c) 1983, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)gprof.1	6.6 (Berkeley) 07/24/90
7.\"
8.Dd
9.Dt GPROF 1
10.Os BSD 4.2
11.Sh NAME
12.Nm gprof
13.Nd display call graph profile data
14.Sh SYNOPSIS
15.Nm gprof
16.Op options
17.Op Ar a.out Op Ar gmon.out ...
18.Sh DESCRIPTION
19.Nm gprof
20produces an execution profile of C, Pascal, or Fortran77 programs.
21The effect of called routines is incorporated in the profile of each caller.
22The profile data is taken from the call graph profile file
23.Pf \&( Pa gmon.out
24default) which is created by programs
25that are compiled with the
26.Fl pg
27option of
28.Xr cc 1 ,
29.Xr pc 1 ,
30and
31.Xr f77 1 .
32The
33.Fl pg
34option also links in versions of the library routines
35that are compiled for profiling.
36.Nm Gprof
37reads the given object file (the default is
38.Pa a.out)
39and establishes the relation between it's symbol table
40and the call graph profile from
41.Pa gmon.out .
42If more than one profile file is specified,
43the
44.Nm gprof
45output shows the sum of the profile information in the given profile files.
46.Pp
47.Nm Gprof
48calculates the amount of time spent in each routine.
49Next, these times are propagated along the edges of the call graph.
50Cycles are discovered, and calls into a cycle are made to share the time
51of the cycle.
52The first listing shows the functions
53sorted according to the time they represent
54including the time of their call graph descendents.
55Below each function entry is shown its (direct) call graph children,
56and how their times are propagated to this function.
57A similar display above the function shows how this function's time and the
58time of its descendents is propagated to its (direct) call graph parents.
59.Pp
60Cycles are also shown, with an entry for the cycle as a whole and
61a listing of the members of the cycle and their contributions to the
62time and call counts of the cycle.
63.Pp
64Second, a flat profile is given,
65similar to that provided by
66.Xr prof  1  .
67This listing gives the total execution times, the call counts,
68the time in milleseconds the call spent in the routine itself, and
69the time in milleseconds the call spent in the routine itself including
70its descendents.
71.Pp
72Finally, an index of the function names is provided.
73.Pp
74The following options are available:
75.Tw Fl
76.Tp Fl a
77suppresses the printing of statically declared functions.
78If this option is given, all relevant information about the static function
79(e.g., time samples, calls to other functions, calls from other functions)
80belongs to the function loaded just before the static function in the
81.Pa a.out
82file.
83.Tp Fl b
84suppresses the printing of a description of each field in the profile.
85.Tp Fl c
86the static call graph of the program is discovered by a heuristic
87that examines the text space of the object file.
88Static-only parents or children are shown
89with call counts of 0.
90.Tc Fl e
91.Ws
92.Ar name
93.Cx
94suppresses the printing of the graph profile entry for routine
95.Ar name
96and all its descendants
97(unless they have other ancestors that aren't suppressed).
98More than one
99.Fl e
100option may be given.
101Only one
102.Ar name
103may be given with each
104.Fl e
105option.
106.Tc Fl E
107.Ws
108.Ar name
109.Cx
110suppresses the printing of the graph profile entry for routine
111.Ar name
112(and its descendants) as
113.Fl e  ,
114above, and also excludes the time spent in
115.Ar name
116(and its descendants) from the total and percentage time computations.
117(For example,
118.Fl E
119.Ar mcount
120.Fl E
121.Ar mcleanup
122is the default.)
123.Tc Fl f
124.Ws
125.Ar name
126.Cx
127prints the graph profile entry of only the specified routine
128.Ar name
129and its descendants.
130More than one
131.Fl f
132option may be given.
133Only one
134.Ar name
135may be given with each
136.Fl f
137option.
138.Tc Fl F
139.Ws
140.Ar name
141.Cx
142prints the graph profile entry of only the routine
143.Ar name
144and its descendants (as
145.Fl f ,
146above) and also uses only the times of the printed routines
147in total time and percentage computations.
148More than one
149.Fl F
150option may be given.
151Only one
152.Ar name
153may be given with each
154.Fl F
155option.
156The
157.Fl F
158option
159overrides
160the
161.Fl E
162option.
163.Tc Fl k
164.Ws
165.Ar fromname
166.Ws
167.Ar toname
168.Cx
169will delete any arcs from routine
170.Ar fromname
171to routine
172.Ar toname  .
173This can be used to break undesired cycles.
174More than one
175.Fl k
176option may be given.
177Only one pair of routine names may be given with each
178.Fl k
179option.
180.Tp Fl s
181a profile file
182.Pa gmon.sum
183is produced that represents
184the sum of the profile information in all the specified profile files.
185This summary profile file may be given to later
186executions of gprof (probably also with a
187.Fl s  )
188to accumulate profile data across several runs of an
189.Pa a.out
190file.
191.Tp Fl z
192displays routines that have zero usage (as shown by call counts
193and accumulated time).
194This is useful with the
195.Fl c
196option for discovering which routines were never called.
197.Tp
198.Sh FILES
199.Dw gmon.sum
200.Di L
201.Dp Pa a.out
202the namelist and text space.
203.Dp Pa gmon.out
204dynamic call graph and profile.
205.Dp Pa gmon.sum
206summarized dynamic call graph and profile.
207.Dp
208.Sh SEE ALSO
209.Xr monitor 3 ,
210.Xr profil 2 ,
211.Xr cc 1 ,
212.Xr prof 1
213.br
214.Em An Execution Profiler for Modular Programs ,
215by
216S. Graham, P. Kessler, M. McKusick;
217Software  - Practice and Experience,
218Vol. 13, pp. 671-685, 1983.
219.br
220.Em gprof: A Call Graph Execution Profiler ,
221by S. Graham, P. Kessler, M. McKusick;
222Proceedings of the SIGPLAN '82 Symposium on Compiler Construction,
223SIGPLAN Notices, Vol. 17, No  6, pp. 120-126, June 1982.
224.Sh HISTORY
225.Nm Gprof
226appeared in 4.2 BSD.
227.Sh BUGS
228The granularity of the sampling is shown, but remains
229statistical at best.
230We assume that the time for each execution of a function
231can be expressed by the total time for the function divided
232by the number of times the function is called.
233Thus the time propagated along the call graph arcs to the function's
234parents is directly proportional to the number of times that
235arc is traversed.
236.Pp
237Parents that are not themselves profiled will have the time of
238their profiled children propagated to them, but they will appear
239to be spontaneously invoked in the call graph listing, and will
240not have their time propagated further.
241Similarly, signal catchers, even though profiled, will appear
242to be spontaneous (although for more obscure reasons).
243Any profiled children of signal catchers should have their times
244propagated properly, unless the signal catcher was invoked during
245the execution of the profiling routine, in which case all is lost.
246.Pp
247The profiled program must call
248.Xr exit  2
249or return normally for the profiling information to be saved
250in the
251.Pa gmon.out
252file.
253