xref: /onnv-gate/usr/src/cmd/sgs/prof/common/profv.h (revision 7008:8f7bd4ba8aeb)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7008Sab196087  * Common Development and Distribution License (the "License").
6*7008Sab196087  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21211Smike_s 
220Sstevel@tonic-gate /*
23*7008Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24211Smike_s  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SGS_PROFV_H
280Sstevel@tonic-gate #define	_SGS_PROFV_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * Header file for processing versioned, *new-style* mon.out files.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <stdio.h>
410Sstevel@tonic-gate #include <sys/types.h>
420Sstevel@tonic-gate #include <sys/mman.h>
430Sstevel@tonic-gate #include <sys/stat.h>
440Sstevel@tonic-gate #include <fcntl.h>
450Sstevel@tonic-gate #include <unistd.h>
460Sstevel@tonic-gate #include <sys/elf.h>
470Sstevel@tonic-gate #include "gelf.h"
480Sstevel@tonic-gate #include "monv.h"
49*7008Sab196087 #include "_machelf.h"
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Booleans.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate typedef int	bool;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #define	TRUE	1
570Sstevel@tonic-gate #define	FALSE	0
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * Bit macro and flag bit definitions. These and the sort_flags below,
610Sstevel@tonic-gate  * need to be always in sync with the set in prof.c
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate extern int		flags;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #define	F_SORT		0x1
660Sstevel@tonic-gate #define	F_VERBOSE	0x2
670Sstevel@tonic-gate #define	F_ZSYMS		0x4
680Sstevel@tonic-gate #define	F_PADDR		0x8
690Sstevel@tonic-gate #define	F_NHEAD		0x10
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Sort flags. Mutually exclusive.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate extern unsigned char	sort_flag;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	BY_ADDRESS	0x1
770Sstevel@tonic-gate #define	BY_NCALLS	0x2
780Sstevel@tonic-gate #define	BY_NAME		0x4
790Sstevel@tonic-gate #define	BY_TIME		0x8
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * Error codes
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate #define	ERR_SYSCALL	1
850Sstevel@tonic-gate #define	ERR_INPUT	2
860Sstevel@tonic-gate #define	ERR_ELF		3
870Sstevel@tonic-gate #define	ERR_MEMORY	4
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * Other useful macros.
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate #define	BUCKET_SZ	4096
930Sstevel@tonic-gate #define	PRF_END		"_end"
940Sstevel@tonic-gate 
950Sstevel@tonic-gate extern int		gflag, Cflag;
960Sstevel@tonic-gate extern char		*atitle, *aformat,
970Sstevel@tonic-gate 			*cmdname, *sym_fn, *mon_fn;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * Module info.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate struct mod_info {
1030Sstevel@tonic-gate 	char		*path;		/* pathname of module */
1040Sstevel@tonic-gate 	int		id;		/* id (used while printing) */
1050Sstevel@tonic-gate 	bool		active;		/* is this module active or not ? */
1060Sstevel@tonic-gate 	Address		load_base;	/* base addr where module is loaded */
1070Sstevel@tonic-gate 	Address		load_end;	/* end addr of loaded module */
1080Sstevel@tonic-gate 	GElf_Addr	txt_origin;	/* txt start as given in PHT */
1090Sstevel@tonic-gate 	GElf_Addr	data_end;	/* data end as found from `_end' */
1100Sstevel@tonic-gate 	struct nl	*nl;		/* ptr to module's namelist */
1110Sstevel@tonic-gate 	size_t		nfuncs;		/* number of functions in `nl' */
1120Sstevel@tonic-gate 	struct mod_info	*next;		/* link to next module */
1130Sstevel@tonic-gate };
1140Sstevel@tonic-gate typedef struct mod_info	mod_info_t;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  * List of shared objects. Note that this always includes the program
1180Sstevel@tonic-gate  * executable as the first element.
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate extern mod_info_t	modules;
1210Sstevel@tonic-gate extern size_t		n_modules;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * The symbol table.
1250Sstevel@tonic-gate  */
1260Sstevel@tonic-gate struct nl {
1270Sstevel@tonic-gate 	char		*name;		/* name of the symbol */
1280Sstevel@tonic-gate 	GElf_Addr	value;		/* value of the symbol */
1290Sstevel@tonic-gate 	unsigned char	info;		/* symbol's bind/type info */
1300Sstevel@tonic-gate 	GElf_Xword	size;		/* size of the symbol */
1310Sstevel@tonic-gate 	size_t		ncalls;		/* number of calls to this func */
1320Sstevel@tonic-gate 	size_t		nticks;		/* number of ticks spent here */
1330Sstevel@tonic-gate };
1340Sstevel@tonic-gate typedef struct nl	nltype;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * The profile output record. There is some duplication of fields from
1380Sstevel@tonic-gate  * the namelist, but the profsym contains just the symbols we're going
1390Sstevel@tonic-gate  * to print, and that makes a lot of things easier.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate struct profrec {
1420Sstevel@tonic-gate 	GElf_Addr	addr;			/* symbol value */
1430Sstevel@tonic-gate 	double		percent_time;		/* percentage time spent here */
1440Sstevel@tonic-gate 	double		seconds;		/* time spent here in seconds */
1450Sstevel@tonic-gate 	size_t		ncalls;			/* calls to this function */
1460Sstevel@tonic-gate 	double		msecs_per_call;		/* milliseconds per call */
1470Sstevel@tonic-gate 	char		*demangled_name;	/* demangled name if C++ */
1480Sstevel@tonic-gate 	bool		print_mid;		/* print module id ? */
1490Sstevel@tonic-gate 	char		*name;			/* bookkeeping, not printed */
1500Sstevel@tonic-gate 	mod_info_t	*module;		/* bookkeeping, not printed */
1510Sstevel@tonic-gate };
1520Sstevel@tonic-gate typedef struct profrec	profrec_t;
1530Sstevel@tonic-gate extern profrec_t	*profsym;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate  * Names in profile output need to be sorted to figure out if there'll
1570Sstevel@tonic-gate  * be any duplicate names in the output.
1580Sstevel@tonic-gate  */
1590Sstevel@tonic-gate struct profnames {
1600Sstevel@tonic-gate 	char		*name;
1610Sstevel@tonic-gate 	profrec_t	*pfrec;
1620Sstevel@tonic-gate };
1630Sstevel@tonic-gate typedef struct profnames	profnames_t;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate  * File status.
1670Sstevel@tonic-gate  */
1680Sstevel@tonic-gate extern struct stat	aout_stat, monout_stat;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate  * Timing related externs.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate extern bool	time_in_ticks;
1740Sstevel@tonic-gate extern size_t	n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
1750Sstevel@tonic-gate extern double	total_time;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /*
1780Sstevel@tonic-gate  * Other declarations
1790Sstevel@tonic-gate  */
1800Sstevel@tonic-gate extern void	profver(void);
1810Sstevel@tonic-gate extern nltype	*nllookup(mod_info_t *, Address, Address *);
1820Sstevel@tonic-gate extern Address	*locate(Address *, size_t, Address);
1830Sstevel@tonic-gate extern void	get_syms(char *, mod_info_t *);
184211Smike_s extern int	cmp_by_address(const void *arg1, const void *arg2);
1850Sstevel@tonic-gate extern bool	is_shared_obj(char *);
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate #ifdef	__cplusplus
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate #endif
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate #endif	/* _SGS_PROFV_H */
192