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. 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.\" @(#)profil.2 8.1 (Berkeley) 6/4/93 32.\" 33.Dd December 1, 2017 34.Dt PROFIL 2 35.Os 36.Sh NAME 37.Nm profil 38.Nd control process profiling 39.Sh LIBRARY 40.Lb libc 41.Sh SYNOPSIS 42.In unistd.h 43.Ft int 44.Fn profil "char *samples" "size_t size" "vm_offset_t offset" "int scale" 45.Sh DESCRIPTION 46The 47.Fn profil 48system call enables or disables 49program counter profiling of the current process. 50If profiling is enabled, 51then at every profiling clock tick, 52the kernel updates an appropriate count in the 53.Fa samples 54buffer. 55The frequency of the profiling clock is recorded 56in the header in the profiling output file. 57.Pp 58The buffer 59.Fa samples 60contains 61.Fa size 62bytes and is divided into 63a series of 16-bit bins. 64Each bin counts the number of times the program counter 65was in a particular address range in the process 66when a profiling clock tick occurred while profiling was enabled. 67For a given program counter address, 68the number of the corresponding bin is given 69by the relation: 70.Bd -literal -offset indent 71[(pc - offset) / 2] * scale / 65536 72.Ed 73.Pp 74The 75.Fa offset 76argument is the lowest address at which 77the kernel takes program counter samples. 78The 79.Fa scale 80argument ranges from 1 to 65536 and 81can be used to change the span of the bins. 82A scale of 65536 maps each bin to 2 bytes of address range; 83a scale of 32768 gives 4 bytes, 16384 gives 8 bytes and so on. 84Intermediate values provide approximate intermediate ranges. 85A 86.Fa scale 87value of 0 disables profiling. 88.Sh RETURN VALUES 89.Rv -std profil 90.Sh FILES 91.Bl -tag -width /usr/lib/gcrt0.o -compact 92.It Pa /usr/lib/gcrt0.o 93profiling C run-time startup file 94.It Pa gmon.out 95conventional name for profiling output file 96.El 97.Sh ERRORS 98The following error may be reported: 99.Bl -tag -width Er 100.It Bq Er EFAULT 101The buffer 102.Fa samples 103contains an invalid address. 104.El 105.Sh SEE ALSO 106.Xr gprof 1 107.Sh HISTORY 108The 109.Fn profil 110functionality first appeared in 111.At v3 . 112.Sh BUGS 113This routine should be named 114.Fn profile . 115.Pp 116The 117.Fa samples 118argument should really be a vector of type 119.Fa "unsigned short" . 120.Pp 121The format of the gmon.out file is undocumented. 122