1.\"	$NetBSD: profil.2,v 1.14 2016/06/18 14:39:15 kamil 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. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"	@(#)profil.2	8.1 (Berkeley) 6/4/93
34.\"
35.Dd June 4, 1993
36.Dt PROFIL 2
37.Os
38.Sh NAME
39.Nm profil
40.Nd control process profiling
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In unistd.h
45.Ft int
46.Fn profil "char *samples" "size_t size" "unsigned long offset" "unsigned int scale"
47.Sh DESCRIPTION
48The
49.Fn profil
50function enables or disables
51program counter profiling of the current process.
52If profiling is enabled,
53then at every clock tick,
54the kernel updates an appropriate count in the
55.Fa samples
56buffer.
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 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
76parameter is the lowest address at which
77the kernel takes program counter samples.
78The
79.Fa scale
80parameter 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
89If the
90.Fa scale
91value is nonzero and the buffer
92.Fa samples
93contains an illegal address,
94.Fn profil
95returns \-1,
96profiling is terminated and
97.Va errno
98is set appropriately.
99Otherwise
100.Fn profil
101returns 0.
102.Sh FILES
103.Bl -tag -width /usr/lib/gcrt0.o -compact
104.It Pa /usr/lib/gcrt0.o
105profiling C run-time startup file
106.It Pa gmon.out
107conventional name for profiling output file.
108This may be different if the PROFDIR environment variable is set.
109.El
110.Sh ERRORS
111The following error may be reported:
112.Bl -tag -width Er
113.It Bq Er EFAULT
114The buffer
115.Fa samples
116contains an invalid address.
117.El
118.Sh SEE ALSO
119.Xr gprof 1 ,
120.Xr moncontrol 3
121.\" .Sh HISTORY
122.\" wish I knew...  probably v7.
123.Sh BUGS
124This routine should be named
125.Fn profile .
126.Pp
127The
128.Fa samples
129argument should really be a vector of type
130.Fa "unsigned short" .
131.Pp
132The format of the gmon.out file is undocumented.
133