xref: /original-bsd/usr.bin/gprof/gprof.1 (revision 499a7081)
1.\" Copyright (c) 1983, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"	@(#)gprof.1	6.8 (Berkeley) 07/24/91
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.Bl -tag -width Fl
76.It 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.It Fl b
84Suppresses the printing of a description of each field in the profile.
85.It 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.It Fl e Ar name
91Suppresses the printing of the graph profile entry for routine
92.Ar name
93and all its descendants
94(unless they have other ancestors that aren't suppressed).
95More than one
96.Fl e
97option may be given.
98Only one
99.Ar name
100may be given with each
101.Fl e
102option.
103.It Fl E Ar name
104Suppresses the printing of the graph profile entry for routine
105.Ar name
106(and its descendants) as
107.Fl e  ,
108above, and also excludes the time spent in
109.Ar name
110(and its descendants) from the total and percentage time computations.
111(For example,
112.Fl E
113.Ar mcount
114.Fl E
115.Ar mcleanup
116is the default.)
117.It Fl f Ar name
118Prints the graph profile entry of only the specified routine
119.Ar name
120and its descendants.
121More than one
122.Fl f
123option may be given.
124Only one
125.Ar name
126may be given with each
127.Fl f
128option.
129.It Fl F Ar name
130Prints the graph profile entry of only the routine
131.Ar name
132and its descendants (as
133.Fl f ,
134above) and also uses only the times of the printed routines
135in total time and percentage computations.
136More than one
137.Fl F
138option may be given.
139Only one
140.Ar name
141may be given with each
142.Fl F
143option.
144The
145.Fl F
146option
147overrides
148the
149.Fl E
150option.
151.It Fl k Ar fromname Ar toname
152Will delete any arcs from routine
153.Ar fromname
154to routine
155.Ar toname .
156This can be used to break undesired cycles.
157More than one
158.Fl k
159option may be given.
160Only one pair of routine names may be given with each
161.Fl k
162option.
163.It Fl s
164A profile file
165.Pa gmon.sum
166is produced that represents
167the sum of the profile information in all the specified profile files.
168This summary profile file may be given to later
169executions of gprof (probably also with a
170.Fl s )
171to accumulate profile data across several runs of an
172.Pa a.out
173file.
174.It Fl z
175Displays routines that have zero usage (as shown by call counts
176and accumulated time).
177This is useful with the
178.Fl c
179option for discovering which routines were never called.
180.El
181.Sh FILES
182.Bl -tag -width gmon.sum -compact
183.It Pa a.out
184The namelist and text space.
185.It Pa gmon.out
186Dynamic call graph and profile.
187.It Pa gmon.sum
188Summarized dynamic call graph and profile.
189.El
190.Sh SEE ALSO
191.Xr monitor 3 ,
192.Xr profil 2 ,
193.Xr cc 1 ,
194.Xr prof 1
195.Rs
196.%T "An Execution Profiler for Modular Programs"
197.%A S. Graham
198.%A P. Kessler
199.%A M. McKusick
200.%J "Software - Practice and Experience"
201.%V 13
202.%P pp. 671-685
203.%D 1983
204.Re
205.Rs
206.%T "gprof: A Call Graph Execution Profiler"
207.%A S. Graham
208.%A P. Kessler
209.%A M. McKusick
210.%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices"
211.%V 17
212.%N 6
213.%P pp. 120-126
214.%D June 1982
215.Re
216.Sh HISTORY
217The
218.Nm gprof
219profiler
220appeared in
221.Bx 4.2 .
222.Sh BUGS
223The granularity of the sampling is shown, but remains
224statistical at best.
225We assume that the time for each execution of a function
226can be expressed by the total time for the function divided
227by the number of times the function is called.
228Thus the time propagated along the call graph arcs to the function's
229parents is directly proportional to the number of times that
230arc is traversed.
231.Pp
232Parents that are not themselves profiled will have the time of
233their profiled children propagated to them, but they will appear
234to be spontaneously invoked in the call graph listing, and will
235not have their time propagated further.
236Similarly, signal catchers, even though profiled, will appear
237to be spontaneous (although for more obscure reasons).
238Any profiled children of signal catchers should have their times
239propagated properly, unless the signal catcher was invoked during
240the execution of the profiling routine, in which case all is lost.
241.Pp
242The profiled program must call
243.Xr exit  2
244or return normally for the profiling information to be saved
245in the
246.Pa gmon.out
247file.
248