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