xref: /csrg-svn/usr.bin/gprof/gprof.1 (revision 62017)
1*62017Sbostic.\" Copyright (c) 1983, 1990, 1993
2*62017Sbostic.\"	The Regents of the University of California.  All rights reserved.
319768Smckusick.\"
450520Scael.\" %sccs.include.redist.roff%
519768Smckusick.\"
6*62017Sbostic.\"	@(#)gprof.1	8.1 (Berkeley) 06/06/93
743693Scael.\"
843693Scael.Dd
943693Scael.Dt GPROF 1
1043693Scael.Os BSD 4.2
1143693Scael.Sh NAME
1243693Scael.Nm gprof
1343693Scael.Nd display call graph profile data
1443693Scael.Sh SYNOPSIS
1543693Scael.Nm gprof
1643693Scael.Op options
1743693Scael.Op Ar a.out Op Ar gmon.out ...
1843693Scael.Sh DESCRIPTION
1950520Scael.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
2350520Scael.Pf ( Pa gmon.out
2419768Smckusickdefault) which is created by programs
2543693Scaelthat are compiled with the
2643693Scael.Fl pg
2743693Scaeloption of
2843693Scael.Xr cc 1 ,
2943693Scael.Xr pc 1 ,
3019768Smckusickand
3143693Scael.Xr f77 1 .
3232285SmckusickThe
3343693Scael.Fl pg
3443693Scaeloption also links in versions of the library routines
3532285Smckusickthat are compiled for profiling.
3643693Scael.Nm Gprof
3743693Scaelreads the given object file (the default is
3843693Scael.Pa a.out)
3943693Scaeland establishes the relation between it's symbol table
4043693Scaeland the call graph profile from
4143693Scael.Pa gmon.out .
4219768SmckusickIf more than one profile file is specified,
4319768Smckusickthe
4443693Scael.Nm gprof
4519768Smckusickoutput shows the sum of the profile information in the given profile files.
4643693Scael.Pp
4743693Scael.Nm Gprof
4832285Smckusickcalculates the amount of time spent in each routine.
4919768SmckusickNext, these times are propagated along the edges of the call graph.
5043693ScaelCycles 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.
5943693Scael.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.
6343693Scael.Pp
6432285SmckusickSecond, a flat profile is given,
6532285Smckusicksimilar to that provided by
6643693Scael.Xr prof  1  .
6732285SmckusickThis listing gives the total execution times, the call counts,
6843693Scaelthe time in milleseconds the call spent in the routine itself, and
6943693Scaelthe time in milleseconds the call spent in the routine itself including
7032285Smckusickits descendents.
7143693Scael.Pp
7232285SmckusickFinally, an index of the function names is provided.
7343693Scael.Pp
7419768SmckusickThe following options are available:
7550520Scael.Bl -tag -width Fl
7650520Scael.It Fl a
7750520ScaelSuppresses the printing of statically declared functions.
7819768SmckusickIf this option is given, all relevant information about the static function
7943693Scael(e.g., time samples, calls to other functions, calls from other functions)
8019768Smckusickbelongs to the function loaded just before the static function in the
8143693Scael.Pa a.out
8219768Smckusickfile.
8350520Scael.It Fl b
8450520ScaelSuppresses the printing of a description of each field in the profile.
8550520Scael.It Fl c
8650520ScaelThe 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.
9052813Smckusick.It Fl C Ar count
9152813SmckusickFind a minimal set of arcs that can be broken to eliminate all cycles with
9252813Smckusick.Ar count
9352813Smckusickor more members.
9452813SmckusickCaution: the algorithm used to break cycles is exponential,
9552813Smckusickso using this option may cause
9652813Smckusick.Nm gprof
9752813Smckusickto run for a very long time.
9850520Scael.It Fl e Ar name
9950520ScaelSuppresses the printing of the graph profile entry for routine
10043693Scael.Ar name
10119768Smckusickand all its descendants
10219768Smckusick(unless they have other ancestors that aren't suppressed).
10319768SmckusickMore than one
10443693Scael.Fl e
10519768Smckusickoption may be given.
10619768SmckusickOnly one
10743693Scael.Ar name
10819768Smckusickmay be given with each
10943693Scael.Fl e
11019768Smckusickoption.
11150520Scael.It Fl E Ar name
11250520ScaelSuppresses the printing of the graph profile entry for routine
11343693Scael.Ar name
11443693Scael(and its descendants) as
11543693Scael.Fl e  ,
11619768Smckusickabove, and also excludes the time spent in
11743693Scael.Ar name
11819768Smckusick(and its descendants) from the total and percentage time computations.
11919768Smckusick(For example,
12043693Scael.Fl E
12143693Scael.Ar mcount
12243693Scael.Fl E
12343693Scael.Ar mcleanup
12419768Smckusickis the default.)
12550520Scael.It Fl f Ar name
12650520ScaelPrints the graph profile entry of only the specified routine
12743693Scael.Ar name
12819768Smckusickand its descendants.
12919768SmckusickMore than one
13043693Scael.Fl f
13119768Smckusickoption may be given.
13219768SmckusickOnly one
13343693Scael.Ar name
13419768Smckusickmay be given with each
13543693Scael.Fl f
13619768Smckusickoption.
13750520Scael.It Fl F Ar name
13850520ScaelPrints the graph profile entry of only the routine
13943693Scael.Ar name
14043693Scaeland its descendants (as
14143693Scael.Fl f ,
14219768Smckusickabove) and also uses only the times of the printed routines
14319768Smckusickin total time and percentage computations.
14419768SmckusickMore than one
14543693Scael.Fl F
14619768Smckusickoption may be given.
14719768SmckusickOnly one
14843693Scael.Ar name
14919768Smckusickmay be given with each
15043693Scael.Fl F
15119768Smckusickoption.
15219768SmckusickThe
15343693Scael.Fl F
15419768Smckusickoption
15519768Smckusickoverrides
15619768Smckusickthe
15743693Scael.Fl E
15819768Smckusickoption.
15950520Scael.It Fl k Ar fromname Ar toname
16050520ScaelWill delete any arcs from routine
16143693Scael.Ar fromname
16230964Smckusickto routine
16350520Scael.Ar toname .
16430964SmckusickThis can be used to break undesired cycles.
16530964SmckusickMore than one
16643693Scael.Fl k
16730964Smckusickoption may be given.
16830964SmckusickOnly one pair of routine names may be given with each
16943693Scael.Fl k
17030964Smckusickoption.
17150520Scael.It Fl s
17250520ScaelA profile file
17343693Scael.Pa gmon.sum
17432285Smckusickis produced that represents
17519768Smckusickthe sum of the profile information in all the specified profile files.
17632285SmckusickThis summary profile file may be given to later
17719768Smckusickexecutions of gprof (probably also with a
17850520Scael.Fl s )
17919768Smckusickto accumulate profile data across several runs of an
18043693Scael.Pa a.out
18119768Smckusickfile.
18250520Scael.It Fl z
18350520ScaelDisplays routines that have zero usage (as shown by call counts
18419768Smckusickand accumulated time).
18543693ScaelThis is useful with the
18643693Scael.Fl c
18719768Smckusickoption for discovering which routines were never called.
18850520Scael.El
18943693Scael.Sh FILES
19050520Scael.Bl -tag -width gmon.sum -compact
19150520Scael.It Pa a.out
19250520ScaelThe namelist and text space.
19350520Scael.It Pa gmon.out
19450520ScaelDynamic call graph and profile.
19550520Scael.It Pa gmon.sum
19650520ScaelSummarized dynamic call graph and profile.
19750520Scael.El
19843693Scael.Sh SEE ALSO
19943693Scael.Xr monitor 3 ,
20043693Scael.Xr profil 2 ,
20143693Scael.Xr cc 1 ,
20243693Scael.Xr prof 1
20350520Scael.Rs
20450520Scael.%T "An Execution Profiler for Modular Programs"
20550520Scael.%A S. Graham
20650520Scael.%A P. Kessler
20750520Scael.%A M. McKusick
20850520Scael.%J "Software - Practice and Experience"
20950520Scael.%V 13
21050520Scael.%P pp. 671-685
21150520Scael.%D 1983
21250520Scael.Re
21350520Scael.Rs
21450520Scael.%T "gprof: A Call Graph Execution Profiler"
21550520Scael.%A S. Graham
21650520Scael.%A P. Kessler
21750520Scael.%A M. McKusick
21850520Scael.%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices"
21950520Scael.%V 17
22050520Scael.%N 6
22150520Scael.%P pp. 120-126
22250520Scael.%D June 1982
22350520Scael.Re
22443693Scael.Sh HISTORY
22550520ScaelThe
22650520Scael.Nm gprof
22750520Scaelprofiler
22850520Scaelappeared in
22950520Scael.Bx 4.2 .
23043693Scael.Sh BUGS
23119768SmckusickThe granularity of the sampling is shown, but remains
23219768Smckusickstatistical at best.
23319768SmckusickWe assume that the time for each execution of a function
23419768Smckusickcan be expressed by the total time for the function divided
23519768Smckusickby the number of times the function is called.
23632285SmckusickThus the time propagated along the call graph arcs to the function's
23732285Smckusickparents is directly proportional to the number of times that
23819768Smckusickarc is traversed.
23943693Scael.Pp
24043693ScaelParents that are not themselves profiled will have the time of
24119768Smckusicktheir profiled children propagated to them, but they will appear
24219768Smckusickto be spontaneously invoked in the call graph listing, and will
24319768Smckusicknot have their time propagated further.
24419768SmckusickSimilarly, signal catchers, even though profiled, will appear
24519768Smckusickto be spontaneous (although for more obscure reasons).
24619768SmckusickAny profiled children of signal catchers should have their times
24743693Scaelpropagated properly, unless the signal catcher was invoked during
24819768Smckusickthe execution of the profiling routine, in which case all is lost.
24943693Scael.Pp
25043693ScaelThe profiled program must call
25143693Scael.Xr exit  2
25219768Smckusickor return normally for the profiling information to be saved
25343693Scaelin the
25443693Scael.Pa gmon.out
25543693Scaelfile.
256