1.\" Copyright (c) 1983, 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)gprof.1 8.1 (Berkeley) 6/6/93 33.\" $FreeBSD$ 34.\" 35.Dd June 6, 1993 36.Dt GPROF 1 37.Os 38.Sh NAME 39.Nm gprof 40.Nd display call graph profile data 41.Sh SYNOPSIS 42.Nm 43.Op options 44.Op Ar a.out Op Ar a.out.gmon ... 45.Sh DESCRIPTION 46.Nm Gprof 47produces an execution profile of C, Pascal, or Fortran77 programs. 48The effect of called routines is incorporated in the profile of each caller. 49The profile data is taken from the call graph profile file 50which is created by programs that are compiled with the 51.Fl pg 52option of 53.Xr cc 1 , 54.Xr pc 1 , 55and 56.Xr f77 1 . 57The 58.Fl pg 59option also links in versions of the library routines 60that are compiled for profiling. 61By convention these libraries have their name suffixed with 62.Pa _p , 63i.e. the profiled version of 64.Pa libc.a 65is 66.Pa libc_p.a 67and if you specify libraries directly to the 68compiler or linker you can use 69.Fl l Ns Ar c_p 70instead of 71.Fl l Ns Ar c . 72.Nm Gprof 73reads the given object file (the default is 74.Pa a.out) 75and establishes the relation between its symbol table 76and the call graph profile. 77The default graph profile file name is the name 78of the executable with the suffix 79.Pa .gmon 80appended. 81If more than one profile file is specified, 82the 83.Nm 84output shows the sum of the profile information in the given profile files. 85.Pp 86.Nm Gprof 87calculates the amount of time spent in each routine. 88Next, these times are propagated along the edges of the call graph. 89Cycles are discovered, and calls into a cycle are made to share the time 90of the cycle. 91The first listing shows the functions 92sorted according to the time they represent 93including the time of their call graph descendents. 94Below each function entry is shown its (direct) call graph children, 95and how their times are propagated to this function. 96A similar display above the function shows how this function's time and the 97time of its descendents is propagated to its (direct) call graph parents. 98.Pp 99Cycles are also shown, with an entry for the cycle as a whole and 100a listing of the members of the cycle and their contributions to the 101time and call counts of the cycle. 102.Pp 103Second, a flat profile is given, 104similar to that provided by 105.Xr prof 1 . 106This listing gives the total execution times, the call counts, 107the time in msec or usec the call spent in the routine itself, and 108the time in msec or usec the call spent in the routine itself including 109its descendents. 110.Pp 111Finally, an index of the function names is provided. 112.Pp 113The following options are available: 114.Bl -tag -width Fl 115.It Fl a 116Suppresses the printing of statically declared functions. 117If this option is given, all relevant information about the static function 118(e.g., time samples, calls to other functions, calls from other functions) 119belongs to the function loaded just before the static function in the 120.Pa a.out 121file. 122.It Fl b 123Suppresses the printing of a description of each field in the profile. 124.It Fl c 125The static call graph of the program is discovered by a heuristic 126that examines the text space of the object file. 127Static-only parents or children are shown 128with call counts of 0. 129This option is not supported on some architectures. 130.It Fl C Ar count 131Find a minimal set of arcs that can be broken to eliminate all cycles with 132.Ar count 133or more members. 134Caution: the algorithm used to break cycles is exponential, 135so using this option may cause 136.Nm 137to run for a very long time. 138.It Fl e Ar name 139Suppresses the printing of the graph profile entry for routine 140.Ar name 141and all its descendants 142(unless they have other ancestors that aren't suppressed). 143More than one 144.Fl e 145option may be given. 146Only one 147.Ar name 148may be given with each 149.Fl e 150option. 151.It Fl E Ar name 152Suppresses the printing of the graph profile entry for routine 153.Ar name 154(and its descendants) as 155.Fl e , 156above, and also excludes the time spent in 157.Ar name 158(and its descendants) from the total and percentage time computations. 159(For example, 160.Fl E 161.Ar mcount 162.Fl E 163.Ar mcleanup 164is the default.) 165.It Fl f Ar name 166Prints the graph profile entry of only the specified routine 167.Ar name 168and its descendants. 169More than one 170.Fl f 171option may be given. 172Only one 173.Ar name 174may be given with each 175.Fl f 176option. 177.It Fl F Ar name 178Prints the graph profile entry of only the routine 179.Ar name 180and its descendants (as 181.Fl f , 182above) and also uses only the times of the printed routines 183in total time and percentage computations. 184More than one 185.Fl F 186option may be given. 187Only one 188.Ar name 189may be given with each 190.Fl F 191option. 192The 193.Fl F 194option 195overrides 196the 197.Fl E 198option. 199.It Fl k Ar fromname Ar toname 200Will delete any arcs from routine 201.Ar fromname 202to routine 203.Ar toname . 204This can be used to break undesired cycles. 205More than one 206.Fl k 207option may be given. 208Only one pair of routine names may be given with each 209.Fl k 210option. 211.It Fl K 212Gather information about symbols from the currently-running kernel using the 213.Xr sysctl 3 214and 215.Xr kldsym 2 216interfaces. 217This forces the 218.Pa a.out 219argument to be ignored, and allows for symbols in 220.Xr kld 4 221modules to be used. 222.It Fl l 223Suppresses the printing of the call-graph profile. 224.It Fl L 225Suppresses the printing of the flat profile. 226.It Fl s 227A profile file 228.Pa gmon.sum 229is produced that represents 230the sum of the profile information in all the specified profile files. 231This summary profile file may be given to later 232executions of gprof (probably also with a 233.Fl s ) 234to accumulate profile data across several runs of an 235.Pa a.out 236file. 237.It Fl u 238Suppresses the printing of functions whose names are not visible to 239C programs. For the ELF object format, this means names that 240contain the 241.Ql .\& 242character. For the a.out object format, it means names that do not 243begin with a 244.Ql _ 245character. 246All relevant information about such functions belongs to the 247(non-suppressed) function with the next lowest address. 248This is useful for eliminating "functions" that are just labels 249inside other functions. 250.It Fl z 251Displays routines that have zero usage (as shown by call counts 252and accumulated time). 253This is useful with the 254.Fl c 255option for discovering which routines were never called. 256.El 257.Sh FILES 258.Bl -tag -width a.out.gmon -compact 259.It Pa a.out 260The namelist and text space. 261.It Pa a.out.gmon 262Dynamic call graph and profile. 263.It Pa gmon.sum 264Summarized dynamic call graph and profile. 265.El 266.Sh SEE ALSO 267.Xr cc 1 , 268.Xr profil 2 , 269.Xr clocks 7 270.\" .Xr monitor 3 , 271.\" .Xr prof 1 272.Rs 273.%T "An Execution Profiler for Modular Programs" 274.%A S. Graham 275.%A P. Kessler 276.%A M. McKusick 277.%J "Software - Practice and Experience" 278.%V 13 279.%P pp. 671-685 280.%D 1983 281.Re 282.Rs 283.%T "gprof: A Call Graph Execution Profiler" 284.%A S. Graham 285.%A P. Kessler 286.%A M. McKusick 287.%J "Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices" 288.%V 17 289.%N 6 290.%P pp. 120-126 291.%D June 1982 292.Re 293.Sh HISTORY 294The 295.Nm 296profiler 297appeared in 298.Bx 4.2 . 299.Sh BUGS 300The granularity of the sampling is shown, but remains 301statistical at best. 302We assume that the time for each execution of a function 303can be expressed by the total time for the function divided 304by the number of times the function is called. 305Thus the time propagated along the call graph arcs to the function's 306parents is directly proportional to the number of times that 307arc is traversed. 308.Pp 309Parents that are not themselves profiled will have the time of 310their profiled children propagated to them, but they will appear 311to be spontaneously invoked in the call graph listing, and will 312not have their time propagated further. 313Similarly, signal catchers, even though profiled, will appear 314to be spontaneous (although for more obscure reasons). 315Any profiled children of signal catchers should have their times 316propagated properly, unless the signal catcher was invoked during 317the execution of the profiling routine, in which case all is lost. 318.Pp 319The profiled program must call 320.Xr exit 3 321or return normally for the profiling information to be saved 322in the graph profile file. 323