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