1*8269e767SBrooks Davis.\" Copyright (c) 1993 2*8269e767SBrooks Davis.\" The Regents of the University of California. All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" This code is derived from software contributed to Berkeley by 5*8269e767SBrooks Davis.\" Donn Seeley of BSDI. 6*8269e767SBrooks Davis.\" 7*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 8*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 9*8269e767SBrooks Davis.\" are met: 10*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 11*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 12*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 13*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 14*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 15*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors 16*8269e767SBrooks Davis.\" may be used to endorse or promote products derived from this software 17*8269e767SBrooks Davis.\" without specific prior written permission. 18*8269e767SBrooks Davis.\" 19*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*8269e767SBrooks Davis.\" SUCH DAMAGE. 30*8269e767SBrooks Davis.\" 31*8269e767SBrooks Davis.Dd December 1, 2017 32*8269e767SBrooks Davis.Dt PROFIL 2 33*8269e767SBrooks Davis.Os 34*8269e767SBrooks Davis.Sh NAME 35*8269e767SBrooks Davis.Nm profil 36*8269e767SBrooks Davis.Nd control process profiling 37*8269e767SBrooks Davis.Sh LIBRARY 38*8269e767SBrooks Davis.Lb libc 39*8269e767SBrooks Davis.Sh SYNOPSIS 40*8269e767SBrooks Davis.In unistd.h 41*8269e767SBrooks Davis.Ft int 42*8269e767SBrooks Davis.Fn profil "char *samples" "size_t size" "vm_offset_t offset" "int scale" 43*8269e767SBrooks Davis.Sh DESCRIPTION 44*8269e767SBrooks DavisThe 45*8269e767SBrooks Davis.Fn profil 46*8269e767SBrooks Davissystem call enables or disables 47*8269e767SBrooks Davisprogram counter profiling of the current process. 48*8269e767SBrooks DavisIf profiling is enabled, 49*8269e767SBrooks Davisthen at every profiling clock tick, 50*8269e767SBrooks Davisthe kernel updates an appropriate count in the 51*8269e767SBrooks Davis.Fa samples 52*8269e767SBrooks Davisbuffer. 53*8269e767SBrooks DavisThe frequency of the profiling clock is recorded 54*8269e767SBrooks Davisin the header in the profiling output file. 55*8269e767SBrooks Davis.Pp 56*8269e767SBrooks DavisThe buffer 57*8269e767SBrooks Davis.Fa samples 58*8269e767SBrooks Daviscontains 59*8269e767SBrooks Davis.Fa size 60*8269e767SBrooks Davisbytes and is divided into 61*8269e767SBrooks Davisa series of 16-bit bins. 62*8269e767SBrooks DavisEach bin counts the number of times the program counter 63*8269e767SBrooks Daviswas in a particular address range in the process 64*8269e767SBrooks Daviswhen a profiling clock tick occurred while profiling was enabled. 65*8269e767SBrooks DavisFor a given program counter address, 66*8269e767SBrooks Davisthe number of the corresponding bin is given 67*8269e767SBrooks Davisby the relation: 68*8269e767SBrooks Davis.Bd -literal -offset indent 69*8269e767SBrooks Davis[(pc - offset) / 2] * scale / 65536 70*8269e767SBrooks Davis.Ed 71*8269e767SBrooks Davis.Pp 72*8269e767SBrooks DavisThe 73*8269e767SBrooks Davis.Fa offset 74*8269e767SBrooks Davisargument is the lowest address at which 75*8269e767SBrooks Davisthe kernel takes program counter samples. 76*8269e767SBrooks DavisThe 77*8269e767SBrooks Davis.Fa scale 78*8269e767SBrooks Davisargument ranges from 1 to 65536 and 79*8269e767SBrooks Daviscan be used to change the span of the bins. 80*8269e767SBrooks DavisA scale of 65536 maps each bin to 2 bytes of address range; 81*8269e767SBrooks Davisa scale of 32768 gives 4 bytes, 16384 gives 8 bytes and so on. 82*8269e767SBrooks DavisIntermediate values provide approximate intermediate ranges. 83*8269e767SBrooks DavisA 84*8269e767SBrooks Davis.Fa scale 85*8269e767SBrooks Davisvalue of 0 disables profiling. 86*8269e767SBrooks Davis.Sh RETURN VALUES 87*8269e767SBrooks Davis.Rv -std profil 88*8269e767SBrooks Davis.Sh FILES 89*8269e767SBrooks Davis.Bl -tag -width /usr/lib/gcrt0.o -compact 90*8269e767SBrooks Davis.It Pa /usr/lib/gcrt0.o 91*8269e767SBrooks Davisprofiling C run-time startup file 92*8269e767SBrooks Davis.It Pa gmon.out 93*8269e767SBrooks Davisconventional name for profiling output file 94*8269e767SBrooks Davis.El 95*8269e767SBrooks Davis.Sh ERRORS 96*8269e767SBrooks DavisThe following error may be reported: 97*8269e767SBrooks Davis.Bl -tag -width Er 98*8269e767SBrooks Davis.It Bq Er EFAULT 99*8269e767SBrooks DavisThe buffer 100*8269e767SBrooks Davis.Fa samples 101*8269e767SBrooks Daviscontains an invalid address. 102*8269e767SBrooks Davis.El 103*8269e767SBrooks Davis.Sh SEE ALSO 104*8269e767SBrooks Davis.Xr gprof 1 105*8269e767SBrooks Davis.Sh HISTORY 106*8269e767SBrooks DavisThe 107*8269e767SBrooks Davis.Fn profil 108*8269e767SBrooks Davisfunctionality first appeared in 109*8269e767SBrooks Davis.At v3 . 110*8269e767SBrooks Davis.Sh BUGS 111*8269e767SBrooks DavisThis routine should be named 112*8269e767SBrooks Davis.Fn profile . 113*8269e767SBrooks Davis.Pp 114*8269e767SBrooks DavisThe 115*8269e767SBrooks Davis.Fa samples 116*8269e767SBrooks Davisargument should really be a vector of type 117*8269e767SBrooks Davis.Fa "unsigned short" . 118*8269e767SBrooks Davis.Pp 119*8269e767SBrooks DavisThe format of the gmon.out file is undocumented. 120