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 2001,2002 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _PROFILE_H 28 #define _PROFILE_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #ifndef _ASM 37 38 #include <sys/types.h> 39 #include <synch.h> 40 #include <link.h> 41 42 /* 43 * The profile buffer created by ld.so.1 consists of 3 sections; the header, 44 * the profil(2) buffer, and an array of call graph arc structures. 45 */ 46 47 typedef struct l_hdr { /* Linker profile buffer header */ 48 unsigned int hd_magic; /* identifier for file */ 49 unsigned int hd_version; /* version for rtld prof file */ 50 lwp_mutex_t hd_mutex; /* Provides for process locking */ 51 caddr_t hd_hpc; /* Relative high pc address */ 52 unsigned int hd_psize; /* Size of profil(2) buffer */ 53 unsigned int hd_fsize; /* Size of file */ 54 unsigned int hd_ncndx; /* Next (and last) index into */ 55 unsigned int hd_lcndx; /* call graph arc structure */ 56 } L_hdr; 57 58 59 /* 60 * The *64 structs are for gprof, as a 32-bit program, 61 * to read 64-bit profiles correctly. 62 */ 63 64 typedef struct l_hdr64 { /* Linker profile buffer header */ 65 unsigned int hd_magic; /* identifier for file */ 66 unsigned int hd_version; /* version for rtld prof file */ 67 lwp_mutex_t hd_mutex; /* Provides for process locking */ 68 u_longlong_t hd_hpc; /* Relative high pc address */ 69 unsigned int hd_psize; /* Size of profil(2) buffer */ 70 unsigned int hd_fsize; /* Size of file */ 71 unsigned int hd_ncndx; /* Next (and last) index into */ 72 unsigned int hd_lcndx; /* call graph arc structure */ 73 } L_hdr64; 74 75 76 77 typedef struct l_cgarc { /* Linker call graph arc entry */ 78 caddr_t cg_from; /* Source of call */ 79 caddr_t cg_to; /* Destination of call */ 80 unsigned int cg_count; /* Instance count */ 81 unsigned int cg_next; /* Link index for multiple sources */ 82 } L_cgarc; 83 84 85 typedef struct l_cgarc64 { /* Linker call graph arc entry */ 86 u_longlong_t cg_from; /* Source of call */ 87 u_longlong_t cg_to; /* Destination of call */ 88 unsigned int cg_count; /* Instance count */ 89 unsigned int cg_next; /* Link index for multiple sources */ 90 } L_cgarc64; 91 92 93 /* 94 * Snapshots of this profile buffer are taken by `ldmon' and packaged into 95 * a gmon.out file appropriate for analysis by gprof(1). This gmon file 96 * consists of three sections (taken from gmon.h); a header, a profil(2) 97 * buffer, and an array of call graph arc structures. 98 */ 99 100 typedef struct m_hdr { /* Monitor profile buffer header */ 101 char *hd_lpc; /* Low pc value */ 102 char *hd_hpc; /* High pc value */ 103 int hd_off; /* Offset into call graph array */ 104 } M_hdr; 105 106 typedef struct m_hdr64 { /* Monitor profile buffer header */ 107 u_longlong_t hd_lpc; /* Low pc value */ 108 u_longlong_t hd_hpc; /* High pc value */ 109 int hd_off; /* Offset into call graph array */ 110 } M_hdr64; 111 112 typedef struct m_cgarc { /* Monitor call graph arc entry */ 113 unsigned int cg_from; /* Source of call */ 114 unsigned int cg_to; /* Destination of call */ 115 int cg_count; /* Instance count */ 116 } M_cgarc; 117 118 typedef struct m_cnt { /* Prof(1) function count structure */ 119 char *fc_fnpc; /* Called functions address */ 120 int fc_mcnt; /* Instance count */ 121 } M_cnt; 122 123 124 #define PROF_LIBRARY "ldprofile.so.1" 125 126 /* 127 * Generic defines for creating profiled output buffer. 128 */ 129 130 #define PRF_BARSIZE 2 /* No. of program bytes that */ 131 /* correspond to each histogram */ 132 /* bar in the profil(2) buffer */ 133 #define PRF_SCALE 0x8000 /* Scale to provide above */ 134 /* histogram correspondence */ 135 #define PRF_CGNUMB 256 /* Size of call graph extension */ 136 #define PRF_CGINIT 2 /* Initial symbol blocks to allocate */ 137 /* for the call graph structure */ 138 #define PRF_OUTADDR (caddr_t)-1 /* Function addresses outside of */ 139 /* the range being monitored */ 140 #define PRF_OUTADDR64 (u_longlong_t)-1 /* Function addresses outside */ 141 /* of the range being monitored */ 142 #define PRF_UNKNOWN (caddr_t)-2 /* Unknown function address */ 143 144 #define PRF_ROUNDUP(x, a) (((x) + ((a) - 1)) & ~((a) - 1)) 145 #define PRF_ROUNDWN(x, a) ((x) & ~((a) - 1)) 146 147 #define PRF_MAGIC 0xffffffff /* unique number to differentiate */ 148 /* profiled file from gmon.out for */ 149 /* gprof */ 150 #define PRF_VERSION 0x1 /* current PROF file version */ 151 #define PRF_VERSION_64 0x2 /* 64-bit current PROF file version */ 152 153 154 /* 155 * Related data and function definitions. 156 */ 157 158 extern int profile_rtld; /* Rtld is being profiled */ 159 160 extern uintptr_t (* p_cg_interp)(int, caddr_t, caddr_t); 161 162 #endif 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 #endif /* _PROFILE_H */ 169