xref: /illumos-gate/usr/src/cmd/sgs/prof/common/profv.h (revision b9bd317c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*b9bd317cSab  * Common Development and Distribution License (the "License").
6*b9bd317cSab  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2192ed1782Smike_s 
227c478bd9Sstevel@tonic-gate /*
23*b9bd317cSab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2492ed1782Smike_s  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SGS_PROFV_H
287c478bd9Sstevel@tonic-gate #define	_SGS_PROFV_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Header file for processing versioned, *new-style* mon.out files.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <stdio.h>
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/mman.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate #include <fcntl.h>
457c478bd9Sstevel@tonic-gate #include <unistd.h>
467c478bd9Sstevel@tonic-gate #include <sys/elf.h>
477c478bd9Sstevel@tonic-gate #include "gelf.h"
487c478bd9Sstevel@tonic-gate #include "monv.h"
49*b9bd317cSab #include "_machelf.h"
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Booleans.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate typedef int	bool;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	TRUE	1
577c478bd9Sstevel@tonic-gate #define	FALSE	0
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Bit macro and flag bit definitions. These and the sort_flags below,
617c478bd9Sstevel@tonic-gate  * need to be always in sync with the set in prof.c
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate extern int		flags;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	F_SORT		0x1
667c478bd9Sstevel@tonic-gate #define	F_VERBOSE	0x2
677c478bd9Sstevel@tonic-gate #define	F_ZSYMS		0x4
687c478bd9Sstevel@tonic-gate #define	F_PADDR		0x8
697c478bd9Sstevel@tonic-gate #define	F_NHEAD		0x10
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Sort flags. Mutually exclusive.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate extern unsigned char	sort_flag;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	BY_ADDRESS	0x1
777c478bd9Sstevel@tonic-gate #define	BY_NCALLS	0x2
787c478bd9Sstevel@tonic-gate #define	BY_NAME		0x4
797c478bd9Sstevel@tonic-gate #define	BY_TIME		0x8
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Error codes
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	ERR_SYSCALL	1
857c478bd9Sstevel@tonic-gate #define	ERR_INPUT	2
867c478bd9Sstevel@tonic-gate #define	ERR_ELF		3
877c478bd9Sstevel@tonic-gate #define	ERR_MEMORY	4
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Other useful macros.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	BUCKET_SZ	4096
937c478bd9Sstevel@tonic-gate #define	PRF_END		"_end"
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern int		gflag, Cflag;
967c478bd9Sstevel@tonic-gate extern char		*atitle, *aformat,
977c478bd9Sstevel@tonic-gate 			*cmdname, *sym_fn, *mon_fn;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * Module info.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate struct mod_info {
1037c478bd9Sstevel@tonic-gate 	char		*path;		/* pathname of module */
1047c478bd9Sstevel@tonic-gate 	int		id;		/* id (used while printing) */
1057c478bd9Sstevel@tonic-gate 	bool		active;		/* is this module active or not ? */
1067c478bd9Sstevel@tonic-gate 	Address		load_base;	/* base addr where module is loaded */
1077c478bd9Sstevel@tonic-gate 	Address		load_end;	/* end addr of loaded module */
1087c478bd9Sstevel@tonic-gate 	GElf_Addr	txt_origin;	/* txt start as given in PHT */
1097c478bd9Sstevel@tonic-gate 	GElf_Addr	data_end;	/* data end as found from `_end' */
1107c478bd9Sstevel@tonic-gate 	struct nl	*nl;		/* ptr to module's namelist */
1117c478bd9Sstevel@tonic-gate 	size_t		nfuncs;		/* number of functions in `nl' */
1127c478bd9Sstevel@tonic-gate 	struct mod_info	*next;		/* link to next module */
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate typedef struct mod_info	mod_info_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * List of shared objects. Note that this always includes the program
1187c478bd9Sstevel@tonic-gate  * executable as the first element.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate extern mod_info_t	modules;
1217c478bd9Sstevel@tonic-gate extern size_t		n_modules;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * The symbol table.
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate struct nl {
1277c478bd9Sstevel@tonic-gate 	char		*name;		/* name of the symbol */
1287c478bd9Sstevel@tonic-gate 	GElf_Addr	value;		/* value of the symbol */
1297c478bd9Sstevel@tonic-gate 	unsigned char	info;		/* symbol's bind/type info */
1307c478bd9Sstevel@tonic-gate 	GElf_Xword	size;		/* size of the symbol */
1317c478bd9Sstevel@tonic-gate 	size_t		ncalls;		/* number of calls to this func */
1327c478bd9Sstevel@tonic-gate 	size_t		nticks;		/* number of ticks spent here */
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate typedef struct nl	nltype;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * The profile output record. There is some duplication of fields from
1387c478bd9Sstevel@tonic-gate  * the namelist, but the profsym contains just the symbols we're going
1397c478bd9Sstevel@tonic-gate  * to print, and that makes a lot of things easier.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate struct profrec {
1427c478bd9Sstevel@tonic-gate 	GElf_Addr	addr;			/* symbol value */
1437c478bd9Sstevel@tonic-gate 	double		percent_time;		/* percentage time spent here */
1447c478bd9Sstevel@tonic-gate 	double		seconds;		/* time spent here in seconds */
1457c478bd9Sstevel@tonic-gate 	size_t		ncalls;			/* calls to this function */
1467c478bd9Sstevel@tonic-gate 	double		msecs_per_call;		/* milliseconds per call */
1477c478bd9Sstevel@tonic-gate 	char		*demangled_name;	/* demangled name if C++ */
1487c478bd9Sstevel@tonic-gate 	bool		print_mid;		/* print module id ? */
1497c478bd9Sstevel@tonic-gate 	char		*name;			/* bookkeeping, not printed */
1507c478bd9Sstevel@tonic-gate 	mod_info_t	*module;		/* bookkeeping, not printed */
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate typedef struct profrec	profrec_t;
1537c478bd9Sstevel@tonic-gate extern profrec_t	*profsym;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Names in profile output need to be sorted to figure out if there'll
1577c478bd9Sstevel@tonic-gate  * be any duplicate names in the output.
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate struct profnames {
1607c478bd9Sstevel@tonic-gate 	char		*name;
1617c478bd9Sstevel@tonic-gate 	profrec_t	*pfrec;
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate typedef struct profnames	profnames_t;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * File status.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate extern struct stat	aout_stat, monout_stat;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * Timing related externs.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate extern bool	time_in_ticks;
1747c478bd9Sstevel@tonic-gate extern size_t	n_pcsamples, n_accounted_ticks, n_zeros, total_funcs;
1757c478bd9Sstevel@tonic-gate extern double	total_time;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate  * Other declarations
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate extern void	profver(void);
1817c478bd9Sstevel@tonic-gate extern nltype	*nllookup(mod_info_t *, Address, Address *);
1827c478bd9Sstevel@tonic-gate extern Address	*locate(Address *, size_t, Address);
1837c478bd9Sstevel@tonic-gate extern void	get_syms(char *, mod_info_t *);
18492ed1782Smike_s extern int	cmp_by_address(const void *arg1, const void *arg2);
1857c478bd9Sstevel@tonic-gate extern bool	is_shared_obj(char *);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate #endif
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #endif	/* _SGS_PROFV_H */
192