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