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