143693Scael.\" Copyright (c) 1983, 1990 The Regents of the University of California. 243693Scael.\" All rights reserved. 319768Smckusick.\" 4*50520Scael.\" %sccs.include.redist.roff% 519768Smckusick.\" 6*50520Scael.\" @(#)gprof.1 6.8 (Berkeley) 07/24/91 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 19*50520Scael.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*50520Scael.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: 75*50520Scael.Bl -tag -width Fl 76*50520Scael.It Fl a 77*50520ScaelSuppresses 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. 83*50520Scael.It Fl b 84*50520ScaelSuppresses the printing of a description of each field in the profile. 85*50520Scael.It Fl c 86*50520ScaelThe 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*50520Scael.It Fl e Ar name 91*50520ScaelSuppresses the printing of the graph profile entry for routine 9243693Scael.Ar name 9319768Smckusickand all its descendants 9419768Smckusick(unless they have other ancestors that aren't suppressed). 9519768SmckusickMore than one 9643693Scael.Fl e 9719768Smckusickoption may be given. 9819768SmckusickOnly one 9943693Scael.Ar name 10019768Smckusickmay be given with each 10143693Scael.Fl e 10219768Smckusickoption. 103*50520Scael.It Fl E Ar name 104*50520ScaelSuppresses the printing of the graph profile entry for routine 10543693Scael.Ar name 10643693Scael(and its descendants) as 10743693Scael.Fl e , 10819768Smckusickabove, and also excludes the time spent in 10943693Scael.Ar name 11019768Smckusick(and its descendants) from the total and percentage time computations. 11119768Smckusick(For example, 11243693Scael.Fl E 11343693Scael.Ar mcount 11443693Scael.Fl E 11543693Scael.Ar mcleanup 11619768Smckusickis the default.) 117*50520Scael.It Fl f Ar name 118*50520ScaelPrints the graph profile entry of only the specified routine 11943693Scael.Ar name 12019768Smckusickand its descendants. 12119768SmckusickMore than one 12243693Scael.Fl f 12319768Smckusickoption may be given. 12419768SmckusickOnly one 12543693Scael.Ar name 12619768Smckusickmay be given with each 12743693Scael.Fl f 12819768Smckusickoption. 129*50520Scael.It Fl F Ar name 130*50520ScaelPrints the graph profile entry of only the routine 13143693Scael.Ar name 13243693Scaeland its descendants (as 13343693Scael.Fl f , 13419768Smckusickabove) and also uses only the times of the printed routines 13519768Smckusickin total time and percentage computations. 13619768SmckusickMore than one 13743693Scael.Fl F 13819768Smckusickoption may be given. 13919768SmckusickOnly one 14043693Scael.Ar name 14119768Smckusickmay be given with each 14243693Scael.Fl F 14319768Smckusickoption. 14419768SmckusickThe 14543693Scael.Fl F 14619768Smckusickoption 14719768Smckusickoverrides 14819768Smckusickthe 14943693Scael.Fl E 15019768Smckusickoption. 151*50520Scael.It Fl k Ar fromname Ar toname 152*50520ScaelWill delete any arcs from routine 15343693Scael.Ar fromname 15430964Smckusickto routine 155*50520Scael.Ar toname . 15630964SmckusickThis can be used to break undesired cycles. 15730964SmckusickMore than one 15843693Scael.Fl k 15930964Smckusickoption may be given. 16030964SmckusickOnly one pair of routine names may be given with each 16143693Scael.Fl k 16230964Smckusickoption. 163*50520Scael.It Fl s 164*50520ScaelA profile file 16543693Scael.Pa gmon.sum 16632285Smckusickis produced that represents 16719768Smckusickthe sum of the profile information in all the specified profile files. 16832285SmckusickThis summary profile file may be given to later 16919768Smckusickexecutions of gprof (probably also with a 170*50520Scael.Fl s ) 17119768Smckusickto accumulate profile data across several runs of an 17243693Scael.Pa a.out 17319768Smckusickfile. 174*50520Scael.It Fl z 175*50520ScaelDisplays routines that have zero usage (as shown by call counts 17619768Smckusickand accumulated time). 17743693ScaelThis is useful with the 17843693Scael.Fl c 17919768Smckusickoption for discovering which routines were never called. 180*50520Scael.El 18143693Scael.Sh FILES 182*50520Scael.Bl -tag -width gmon.sum -compact 183*50520Scael.It Pa a.out 184*50520ScaelThe namelist and text space. 185*50520Scael.It Pa gmon.out 186*50520ScaelDynamic call graph and profile. 187*50520Scael.It Pa gmon.sum 188*50520ScaelSummarized dynamic call graph and profile. 189*50520Scael.El 19043693Scael.Sh SEE ALSO 19143693Scael.Xr monitor 3 , 19243693Scael.Xr profil 2 , 19343693Scael.Xr cc 1 , 19443693Scael.Xr prof 1 195*50520Scael.Rs 196*50520Scael.%T "An Execution Profiler for Modular Programs" 197*50520Scael.%A S. Graham 198*50520Scael.%A P. Kessler 199*50520Scael.%A M. McKusick 200*50520Scael.%J "Software - Practice and Experience" 201*50520Scael.%V 13 202*50520Scael.%P pp. 671-685 203*50520Scael.%D 1983 204*50520Scael.Re 205*50520Scael.Rs 206*50520Scael.%T "gprof: A Call Graph Execution Profiler" 207*50520Scael.%A S. Graham 208*50520Scael.%A P. Kessler 209*50520Scael.%A M. McKusick 210*50520Scael.%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices" 211*50520Scael.%V 17 212*50520Scael.%N 6 213*50520Scael.%P pp. 120-126 214*50520Scael.%D June 1982 215*50520Scael.Re 21643693Scael.Sh HISTORY 217*50520ScaelThe 218*50520Scael.Nm gprof 219*50520Scaelprofiler 220*50520Scaelappeared in 221*50520Scael.Bx 4.2 . 22243693Scael.Sh BUGS 22319768SmckusickThe granularity of the sampling is shown, but remains 22419768Smckusickstatistical at best. 22519768SmckusickWe assume that the time for each execution of a function 22619768Smckusickcan be expressed by the total time for the function divided 22719768Smckusickby the number of times the function is called. 22832285SmckusickThus the time propagated along the call graph arcs to the function's 22932285Smckusickparents is directly proportional to the number of times that 23019768Smckusickarc is traversed. 23143693Scael.Pp 23243693ScaelParents that are not themselves profiled will have the time of 23319768Smckusicktheir profiled children propagated to them, but they will appear 23419768Smckusickto be spontaneously invoked in the call graph listing, and will 23519768Smckusicknot have their time propagated further. 23619768SmckusickSimilarly, signal catchers, even though profiled, will appear 23719768Smckusickto be spontaneous (although for more obscure reasons). 23819768SmckusickAny profiled children of signal catchers should have their times 23943693Scaelpropagated properly, unless the signal catcher was invoked during 24019768Smckusickthe execution of the profiling routine, in which case all is lost. 24143693Scael.Pp 24243693ScaelThe profiled program must call 24343693Scael.Xr exit 2 24419768Smckusickor return normally for the profiling information to be saved 24543693Scaelin the 24643693Scael.Pa gmon.out 24743693Scaelfile. 248