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