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