xref: /illumos-gate/usr/src/cmd/sgs/include/profile.h (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef	_ASM
35 
36 #include <sys/types.h>
37 #include <synch.h>
38 #include <link.h>
39 
40 /*
41  * The profile buffer created by ld.so.1 consists of 3 sections; the header,
42  * the profil(2) buffer, and an array of call graph arc structures.
43  */
44 
45 typedef struct l_hdr {			/* Linker profile buffer header */
46 	unsigned int	hd_magic;	/* identifier for file */
47 	unsigned int	hd_version;	/* version for rtld prof file */
48 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
49 	caddr_t		hd_hpc;		/* Relative high pc address */
50 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
51 	unsigned int	hd_fsize;	/* Size of file */
52 	unsigned int	hd_ncndx;	/* Next (and last) index into */
53 	unsigned int	hd_lcndx;	/*	call graph arc structure */
54 } L_hdr;
55 
56 
57 /*
58  * The *64 structs are for gprof, as a 32-bit program,
59  * to read 64-bit profiles correctly.
60  */
61 
62 typedef struct l_hdr64 {		/* Linker profile buffer header */
63 	unsigned int	hd_magic;	/* identifier for file */
64 	unsigned int	hd_version;	/* version for rtld prof file */
65 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
66 	u_longlong_t	hd_hpc;		/* Relative high pc address */
67 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
68 	unsigned int	hd_fsize;	/* Size of file */
69 	unsigned int	hd_ncndx;	/* Next (and last) index into */
70 	unsigned int	hd_lcndx;	/*	call graph arc structure */
71 } L_hdr64;
72 
73 
74 
75 typedef struct l_cgarc {		/* Linker call graph arc entry */
76 	caddr_t		cg_from;	/* Source of call */
77 	caddr_t		cg_to;		/* Destination of call */
78 	unsigned int	cg_count;	/* Instance count */
79 	unsigned int	cg_next;	/* Link index for multiple sources */
80 } L_cgarc;
81 
82 
83 typedef struct l_cgarc64 {		/* Linker call graph arc entry */
84 	u_longlong_t	cg_from;	/* Source of call */
85 	u_longlong_t	cg_to;		/* Destination of call */
86 	unsigned int	cg_count;	/* Instance count */
87 	unsigned int	cg_next;	/* Link index for multiple sources */
88 } L_cgarc64;
89 
90 
91 
92 /*
93  * Generic defines for creating profiled output buffer.
94  */
95 
96 #define	PRF_BARSIZE	2		/* No. of program bytes that */
97 					/* correspond to each histogram */
98 					/* bar in the profil(2) buffer */
99 #define	PRF_SCALE	0x8000		/* Scale to provide above */
100 					/* histogram correspondence */
101 #define	PRF_CGNUMB	256		/* Size of call graph extension */
102 #define	PRF_CGINIT	2		/* Initial symbol blocks to allocate */
103 					/*	for the call graph structure */
104 #define	PRF_OUTADDR	(caddr_t)-1	/* Function addresses outside of */
105 					/*	the range being monitored */
106 #define	PRF_OUTADDR64	(u_longlong_t)-1	/* Function addresses outside */
107 					/*	of the range being monitored */
108 #define	PRF_UNKNOWN	(caddr_t)-2	/* Unknown function address */
109 
110 #define	PRF_ROUNDUP(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
111 #define	PRF_ROUNDWN(x, a) ((x) & ~((a) - 1))
112 
113 #define	PRF_MAGIC	0xffffffff	/* unique number to differentiate */
114 					/* profiled file from gmon.out for */
115 					/* gprof */
116 #define	PRF_VERSION	0x1		/* current PROF file version */
117 #define	PRF_VERSION_64	0x2		/* 64-bit current PROF file version */
118 
119 
120 /*
121  * Related data and function definitions.
122  */
123 
124 extern	int		profile_rtld;		/* Rtld is being profiled */
125 
126 extern	uintptr_t (*	p_cg_interp)(int, caddr_t, caddr_t);
127 
128 #endif
129 
130 #ifdef	__cplusplus
131 }
132 #endif
133 
134 #endif /* _PROFILE_H */
135