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