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