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