xref: /titanic_44/usr/src/cmd/sgs/prof/common/profv.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_SGS_PROFV_H
29 #define	_SGS_PROFV_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  * Header file for processing versioned, *new-style* mon.out files.
35  */
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <stdio.h>
42 #include <sys/types.h>
43 #include <sys/mman.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46 #include <unistd.h>
47 #include <sys/elf.h>
48 #include "gelf.h"
49 #include "monv.h"
50 
51 /*
52  * Booleans.
53  */
54 typedef int	bool;
55 
56 #define	TRUE	1
57 #define	FALSE	0
58 
59 /*
60  * Bit macro and flag bit definitions. These and the sort_flags below,
61  * need to be always in sync with the set in prof.c
62  */
63 extern int		flags;
64 
65 #define	F_SORT		0x1
66 #define	F_VERBOSE	0x2
67 #define	F_ZSYMS		0x4
68 #define	F_PADDR		0x8
69 #define	F_NHEAD		0x10
70 
71 /*
72  * Sort flags. Mutually exclusive.
73  */
74 extern unsigned char	sort_flag;
75 
76 #define	BY_ADDRESS	0x1
77 #define	BY_NCALLS	0x2
78 #define	BY_NAME		0x4
79 #define	BY_TIME		0x8
80 
81 /*
82  * Error codes
83  */
84 #define	ERR_SYSCALL	1
85 #define	ERR_INPUT	2
86 #define	ERR_ELF		3
87 #define	ERR_MEMORY	4
88 
89 /*
90  * Other useful macros.
91  */
92 #define	BUCKET_SZ	4096
93 #define	PRF_END		"_end"
94 
95 extern int		gflag, Cflag;
96 extern char		*atitle, *aformat,
97 			*cmdname, *sym_fn, *mon_fn;
98 
99 /*
100  * Module info.
101  */
102 struct mod_info {
103 	char		*path;		/* pathname of module */
104 	int		id;		/* id (used while printing) */
105 	bool		active;		/* is this module active or not ? */
106 	Address		load_base;	/* base addr where module is loaded */
107 	Address		load_end;	/* end addr of loaded module */
108 	GElf_Addr	txt_origin;	/* txt start as given in PHT */
109 	GElf_Addr	data_end;	/* data end as found from `_end' */
110 	struct nl	*nl;		/* ptr to module's namelist */
111 	size_t		nfuncs;		/* number of functions in `nl' */
112 	struct mod_info	*next;		/* link to next module */
113 };
114 typedef struct mod_info	mod_info_t;
115 
116 /*
117  * List of shared objects. Note that this always includes the program
118  * executable as the first element.
119  */
120 extern mod_info_t	modules;
121 extern size_t		n_modules;
122 
123 /*
124  * The symbol table.
125  */
126 struct nl {
127 	char		*name;		/* name of the symbol */
128 	GElf_Addr	value;		/* value of the symbol */
129 	unsigned char	info;		/* symbol's bind/type info */
130 	GElf_Xword	size;		/* size of the symbol */
131 	size_t		ncalls;		/* number of calls to this func */
132 	size_t		nticks;		/* number of ticks spent here */
133 };
134 typedef struct nl	nltype;
135 
136 /*
137  * The profile output record. There is some duplication of fields from
138  * the namelist, but the profsym contains just the symbols we're going
139  * to print, and that makes a lot of things easier.
140  */
141 struct profrec {
142 	GElf_Addr	addr;			/* symbol value */
143 	double		percent_time;		/* percentage time spent here */
144 	double		seconds;		/* time spent here in seconds */
145 	size_t		ncalls;			/* calls to this function */
146 	double		msecs_per_call;		/* milliseconds per call */
147 	char		*demangled_name;	/* demangled name if C++ */
148 	bool		print_mid;		/* print module id ? */
149 	char		*name;			/* bookkeeping, not printed */
150 	mod_info_t	*module;		/* bookkeeping, not printed */
151 };
152 typedef struct profrec	profrec_t;
153 extern profrec_t	*profsym;
154 
155 /*
156  * Names in profile output need to be sorted to figure out if there'll
157  * be any duplicate names in the output.
158  */
159 struct profnames {
160 	char		*name;
161 	profrec_t	*pfrec;
162 };
163 typedef struct profnames	profnames_t;
164 
165 /*
166  * st_info is the same size (1 byte) in both ELF64 and ELF32
167  */
168 #define	ELF_ST_TYPE(info)	ELF64_ST_TYPE(info)
169 #define	ELF_ST_BIND(info)	ELF64_ST_BIND(info)
170 
171 /*
172  * File status.
173  */
174 extern struct stat	aout_stat, monout_stat;
175 
176 /*
177  * Timing related externs.
178  */
179 extern bool	time_in_ticks;
180 extern size_t	n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
181 extern double	total_time;
182 
183 /*
184  * Imported declarations
185  */
186 extern char	*sgs_demangle(char *);
187 
188 /*
189  * Other declarations
190  */
191 extern void	profver(void);
192 extern nltype	*nllookup(mod_info_t *, Address, Address *);
193 extern Address	*locate(Address *, size_t, Address);
194 extern void	get_syms(char *, mod_info_t *);
195 extern int	cmp_by_address(const void *arg1, const void *arg2);
196 extern bool	is_shared_obj(char *);
197 
198 #ifdef	__cplusplus
199 }
200 #endif
201 
202 #endif	/* _SGS_PROFV_H */
203