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