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