]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/gmon.h
6a294ca2d869ae3c8f4ff54cde4a0cf3707923a3
[apple/xnu.git] / bsd / sys / gmon.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
31 /*-
32 * Copyright (c) 1982, 1986, 1992, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * @(#)gmon.h 8.2 (Berkeley) 1/4/94
64 */
65
66 #ifndef _SYS_GMON_H_
67 #define _SYS_GMON_H_
68
69 /*
70 * Structure prepended to gmon.out profiling data file.
71 */
72 struct gmonhdr {
73 u_long lpc; /* base pc address of sample buffer */
74 u_long hpc; /* max pc address of sampled buffer */
75 int ncnt; /* size of sample buffer (plus this header) */
76 int version; /* version number */
77 int profrate; /* profiling clock rate */
78 int spare[3]; /* reserved */
79 };
80 #define GMONVERSION 0x00051879
81
82 /*
83 * histogram counters are unsigned shorts (according to the kernel).
84 */
85 #define HISTCOUNTER unsigned short
86
87 /*
88 * fraction of text space to allocate for histogram counters here, 1/2
89 */
90 #define HISTFRACTION 2
91
92 /*
93 * Fraction of text space to allocate for from hash buckets.
94 * The value of HASHFRACTION is based on the minimum number of bytes
95 * of separation between two subroutine call points in the object code.
96 * Given MIN_SUBR_SEPARATION bytes of separation the value of
97 * HASHFRACTION is calculated as:
98 *
99 * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
100 *
101 * For example, on the VAX, the shortest two call sequence is:
102 *
103 * calls $0,(r0)
104 * calls $0,(r0)
105 *
106 * which is separated by only three bytes, thus HASHFRACTION is
107 * calculated as:
108 *
109 * HASHFRACTION = 3 / (2 * 2 - 1) = 1
110 *
111 * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
112 * is less than three, this algorithm will not work!
113 *
114 * In practice, however, call instructions are rarely at a minimal
115 * distance. Hence, we will define HASHFRACTION to be 2 across all
116 * architectures. This saves a reasonable amount of space for
117 * profiling data structures without (in practice) sacrificing
118 * any granularity.
119 */
120 #define HASHFRACTION 2
121
122 /*
123 * percent of text space to allocate for tostructs with a minimum.
124 */
125 #define ARCDENSITY 2
126 #define MINARCS 50
127 #define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2)
128
129 struct tostruct {
130 u_long selfpc;
131 long count;
132 u_short link;
133 u_short order;
134 };
135
136 /*
137 * a raw arc, with pointers to the calling site and
138 * the called site and a count.
139 */
140 struct rawarc {
141 u_long raw_frompc;
142 u_long raw_selfpc;
143 long raw_count;
144 };
145
146 /*
147 * general rounding functions.
148 */
149 #define ROUNDDOWN(x,y) (((x)/(y))*(y))
150 #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
151
152 /*
153 * The profiling data structures are housed in this structure.
154 */
155 struct gmonparam {
156 int state;
157 u_short *kcount;
158 u_long kcountsize;
159 u_short *froms;
160 u_long fromssize;
161 struct tostruct *tos;
162 u_long tossize;
163 long tolimit;
164 u_long lowpc;
165 u_long highpc;
166 u_long textsize;
167 u_long hashfraction;
168 };
169 extern struct gmonparam _gmonparam;
170
171 /*
172 * Possible states of profiling.
173 */
174 #define GMON_PROF_ON 0
175 #define GMON_PROF_BUSY 1
176 #define GMON_PROF_ERROR 2
177 #define GMON_PROF_OFF 3
178
179 /*
180 * Sysctl definitions for extracting profiling information from the kernel.
181 */
182 #define GPROF_STATE 0 /* int: profiling enabling variable */
183 #define GPROF_COUNT 1 /* struct: profile tick count buffer */
184 #define GPROF_FROMS 2 /* struct: from location hash bucket */
185 #define GPROF_TOS 3 /* struct: destination/count structure */
186 #define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */
187
188 /*
189 * In order to support more information than in the original mon.out and
190 * gmon.out files there is an alternate gmon.out file format. The alternate
191 * gmon.out file format starts with a magic number then separates the
192 * information with gmon_data structs.
193 */
194 #define GMON_MAGIC 0xbeefbabe
195 struct gmon_data {
196 unsigned long type; /* constant for type of data following this struct */
197 unsigned long size; /* size in bytes of the data following this struct */
198 };
199
200 /*
201 * The GMONTYPE_SAMPLES gmon_data.type is for the histogram counters described
202 * above and has a struct gmonhdr followed by the counters.
203 */
204 #define GMONTYPE_SAMPLES 1
205 /*
206 * The GMONTYPE_RAWARCS gmon_data.type is for the raw arcs described above.
207 */
208 #define GMONTYPE_RAWARCS 2
209 /*
210 * The GMONTYPE_ARCS_ORDERS gmon_data.type is for the raw arcs with a call
211 * order field. The order is the order is a sequence number for the order each
212 * call site was executed. Raw_order values start at 1 not zero. Other than
213 * the raw_order field this is the same information as in the struct rawarc.
214 */
215 #define GMONTYPE_ARCS_ORDERS 3
216 struct rawarc_order {
217 unsigned long raw_frompc;
218 unsigned long raw_selfpc;
219 unsigned long raw_count;
220 unsigned long raw_order;
221 };
222 /*
223 * The GMONTYPE_DYLD_STATE gmon_data.type is for the dynamic link editor state
224 * of the program.
225 * The informations starts with an unsigned long with the count of states:
226 * image_count
227 * Then each state follows in the file. The state is made up of
228 * image_header (the address where dyld loaded this image)
229 * vmaddr_slide (the amount dyld slid this image from it's vmaddress)
230 * name (the file name dyld loaded this image from)
231 */
232 #define GMONTYPE_DYLD_STATE 4
233 #endif /* !_SYS_GMON_H_ */