xref: /illumos-gate/usr/src/cmd/sgs/include/profile.h (revision 2a8bcb4e)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*e0ddff35Sab  *	Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  *	Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_PROFILE_H
287c478bd9Sstevel@tonic-gate #define	_PROFILE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifndef	_ASM
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <synch.h>
387c478bd9Sstevel@tonic-gate #include <link.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * The profile buffer created by ld.so.1 consists of 3 sections; the header,
427c478bd9Sstevel@tonic-gate  * the profil(2) buffer, and an array of call graph arc structures.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef struct l_hdr {			/* Linker profile buffer header */
467c478bd9Sstevel@tonic-gate 	unsigned int	hd_magic;	/* identifier for file */
477c478bd9Sstevel@tonic-gate 	unsigned int	hd_version;	/* version for rtld prof file */
487c478bd9Sstevel@tonic-gate 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
497c478bd9Sstevel@tonic-gate 	caddr_t		hd_hpc;		/* Relative high pc address */
507c478bd9Sstevel@tonic-gate 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
517c478bd9Sstevel@tonic-gate 	unsigned int	hd_fsize;	/* Size of file */
527c478bd9Sstevel@tonic-gate 	unsigned int	hd_ncndx;	/* Next (and last) index into */
537c478bd9Sstevel@tonic-gate 	unsigned int	hd_lcndx;	/*	call graph arc structure */
547c478bd9Sstevel@tonic-gate } L_hdr;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * The *64 structs are for gprof, as a 32-bit program,
597c478bd9Sstevel@tonic-gate  * to read 64-bit profiles correctly.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct l_hdr64 {		/* Linker profile buffer header */
637c478bd9Sstevel@tonic-gate 	unsigned int	hd_magic;	/* identifier for file */
647c478bd9Sstevel@tonic-gate 	unsigned int	hd_version;	/* version for rtld prof file */
657c478bd9Sstevel@tonic-gate 	lwp_mutex_t	hd_mutex;	/* Provides for process locking */
667c478bd9Sstevel@tonic-gate 	u_longlong_t	hd_hpc;		/* Relative high pc address */
677c478bd9Sstevel@tonic-gate 	unsigned int	hd_psize;	/* Size of profil(2) buffer */
687c478bd9Sstevel@tonic-gate 	unsigned int	hd_fsize;	/* Size of file */
697c478bd9Sstevel@tonic-gate 	unsigned int	hd_ncndx;	/* Next (and last) index into */
707c478bd9Sstevel@tonic-gate 	unsigned int	hd_lcndx;	/*	call graph arc structure */
717c478bd9Sstevel@tonic-gate } L_hdr64;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate typedef struct l_cgarc {		/* Linker call graph arc entry */
767c478bd9Sstevel@tonic-gate 	caddr_t		cg_from;	/* Source of call */
777c478bd9Sstevel@tonic-gate 	caddr_t		cg_to;		/* Destination of call */
787c478bd9Sstevel@tonic-gate 	unsigned int	cg_count;	/* Instance count */
797c478bd9Sstevel@tonic-gate 	unsigned int	cg_next;	/* Link index for multiple sources */
807c478bd9Sstevel@tonic-gate } L_cgarc;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate typedef struct l_cgarc64 {		/* Linker call graph arc entry */
847c478bd9Sstevel@tonic-gate 	u_longlong_t	cg_from;	/* Source of call */
857c478bd9Sstevel@tonic-gate 	u_longlong_t	cg_to;		/* Destination of call */
867c478bd9Sstevel@tonic-gate 	unsigned int	cg_count;	/* Instance count */
877c478bd9Sstevel@tonic-gate 	unsigned int	cg_next;	/* Link index for multiple sources */
887c478bd9Sstevel@tonic-gate } L_cgarc64;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * Generic defines for creating profiled output buffer.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #define	PRF_BARSIZE	2		/* No. of program bytes that */
977c478bd9Sstevel@tonic-gate 					/* correspond to each histogram */
987c478bd9Sstevel@tonic-gate 					/* bar in the profil(2) buffer */
997c478bd9Sstevel@tonic-gate #define	PRF_SCALE	0x8000		/* Scale to provide above */
1007c478bd9Sstevel@tonic-gate 					/* histogram correspondence */
1017c478bd9Sstevel@tonic-gate #define	PRF_CGNUMB	256		/* Size of call graph extension */
1027c478bd9Sstevel@tonic-gate #define	PRF_CGINIT	2		/* Initial symbol blocks to allocate */
1037c478bd9Sstevel@tonic-gate 					/*	for the call graph structure */
1047c478bd9Sstevel@tonic-gate #define	PRF_OUTADDR	(caddr_t)-1	/* Function addresses outside of */
1057c478bd9Sstevel@tonic-gate 					/*	the range being monitored */
1067c478bd9Sstevel@tonic-gate #define	PRF_OUTADDR64	(u_longlong_t)-1	/* Function addresses outside */
1077c478bd9Sstevel@tonic-gate 					/*	of the range being monitored */
1087c478bd9Sstevel@tonic-gate #define	PRF_UNKNOWN	(caddr_t)-2	/* Unknown function address */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #define	PRF_ROUNDUP(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
1117c478bd9Sstevel@tonic-gate #define	PRF_ROUNDWN(x, a) ((x) & ~((a) - 1))
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #define	PRF_MAGIC	0xffffffff	/* unique number to differentiate */
1147c478bd9Sstevel@tonic-gate 					/* profiled file from gmon.out for */
1157c478bd9Sstevel@tonic-gate 					/* gprof */
1167c478bd9Sstevel@tonic-gate #define	PRF_VERSION	0x1		/* current PROF file version */
1177c478bd9Sstevel@tonic-gate #define	PRF_VERSION_64	0x2		/* 64-bit current PROF file version */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Related data and function definitions.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate extern	int		profile_rtld;		/* Rtld is being profiled */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate extern	uintptr_t (*	p_cg_interp)(int, caddr_t, caddr_t);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #endif /* _PROFILE_H */
135