xref: /onnv-gate/usr/src/cmd/sgs/include/profile.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright 2001,2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  *	Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_PROFILE_H
28*0Sstevel@tonic-gate #define	_PROFILE_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #ifndef	_ASM
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include <sys/types.h>
39*0Sstevel@tonic-gate #include <synch.h>
40*0Sstevel@tonic-gate #include <link.h>
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * The profile buffer created by ld.so.1 consists of 3 sections; the header,
44*0Sstevel@tonic-gate  * the profil(2) buffer, and an array of call graph arc structures.
45*0Sstevel@tonic-gate  */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate typedef struct l_hdr {			/* Linker profile buffer header */
48*0Sstevel@tonic-gate 	unsigned int	hd_magic;	/* identifier for file */
49*0Sstevel@tonic-gate 	unsigned int	hd_version;	/* version for rtld prof file */
50*0Sstevel@tonic-gate 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
51*0Sstevel@tonic-gate 	caddr_t		hd_hpc;		/* Relative high pc address */
52*0Sstevel@tonic-gate 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
53*0Sstevel@tonic-gate 	unsigned int	hd_fsize;	/* Size of file */
54*0Sstevel@tonic-gate 	unsigned int	hd_ncndx;	/* Next (and last) index into */
55*0Sstevel@tonic-gate 	unsigned int	hd_lcndx;	/*	call graph arc structure */
56*0Sstevel@tonic-gate } L_hdr;
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * The *64 structs are for gprof, as a 32-bit program,
61*0Sstevel@tonic-gate  * to read 64-bit profiles correctly.
62*0Sstevel@tonic-gate  */
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate typedef struct l_hdr64 {		/* Linker profile buffer header */
65*0Sstevel@tonic-gate 	unsigned int	hd_magic;	/* identifier for file */
66*0Sstevel@tonic-gate 	unsigned int	hd_version;	/* version for rtld prof file */
67*0Sstevel@tonic-gate 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
68*0Sstevel@tonic-gate 	u_longlong_t	hd_hpc;		/* Relative high pc address */
69*0Sstevel@tonic-gate 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
70*0Sstevel@tonic-gate 	unsigned int	hd_fsize;	/* Size of file */
71*0Sstevel@tonic-gate 	unsigned int	hd_ncndx;	/* Next (and last) index into */
72*0Sstevel@tonic-gate 	unsigned int	hd_lcndx;	/*	call graph arc structure */
73*0Sstevel@tonic-gate } L_hdr64;
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate typedef struct l_cgarc {		/* Linker call graph arc entry */
78*0Sstevel@tonic-gate 	caddr_t		cg_from;	/* Source of call */
79*0Sstevel@tonic-gate 	caddr_t		cg_to;		/* Destination of call */
80*0Sstevel@tonic-gate 	unsigned int	cg_count;	/* Instance count */
81*0Sstevel@tonic-gate 	unsigned int	cg_next;	/* Link index for multiple sources */
82*0Sstevel@tonic-gate } L_cgarc;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate typedef struct l_cgarc64 {		/* Linker call graph arc entry */
86*0Sstevel@tonic-gate 	u_longlong_t	cg_from;	/* Source of call */
87*0Sstevel@tonic-gate 	u_longlong_t	cg_to;		/* Destination of call */
88*0Sstevel@tonic-gate 	unsigned int	cg_count;	/* Instance count */
89*0Sstevel@tonic-gate 	unsigned int	cg_next;	/* Link index for multiple sources */
90*0Sstevel@tonic-gate } L_cgarc64;
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /*
94*0Sstevel@tonic-gate  * Snapshots of this profile buffer are taken by `ldmon' and packaged into
95*0Sstevel@tonic-gate  * a gmon.out file appropriate for analysis by gprof(1).  This gmon file
96*0Sstevel@tonic-gate  * consists of three sections (taken from gmon.h); a header, a profil(2)
97*0Sstevel@tonic-gate  * buffer, and an array of call graph arc structures.
98*0Sstevel@tonic-gate  */
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate typedef struct m_hdr {			/* Monitor profile buffer header */
101*0Sstevel@tonic-gate 	char		*hd_lpc;		/* Low pc value */
102*0Sstevel@tonic-gate 	char		*hd_hpc;		/* High pc value */
103*0Sstevel@tonic-gate 	int		hd_off;		/* Offset into call graph array */
104*0Sstevel@tonic-gate } M_hdr;
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate typedef struct m_hdr64 {		/* Monitor profile buffer header */
107*0Sstevel@tonic-gate 	u_longlong_t	hd_lpc;		/* Low pc value */
108*0Sstevel@tonic-gate 	u_longlong_t	hd_hpc;		/* High pc value */
109*0Sstevel@tonic-gate 	int		hd_off;		/* Offset into call graph array */
110*0Sstevel@tonic-gate } M_hdr64;
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate typedef struct m_cgarc {		/* Monitor call graph arc entry */
113*0Sstevel@tonic-gate 	unsigned int	cg_from;	/* Source of call */
114*0Sstevel@tonic-gate 	unsigned int	cg_to;		/* Destination of call */
115*0Sstevel@tonic-gate 	int		cg_count;	/* Instance count */
116*0Sstevel@tonic-gate } M_cgarc;
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate typedef struct m_cnt {			/* Prof(1) function count structure */
119*0Sstevel@tonic-gate 	char		*fc_fnpc;	/* Called functions address */
120*0Sstevel@tonic-gate 	int		fc_mcnt;	/* Instance count */
121*0Sstevel@tonic-gate } M_cnt;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate #define	PROF_LIBRARY	"ldprofile.so.1"
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate /*
127*0Sstevel@tonic-gate  * Generic defines for creating profiled output buffer.
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate #define	PRF_BARSIZE	2		/* No. of program bytes that */
131*0Sstevel@tonic-gate 					/* correspond to each histogram */
132*0Sstevel@tonic-gate 					/* bar in the profil(2) buffer */
133*0Sstevel@tonic-gate #define	PRF_SCALE	0x8000		/* Scale to provide above */
134*0Sstevel@tonic-gate 					/* histogram correspondence */
135*0Sstevel@tonic-gate #define	PRF_CGNUMB	256		/* Size of call graph extension */
136*0Sstevel@tonic-gate #define	PRF_CGINIT	2		/* Initial symbol blocks to allocate */
137*0Sstevel@tonic-gate 					/*	for the call graph structure */
138*0Sstevel@tonic-gate #define	PRF_OUTADDR	(caddr_t)-1	/* Function addresses outside of */
139*0Sstevel@tonic-gate 					/*	the range being monitored */
140*0Sstevel@tonic-gate #define	PRF_OUTADDR64	(u_longlong_t)-1	/* Function addresses outside */
141*0Sstevel@tonic-gate 					/*	of the range being monitored */
142*0Sstevel@tonic-gate #define	PRF_UNKNOWN	(caddr_t)-2	/* Unknown function address */
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate #define	PRF_ROUNDUP(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
145*0Sstevel@tonic-gate #define	PRF_ROUNDWN(x, a) ((x) & ~((a) - 1))
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate #define	PRF_MAGIC	0xffffffff	/* unique number to differentiate */
148*0Sstevel@tonic-gate 					/* profiled file from gmon.out for */
149*0Sstevel@tonic-gate 					/* gprof */
150*0Sstevel@tonic-gate #define	PRF_VERSION	0x1		/* current PROF file version */
151*0Sstevel@tonic-gate #define	PRF_VERSION_64	0x2		/* 64-bit current PROF file version */
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate  * Related data and function definitions.
156*0Sstevel@tonic-gate  */
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate extern	int		profile_rtld;		/* Rtld is being profiled */
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate extern	uintptr_t (*	p_cg_interp)(int, caddr_t, caddr_t);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate #endif
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #ifdef	__cplusplus
165*0Sstevel@tonic-gate }
166*0Sstevel@tonic-gate #endif
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate #endif /* _PROFILE_H */
169