1 /* $NetBSD: gmon.h,v 1.6 1996/11/25 20:08:44 jonathan Exp $ */ 2 3 /*- 4 * Copyright (c) 1982, 1986, 1992, 1993 5 * The Regents of the University of California. All rights reserved. 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 * @(#)gmon.h 8.2 (Berkeley) 1/4/94 36 */ 37 38 #ifndef _SYS_GMON_H_ 39 #define _SYS_GMON_H_ 40 41 #include <machine/profile.h> 42 43 /* 44 * Structure prepended to gmon.out profiling data file. 45 */ 46 struct gmonhdr { 47 u_long lpc; /* base pc address of sample buffer */ 48 u_long hpc; /* max pc address of sampled buffer */ 49 int ncnt; /* size of sample buffer (plus this header) */ 50 int version; /* version number */ 51 int profrate; /* profiling clock rate */ 52 int spare[3]; /* reserved */ 53 }; 54 #define GMONVERSION 0x00051879 55 56 /* 57 * histogram counters are unsigned shorts (according to the kernel). 58 */ 59 #define HISTCOUNTER unsigned short 60 61 /* 62 * fraction of text space to allocate for histogram counters here, 1/2 63 */ 64 #ifndef HISTFRACTION 65 #define HISTFRACTION 2 66 #endif /* HISTFRACTION */ 67 68 /* 69 * Fraction of text space to allocate for from hash buckets. 70 * The value of HASHFRACTION is based on the minimum number of bytes 71 * of separation between two subroutine call points in the object code. 72 * Given MIN_SUBR_SEPARATION bytes of separation the value of 73 * HASHFRACTION is calculated as: 74 * 75 * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); 76 * 77 * For example, on the VAX, the shortest two call sequence is: 78 * 79 * calls $0,(r0) 80 * calls $0,(r0) 81 * 82 * which is separated by only three bytes, thus HASHFRACTION is 83 * calculated as: 84 * 85 * HASHFRACTION = 3 / (2 * 2 - 1) = 1 86 * 87 * Note that the division above rounds down, thus if MIN_SUBR_FRACTION 88 * is less than three, this algorithm will not work! 89 * 90 * In practice, however, call instructions are rarely at a minimal 91 * distance. Hence, we will define HASHFRACTION to be 2 across all 92 * architectures. This saves a reasonable amount of space for 93 * profiling data structures without (in practice) sacrificing 94 * any granularity. 95 */ 96 #define HASHFRACTION 2 97 98 /* 99 * percent of text space to allocate for tostructs with a minimum. 100 */ 101 #define ARCDENSITY 2 102 #define MINARCS 50 103 #define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2) 104 105 struct tostruct { 106 u_long selfpc; 107 long count; 108 u_short link; 109 u_short pad; 110 }; 111 112 /* 113 * a raw arc, with pointers to the calling site and 114 * the called site and a count. 115 */ 116 struct rawarc { 117 u_long raw_frompc; 118 u_long raw_selfpc; 119 long raw_count; 120 }; 121 122 /* 123 * general rounding functions. 124 */ 125 #define ROUNDDOWN(x,y) (((x)/(y))*(y)) 126 #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y)) 127 128 /* 129 * The profiling data structures are housed in this structure. 130 */ 131 struct gmonparam { 132 int state; 133 u_short *kcount; 134 u_long kcountsize; 135 u_short *froms; 136 u_long fromssize; 137 struct tostruct *tos; 138 u_long tossize; 139 long tolimit; 140 u_long lowpc; 141 u_long highpc; 142 u_long textsize; 143 u_long hashfraction; 144 }; 145 extern struct gmonparam _gmonparam; 146 147 /* 148 * Possible states of profiling. 149 */ 150 #define GMON_PROF_ON 0 151 #define GMON_PROF_BUSY 1 152 #define GMON_PROF_ERROR 2 153 #define GMON_PROF_OFF 3 154 155 /* 156 * Sysctl definitions for extracting profiling information from the kernel. 157 */ 158 #define GPROF_STATE 0 /* int: profiling enabling variable */ 159 #define GPROF_COUNT 1 /* struct: profile tick count buffer */ 160 #define GPROF_FROMS 2 /* struct: from location hash bucket */ 161 #define GPROF_TOS 3 /* struct: destination/count structure */ 162 #define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */ 163 #endif /* !_SYS_GMON_H_ */ 164