gmon.h revision 7090
192108Sphk/*-
292108Sphk * Copyright (c) 1982, 1986, 1992, 1993
392108Sphk *	The Regents of the University of California.  All rights reserved.
492108Sphk *
592108Sphk * Redistribution and use in source and binary forms, with or without
692108Sphk * modification, are permitted provided that the following conditions
792108Sphk * are met:
892108Sphk * 1. Redistributions of source code must retain the above copyright
992108Sphk *    notice, this list of conditions and the following disclaimer.
1092108Sphk * 2. Redistributions in binary form must reproduce the above copyright
1192108Sphk *    notice, this list of conditions and the following disclaimer in the
1292108Sphk *    documentation and/or other materials provided with the distribution.
1392108Sphk * 3. All advertising materials mentioning features or use of this software
1492108Sphk *    must display the following acknowledgement:
1592108Sphk *	This product includes software developed by the University of
1692108Sphk *	California, Berkeley and its contributors.
1792108Sphk * 4. Neither the name of the University nor the names of its contributors
1892108Sphk *    may be used to endorse or promote products derived from this software
1992108Sphk *    without specific prior written permission.
2092108Sphk *
2192108Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2292108Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2392108Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2492108Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2592108Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2692108Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2792108Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2892108Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2992108Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3092108Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3192108Sphk * SUCH DAMAGE.
3292108Sphk *
3392108Sphk *	@(#)gmon.h	8.2 (Berkeley) 1/4/94
3492108Sphk * $Id: gmon.h,v 1.3 1995/01/29 06:23:34 bde Exp $
3592108Sphk */
36116196Sobrien
37116196Sobrien#ifndef _SYS_GMON_H_
38116196Sobrien#define _SYS_GMON_H_
3992108Sphk
4092108Sphk#include <machine/profile.h>
4192108Sphk
4292108Sphk/*
4392108Sphk * Structure prepended to gmon.out profiling data file.
44223089Sgibbs */
4592108Sphkstruct gmonhdr {
46238886Smav	u_long	lpc;		/* base pc address of sample buffer */
4792108Sphk	u_long	hpc;		/* max pc address of sampled buffer */
4892108Sphk	int	ncnt;		/* size of sample buffer (plus this header) */
49130712Sphk	int	version;	/* version number */
5092108Sphk	int	profrate;	/* profiling clock rate */
5192108Sphk	int	spare[3];	/* reserved */
5292108Sphk};
5392108Sphk#define GMONVERSION	0x00051879
54114216Skan
5592108Sphk/*
5695323Sphk * histogram counters are unsigned shorts (according to the kernel).
57223089Sgibbs */
5892108Sphk#define	HISTCOUNTER	unsigned short
59223089Sgibbs
60223089Sgibbs/*
61223089Sgibbs * fraction of text space to allocate for histogram counters here, 1/2
62223089Sgibbs */
63223089Sgibbs#define	HISTFRACTION	2
6492108Sphk
6592108Sphk/*
6692108Sphk * Fraction of text space to allocate for from hash buckets.
6792108Sphk * The value of HASHFRACTION is based on the minimum number of bytes
6892108Sphk * of separation between two subroutine call points in the object code.
6992108Sphk * Given MIN_SUBR_SEPARATION bytes of separation the value of
70126080Sphk * HASHFRACTION is calculated as:
71111815Sphk *
72111815Sphk *	HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
73111815Sphk *
74111815Sphk * For example, on the VAX, the shortest two call sequence is:
75111815Sphk *
76111815Sphk *	calls	$0,(r0)
77111815Sphk *	calls	$0,(r0)
78126080Sphk *
7992108Sphk * which is separated by only three bytes, thus HASHFRACTION is
8092108Sphk * calculated as:
8192108Sphk *
8292108Sphk *	HASHFRACTION = 3 / (2 * 2 - 1) = 1
83223089Sgibbs *
8492108Sphk * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
8593248Sphk * is less than three, this algorithm will not work!
86112552Sphk *
87133318Sphk * In practice, however, call instructions are rarely at a minimal
88112552Sphk * distance.  Hence, we will define HASHFRACTION to be 2 across all
89133314Sphk * architectures.  This saves a reasonable amount of space for
90223089Sgibbs * profiling data structures without (in practice) sacrificing
9192108Sphk * any granularity.
9292108Sphk */
93115960Sphk#define	HASHFRACTION	2
94105947Sphk
95105947Sphk/*
96105947Sphk * percent of text space to allocate for tostructs with a minimum.
97115960Sphk */
98105947Sphk#define ARCDENSITY	2
99115960Sphk#define MINARCS		50
100115960Sphk
101115960Sphk/*
102115960Sphk * Limit on the number of arcs to so that arc numbers can be stored in
103105947Sphk * `*froms' and stored and incremented without overflow in links.
104105947Sphk */
105105947Sphk#define MAXARCS		(((u_long)1 << (8 * sizeof(u_short))) - 2)
106223089Sgibbs
107223089Sgibbsstruct tostruct {
108223089Sgibbs	u_long	selfpc;
109238886Smav	long	count;
110238886Smav	u_short	link;
111223089Sgibbs	u_short pad;
112238886Smav};
113238886Smav
114238886Smav/*
115238886Smav * a raw arc, with pointers to the calling site and
116238886Smav * the called site and a count.
117238886Smav */
118238886Smavstruct rawarc {
119238886Smav	u_long	raw_frompc;
120238886Smav	u_long	raw_selfpc;
121238886Smav	long	raw_count;
122238886Smav};
123238886Smav
124238886Smav/*
125223089Sgibbs * general rounding functions.
126223089Sgibbs */
127223089Sgibbs#define ROUNDDOWN(x,y)	(((x)/(y))*(y))
128223089Sgibbs#define ROUNDUP(x,y)	((((x)+(y)-1)/(y))*(y))
129223089Sgibbs
130223089Sgibbs/*
131223089Sgibbs * The profiling data structures are housed in this structure.
132223089Sgibbs */
133223089Sgibbsstruct gmonparam {
134223089Sgibbs	int		state;
135223089Sgibbs	u_short		*kcount;
136223089Sgibbs	u_long		kcountsize;
137223089Sgibbs	u_short		*froms;
138223089Sgibbs	u_long		fromssize;
139223089Sgibbs	struct tostruct	*tos;
140223089Sgibbs	u_long		tossize;
141223089Sgibbs	long		tolimit;
142223089Sgibbs	u_long		lowpc;
143223089Sgibbs	u_long		highpc;
144223089Sgibbs	u_long		textsize;
145223089Sgibbs	u_long		hashfraction;
146223089Sgibbs};
147223089Sgibbsextern struct gmonparam _gmonparam;
148223089Sgibbs
149223089Sgibbs/*
150223089Sgibbs * Possible states of profiling.
151223089Sgibbs */
152223089Sgibbs#define	GMON_PROF_ON	0
153223089Sgibbs#define	GMON_PROF_BUSY	1
154119593Sphk#define	GMON_PROF_ERROR	2
155130585Sphk#define	GMON_PROF_OFF	3
156119593Sphk
157119593Sphk#ifdef KERNEL
158119593Sphkvoid	kmstartup __P((void));
159135716Sphk#endif
160119593Sphk
161119593Sphk/*
162135716Sphk * Sysctl definitions for extracting profiling information from the kernel.
163143790Sphk */
164143790Sphk#define	GPROF_STATE	0	/* int: profiling enabling variable */
165119593Sphk#define	GPROF_COUNT	1	/* struct: profile tick count buffer */
166119593Sphk#define	GPROF_FROMS	2	/* struct: from location hash bucket */
167119593Sphk#define	GPROF_TOS	3	/* struct: destination/count structure */
16892108Sphk#define	GPROF_GMONPARAM	4	/* struct: profiling parameters (see above) */
16993250Sphk#endif /* !_SYS_GMON_H_ */
17092108Sphk