xref: /titanic_44/usr/src/cmd/sgs/prof/common/profv.h (revision 159d09a20817016f09b3ea28d1bdada4a336bb91)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
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 #include "_machelf.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  * File status.
167  */
168 extern struct stat	aout_stat, monout_stat;
169 
170 /*
171  * Timing related externs.
172  */
173 extern bool	time_in_ticks;
174 extern size_t	n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
175 extern double	total_time;
176 
177 /*
178  * Other declarations
179  */
180 extern void	profver(void);
181 extern nltype	*nllookup(mod_info_t *, Address, Address *);
182 extern Address	*locate(Address *, size_t, Address);
183 extern void	get_syms(char *, mod_info_t *);
184 extern int	cmp_by_address(const void *arg1, const void *arg2);
185 extern bool	is_shared_obj(char *);
186 
187 #ifdef	__cplusplus
188 }
189 #endif
190 
191 #endif	/* _SGS_PROFV_H */
192