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