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