1.\" Copyright (c) 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Donn Seeley of BSDI. 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. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)profil.2 8.1 (Berkeley) 6/4/93 36.\" 37.Dd "June 4, 1993" 38.Dt PROFIL 2 39.Os 40.Sh NAME 41.Nm profil 42.Nd control process profiling 43.Sh SYNOPSIS 44.Ft int 45.Fn profil "char *samples" "int size" "int offset" "int scale" 46.Sh DESCRIPTION 47The 48.Fn profil 49function enables or disables 50program counter profiling of the current process. 51If profiling is enabled, 52then at every clock tick, 53the kernel updates an appropriate count in the 54.Fa samples 55buffer. 56.Pp 57The buffer 58.Fa samples 59contains 60.Fa size 61bytes and is divided into 62a series of 16-bit bins. 63Each bin counts the number of times the program counter 64was in a particular address range in the process 65when a clock tick occurred while profiling was enabled. 66For a given program counter address, 67the number of the corresponding bin is given 68by the relation: 69.Bd -literal -offset indent 70[(pc - offset) / 2] * scale / 65536 71.Ed 72.Pp 73The 74.Fa offset 75parameter is the lowest address at which 76the kernel takes program counter samples. 77The 78.Fa scale 79parameter ranges from 1 to 65536 and 80can be used to change the span of the bins. 81A scale of 65536 maps each bin to 2 bytes of address range; 82a scale of 32768 gives 4 bytes, 16384 gives 8 bytes and so on. 83Intermediate values provide approximate intermediate ranges. 84A 85.Fa scale 86value of 0 disables profiling. 87.Sh RETURN VALUES 88If the 89.Fa scale 90value is nonzero and the buffer 91.Fa samples 92contains an illegal address, 93.Fn profil 94returns \-1, 95profiling is terminated and 96.Va errno 97is set appropriately. 98Otherwise 99.Fn profil 100returns 0. 101.Sh FILES 102.Bl -tag -width /usr/lib/gcrt0.o -compact 103.It Pa /usr/lib/gcrt0.o 104profiling C run-time startup file 105.It Pa gmon.out 106conventional name for profiling output file 107.El 108.Sh ERRORS 109The following error may be reported: 110.Bl -tag -width Er 111.It Bq Er EFAULT 112The buffer 113.Fa samples 114contains an invalid address. 115.El 116.Sh SEE ALSO 117.Xr gprof 1 118.\" .Sh HISTORY 119.\" wish I knew... probably v7. 120.Sh BUGS 121This routine should be named 122.Fn profile . 123.Pp 124The 125.Fa samples 126argument should really be a vector of type 127.Fa "unsigned short" . 128.Pp 129The format of the gmon.out file is undocumented. 130