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