xref: /csrg-svn/usr.bin/gprof/gprof.1 (revision 43693)
1*43693Scael.\" Copyright (c) 1983, 1990 The Regents of the University of California.
2*43693Scael.\" All rights reserved.
319768Smckusick.\"
4*43693Scael.\" %sccs.include.redist.man%
519768Smckusick.\"
6*43693Scael.\"     @(#)gprof.1	6.5 (Berkeley) 06/24/90
7*43693Scael.\"
8*43693Scael.Dd
9*43693Scael.Dt GPROF 1
10*43693Scael.Os BSD 4.2
11*43693Scael.Sh NAME
12*43693Scael.Nm gprof
13*43693Scael.Nd display call graph profile data
14*43693Scael.Sh SYNOPSIS
15*43693Scael.Nm gprof
16*43693Scael.Op options
17*43693Scael.Op Ar a.out Op Ar gmon.out ...
18*43693Scael.Sh DESCRIPTION
19*43693Scael.Nm gprof
2019768Smckusickproduces an execution profile of C, Pascal, or Fortran77 programs.
2119768SmckusickThe effect of called routines is incorporated in the profile of each caller.
2219768SmckusickThe profile data is taken from the call graph profile file
23*43693Scael.Pf \&( Pa gmon.out
2419768Smckusickdefault) which is created by programs
25*43693Scaelthat are compiled with the
26*43693Scael.Fl pg
27*43693Scaeloption of
28*43693Scael.Xr cc 1 ,
29*43693Scael.Xr pc 1 ,
3019768Smckusickand
31*43693Scael.Xr f77 1 .
3232285SmckusickThe
33*43693Scael.Fl pg
34*43693Scaeloption also links in versions of the library routines
3532285Smckusickthat are compiled for profiling.
36*43693Scael.Nm Gprof
37*43693Scaelreads the given object file (the default is
38*43693Scael.Pa a.out)
39*43693Scaeland establishes the relation between it's symbol table
40*43693Scaeland the call graph profile from
41*43693Scael.Pa gmon.out .
4219768SmckusickIf more than one profile file is specified,
4319768Smckusickthe
44*43693Scael.Nm gprof
4519768Smckusickoutput shows the sum of the profile information in the given profile files.
46*43693Scael.Pp
47*43693Scael.Nm Gprof
4832285Smckusickcalculates the amount of time spent in each routine.
4919768SmckusickNext, these times are propagated along the edges of the call graph.
50*43693ScaelCycles are discovered, and calls into a cycle are made to share the time
5119768Smckusickof the cycle.
5232285SmckusickThe first listing shows the functions
5319768Smckusicksorted according to the time they represent
5419768Smckusickincluding the time of their call graph descendents.
5519768SmckusickBelow each function entry is shown its (direct) call graph children,
5619768Smckusickand how their times are propagated to this function.
5719768SmckusickA similar display above the function shows how this function's time and the
5819768Smckusicktime of its descendents is propagated to its (direct) call graph parents.
59*43693Scael.Pp
6019768SmckusickCycles are also shown, with an entry for the cycle as a whole and
6119768Smckusicka listing of the members of the cycle and their contributions to the
6219768Smckusicktime and call counts of the cycle.
63*43693Scael.Pp
6432285SmckusickSecond, a flat profile is given,
6532285Smckusicksimilar to that provided by
66*43693Scael.Xr prof  1  .
6732285SmckusickThis listing gives the total execution times, the call counts,
68*43693Scaelthe time in milleseconds the call spent in the routine itself, and
69*43693Scaelthe time in milleseconds the call spent in the routine itself including
7032285Smckusickits descendents.
71*43693Scael.Pp
7232285SmckusickFinally, an index of the function names is provided.
73*43693Scael.Pp
7419768SmckusickThe following options are available:
75*43693Scael.Tw Fl
76*43693Scael.Tp Fl a
7719768Smckusicksuppresses the printing of statically declared functions.
7819768SmckusickIf this option is given, all relevant information about the static function
79*43693Scael(e.g., time samples, calls to other functions, calls from other functions)
8019768Smckusickbelongs to the function loaded just before the static function in the
81*43693Scael.Pa a.out
8219768Smckusickfile.
83*43693Scael.Tp Fl b
8432285Smckusicksuppresses the printing of a description of each field in the profile.
85*43693Scael.Tp Fl c
8619768Smckusickthe static call graph of the program is discovered by a heuristic
8732285Smckusickthat examines the text space of the object file.
8832285SmckusickStatic-only parents or children are shown
8919768Smckusickwith call counts of 0.
90*43693Scael.Tc Fl e
91*43693Scael.Ws
92*43693Scael.Ar name
93*43693Scael.Cx
9419768Smckusicksuppresses the printing of the graph profile entry for routine
95*43693Scael.Ar name
9619768Smckusickand all its descendants
9719768Smckusick(unless they have other ancestors that aren't suppressed).
9819768SmckusickMore than one
99*43693Scael.Fl e
10019768Smckusickoption may be given.
10119768SmckusickOnly one
102*43693Scael.Ar name
10319768Smckusickmay be given with each
104*43693Scael.Fl e
10519768Smckusickoption.
106*43693Scael.Tc Fl E
107*43693Scael.Ws
108*43693Scael.Ar name
109*43693Scael.Cx
11019768Smckusicksuppresses the printing of the graph profile entry for routine
111*43693Scael.Ar name
112*43693Scael(and its descendants) as
113*43693Scael.Fl e  ,
11419768Smckusickabove, and also excludes the time spent in
115*43693Scael.Ar name
11619768Smckusick(and its descendants) from the total and percentage time computations.
11719768Smckusick(For example,
118*43693Scael.Fl E
119*43693Scael.Ar mcount
120*43693Scael.Fl E
121*43693Scael.Ar mcleanup
12219768Smckusickis the default.)
123*43693Scael.Tc Fl f
124*43693Scael.Ws
125*43693Scael.Ar name
126*43693Scael.Cx
12719768Smckusickprints the graph profile entry of only the specified routine
128*43693Scael.Ar name
12919768Smckusickand its descendants.
13019768SmckusickMore than one
131*43693Scael.Fl f
13219768Smckusickoption may be given.
13319768SmckusickOnly one
134*43693Scael.Ar name
13519768Smckusickmay be given with each
136*43693Scael.Fl f
13719768Smckusickoption.
138*43693Scael.Tc Fl F
139*43693Scael.Ws
140*43693Scael.Ar name
141*43693Scael.Cx
14219768Smckusickprints the graph profile entry of only the routine
143*43693Scael.Ar name
144*43693Scaeland its descendants (as
145*43693Scael.Fl f ,
14619768Smckusickabove) and also uses only the times of the printed routines
14719768Smckusickin total time and percentage computations.
14819768SmckusickMore than one
149*43693Scael.Fl F
15019768Smckusickoption may be given.
15119768SmckusickOnly one
152*43693Scael.Ar name
15319768Smckusickmay be given with each
154*43693Scael.Fl F
15519768Smckusickoption.
15619768SmckusickThe
157*43693Scael.Fl F
15819768Smckusickoption
15919768Smckusickoverrides
16019768Smckusickthe
161*43693Scael.Fl E
16219768Smckusickoption.
163*43693Scael.Tc Fl k
164*43693Scael.Ws
165*43693Scael.Ar fromname
166*43693Scael.Ws
167*43693Scael.Ar toname
168*43693Scael.Cx
16930964Smckusickwill delete any arcs from routine
170*43693Scael.Ar fromname
17130964Smckusickto routine
172*43693Scael.Ar toname  .
17330964SmckusickThis can be used to break undesired cycles.
17430964SmckusickMore than one
175*43693Scael.Fl k
17630964Smckusickoption may be given.
17730964SmckusickOnly one pair of routine names may be given with each
178*43693Scael.Fl k
17930964Smckusickoption.
180*43693Scael.Tp Fl s
18119768Smckusicka profile file
182*43693Scael.Pa gmon.sum
18332285Smckusickis produced that represents
18419768Smckusickthe sum of the profile information in all the specified profile files.
18532285SmckusickThis summary profile file may be given to later
18619768Smckusickexecutions of gprof (probably also with a
187*43693Scael.Fl s  )
18819768Smckusickto accumulate profile data across several runs of an
189*43693Scael.Pa a.out
19019768Smckusickfile.
191*43693Scael.Tp Fl z
19232285Smckusickdisplays routines that have zero usage (as shown by call counts
19319768Smckusickand accumulated time).
194*43693ScaelThis is useful with the
195*43693Scael.Fl c
19619768Smckusickoption for discovering which routines were never called.
197*43693Scael.Tp
198*43693Scael.Sh FILES
199*43693Scael.Dw gmon.sum
200*43693Scael.Di L
201*43693Scael.Dp Pa a.out
20219768Smckusickthe namelist and text space.
203*43693Scael.Dp Pa gmon.out
20419768Smckusickdynamic call graph and profile.
205*43693Scael.Dp Pa gmon.sum
20619768Smckusicksummarized dynamic call graph and profile.
207*43693Scael.Dp
208*43693Scael.Sh SEE ALSO
209*43693Scael.Xr monitor 3 ,
210*43693Scael.Xr profil 2 ,
211*43693Scael.Xr cc 1 ,
212*43693Scael.Xr prof 1
21319768Smckusick.br
214*43693Scael.Em An Execution Profiler for Modular Programs ,
215*43693Scaelby
21639951SmckusickS. Graham, P. Kessler, M. McKusick;
217*43693ScaelSoftware  - Practice and Experience,
218*43693ScaelVol. 13, pp. 671-685, 1983.
21939951Smckusick.br
220*43693Scael.Em gprof: A Call Graph Execution Profiler ,
221*43693Scaelby S. Graham, P. Kessler, M. McKusick;
222*43693ScaelProceedings of the SIGPLAN '82 Symposium on Compiler Construction,
223*43693ScaelSIGPLAN Notices, Vol. 17, No  6, pp. 120-126, June 1982.
224*43693Scael.Sh HISTORY
225*43693Scael.Nm Gprof
226*43693Scaelappeared in 4.2 BSD.
227*43693Scael.Sh BUGS
22819768SmckusickThe granularity of the sampling is shown, but remains
22919768Smckusickstatistical at best.
23019768SmckusickWe assume that the time for each execution of a function
23119768Smckusickcan be expressed by the total time for the function divided
23219768Smckusickby the number of times the function is called.
23332285SmckusickThus the time propagated along the call graph arcs to the function's
23432285Smckusickparents is directly proportional to the number of times that
23519768Smckusickarc is traversed.
236*43693Scael.Pp
237*43693ScaelParents that are not themselves profiled will have the time of
23819768Smckusicktheir profiled children propagated to them, but they will appear
23919768Smckusickto be spontaneously invoked in the call graph listing, and will
24019768Smckusicknot have their time propagated further.
24119768SmckusickSimilarly, signal catchers, even though profiled, will appear
24219768Smckusickto be spontaneous (although for more obscure reasons).
24319768SmckusickAny profiled children of signal catchers should have their times
244*43693Scaelpropagated properly, unless the signal catcher was invoked during
24519768Smckusickthe execution of the profiling routine, in which case all is lost.
246*43693Scael.Pp
247*43693ScaelThe profiled program must call
248*43693Scael.Xr exit  2
24919768Smckusickor return normally for the profiling information to be saved
250*43693Scaelin the
251*43693Scael.Pa gmon.out
252*43693Scaelfile.
253