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