| 1 | /********************************************************************** |
|---|
| 2 | * Copyright (c) 2005-2008 David Carter <dcarter@arm4.org> and others. |
|---|
| 3 | * All rights reserved. This program and the accompanying materials |
|---|
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
|---|
| 5 | * which accompanies this distribution, and is available at |
|---|
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
|---|
| 7 | * |
|---|
| 8 | * Contributors: |
|---|
| 9 | * David Carter - Initial API and implementation |
|---|
| 10 | **********************************************************************/ |
|---|
| 11 | /* Copyright (c) 2004 The Open Group */ |
|---|
| 12 | /* */ |
|---|
| 13 | /* Permission is hereby granted, free of charge, to any person obtaining a */ |
|---|
| 14 | /* copy of this software (the "Software"), to deal in the Software without */ |
|---|
| 15 | /* restriction, including without limitation the rights to use, copy, */ |
|---|
| 16 | /* modify, merge, publish, distribute, sublicense, and/or sell copies of */ |
|---|
| 17 | /* the Software, and to permit persons to whom the Software is furnished */ |
|---|
| 18 | /* to do so, subject to the following conditions: */ |
|---|
| 19 | /* */ |
|---|
| 20 | /* The above copyright notice and this permission notice shall be included */ |
|---|
| 21 | /* in all copies or substantial portions of the Software. */ |
|---|
| 22 | /* */ |
|---|
| 23 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS */ |
|---|
| 24 | /* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
|---|
| 25 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
|---|
| 26 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
|---|
| 27 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT */ |
|---|
| 28 | /* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR */ |
|---|
| 29 | /* THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
|---|
| 30 | /* */ |
|---|
| 31 | /* ------------------------------------------------------------------------- */ |
|---|
| 32 | |
|---|
| 33 | /* ------------------------------------------------------------------------- */ |
|---|
| 34 | /* arm4agent.h - ARM Agent Specific API Definitions */ |
|---|
| 35 | /* */ |
|---|
| 36 | /* This header contains defines that are explicitly hidden from the */ |
|---|
| 37 | /* application instrumentation and most be known to an ARM Agent. */ |
|---|
| 38 | /* */ |
|---|
| 39 | /* ARM4 C agent implementors must include this header and may also */ |
|---|
| 40 | /* modify this header to define an agent specific correlator. The total */ |
|---|
| 41 | /* length of this correlator cannot exceed ARM_CORR_MAX_LENGTH bytes. */ |
|---|
| 42 | /* ------------------------------------------------------------------------- */ |
|---|
| 43 | |
|---|
| 44 | #if !defined(ARM4AGENT_H_INCLUDED) |
|---|
| 45 | #define ARM4AGENT_H_INCLUDED |
|---|
| 46 | |
|---|
| 47 | #include "arm4.h" /* ARM API definitions */ |
|---|
| 48 | |
|---|
| 49 | /* Data directories */ |
|---|
| 50 | #define ARM4DATA_QUEUE_DIR "/var/run/arm4" |
|---|
| 51 | #define ARM4DATA_DB_DIR "/var/lib/arm4" |
|---|
| 52 | #define ARM4DATA_DB_BACKUP_DIR "/var/lib/arm4/backup" |
|---|
| 53 | |
|---|
| 54 | /* ------------------------------------------------------------------------- */ |
|---|
| 55 | /* ------------------------- ARM agent definitions ------------------------- */ |
|---|
| 56 | /* ------------------------------------------------------------------------- */ |
|---|
| 57 | |
|---|
| 58 | /* Correlator flag bit definitions */ |
|---|
| 59 | #define ARM_CORR_FLAG_APP_TRACE (0x40) /* Application instance trace */ |
|---|
| 60 | /* requested */ |
|---|
| 61 | #define ARM_CORR_FLAG_AGENT_TRACE (0x80) /* Agent transaction instance */ |
|---|
| 62 | /* trace requested */ |
|---|
| 63 | |
|---|
| 64 | /* Known ARM correlator formats: Vendor reserved arena 1-127 */ |
|---|
| 65 | #define ARM_CORR_FORMAT_VERSION2 1 /* ARM2 Correlator format */ |
|---|
| 66 | #define ARM_CORR_FORMAT_VERSION3 2 /* ARM3 Correlator format */ |
|---|
| 67 | #define ARM_CORR_FORMAT_HP 28 /* HP's ARM correlator */ |
|---|
| 68 | #define ARM_CORR_FORMAT_BMC 82 /* BMC's ARM correlator */ |
|---|
| 69 | #define ARM_CORR_FORMAT_IBM 103 /* IBM's ARM correlator */ |
|---|
| 70 | #define ARM_CORR_FORMAT_TANG_IT 122 /* tang-IT's ARM correlator */ |
|---|
| 71 | #define ARM_CORR_FORMAT_SDK4_OUT_PROC 125 /* ARM4SDK out of process corr*/ |
|---|
| 72 | #define ARM_CORR_FORMAT_SDK4_IN_PROC 126 /* ARM4SDK in process corr */ |
|---|
| 73 | |
|---|
| 74 | #define ARM_CORR_FORMAT_INVALID 127 /* Indicates an invalid corr. */ |
|---|
| 75 | |
|---|
| 76 | /* Known ARM correlator formats: Vendor playground arena 128-256 */ |
|---|
| 77 | #define ARM_CORR_FORMAT_HP_128 128 /* HP */ |
|---|
| 78 | #define ARM_CORR_FORMAT_IBM_203 203 /* IBM */ |
|---|
| 79 | #define ARM_CORR_FORMAT_IBM_204 204 /* IBM */ |
|---|
| 80 | |
|---|
| 81 | #define ARM_CORR_MIN_LENGTH 4 /* This is the header length */ |
|---|
| 82 | |
|---|
| 83 | /* IANA Vendor ID */ |
|---|
| 84 | /* See http://www.iana.org/assignments/enterprise-numbers */ |
|---|
| 85 | #define IANA_VENDOR_ID_ARM4_ORG 26026 |
|---|
| 86 | |
|---|
| 87 | /* ------------------------------------------------------------------------- */ |
|---|
| 88 | /* ---------------------------- data definitions --------------------------- */ |
|---|
| 89 | /* ------------------------------------------------------------------------- */ |
|---|
| 90 | |
|---|
| 91 | /* Correlator header which must be the same across all implementations */ |
|---|
| 92 | typedef struct arm_correlator_header { |
|---|
| 93 | arm_uint16_t length; /* Length of correlator */ |
|---|
| 94 | arm_uint8_t format; /* Format of the correlator */ |
|---|
| 95 | arm_uint8_t flags; /* Flags */ |
|---|
| 96 | } arm_correlator_header_t; |
|---|
| 97 | |
|---|
| 98 | /* Correlator structure definitions */ |
|---|
| 99 | typedef struct arm2_correlator { /* ---- ARM 2 Correlator format ---- */ |
|---|
| 100 | arm_uint16_t length; /* Length of correlator */ |
|---|
| 101 | arm_uint8_t format; /* Format of the correlator */ |
|---|
| 102 | arm_uint8_t flags; /* Flags */ |
|---|
| 103 | arm_uint16_t addr_format; /* Format of the address */ |
|---|
| 104 | arm_uint16_t vendor_id; /* IANA Vendor id */ |
|---|
| 105 | arm_uint16_t agent_version; /* Agent version number */ |
|---|
| 106 | arm_uint16_t agent_instance; /* Agent instance number */ |
|---|
| 107 | arm_int32_t start_handle; /* Transaction start handle */ |
|---|
| 108 | arm_int32_t tran_id; /* Transaction id */ |
|---|
| 109 | arm_uint16_t addr_length; /* Length of the address */ |
|---|
| 110 | arm_uint8_t address[146]; /* Agent contact info */ |
|---|
| 111 | } arm2_correlator_t; |
|---|
| 112 | |
|---|
| 113 | typedef struct arm3_correlator { /* ---- ARM 3 Correlator format ---- */ |
|---|
| 114 | arm_uint16_t length; /* Length of correlator */ |
|---|
| 115 | arm_uint8_t format; /* Format of the correlator */ |
|---|
| 116 | arm_uint8_t flags; /* Flags */ |
|---|
| 117 | arm_uint16_t addr_format; /* Format of the address */ |
|---|
| 118 | arm_uint16_t vendor_id; /* IANA Vendor id */ |
|---|
| 119 | arm_uint16_t agent_version; /* Agent version number */ |
|---|
| 120 | arm_uint16_t agent_instance; /* Agent instance number */ |
|---|
| 121 | arm_int64_t tran_handle; /* Transaction handle */ |
|---|
| 122 | arm_id_t tran_id; /* Transaction uuid */ |
|---|
| 123 | arm_uint16_t addr_length; /* Length of the address */ |
|---|
| 124 | arm_uint8_t address[130]; /* Agent contact info */ |
|---|
| 125 | } arm3_correlator_t; |
|---|
| 126 | |
|---|
| 127 | /* 64 bit equivalents of htonl and ntohl */ |
|---|
| 128 | #define ntohll(x) (((arm_uint64_t)(ntohl((arm_uint32_t)((x << 32) >> 32))) << 32) | (arm_uint32_t)ntohl(((int)(x >> 32)))) |
|---|
| 129 | #define htonll(x) ntohll(x) |
|---|
| 130 | |
|---|
| 131 | /* Return values to indicate success or failure */ |
|---|
| 132 | #define ARM_SUCCESS (0) |
|---|
| 133 | #define ARM_FAILURE (-1) |
|---|
| 134 | |
|---|
| 135 | /* Used to record current instance status */ |
|---|
| 136 | #define ARM_ACTIVE (1) |
|---|
| 137 | #define ARM_COMPLETE (0) |
|---|
| 138 | #define ARM_DISCARD (-1) |
|---|
| 139 | |
|---|
| 140 | /* More specific error codes */ |
|---|
| 141 | /* When updating these, be sure to update ArmErrors.java as well */ |
|---|
| 142 | #define ARM_FAILURE_INVALID_ARGUMENT (-100) |
|---|
| 143 | #define ARM_FAILURE_NULL_ARGUMENT (-101) |
|---|
| 144 | #define ARM_FAILURE_UNSUPPORTED_CHARSET (-102) |
|---|
| 145 | #define ARM_FAILURE_TRANSACTION_INACTIVE (-103) |
|---|
| 146 | #define ARM_FAILURE_TRANSACTION_BLOCKED (-104) |
|---|
| 147 | #define ARM_FAILURE_TRANSACTION_NOT_BLOCKED (-105) |
|---|
| 148 | #define ARM_FAILURE_DUPLICATE_ALIAS (-106) |
|---|
| 149 | #define ARM_FAILURE_BAD_ALIAS (-107) |
|---|
| 150 | |
|---|
| 151 | #define ARM_FAILURE_INTERNAL_ERROR (-500) |
|---|
| 152 | |
|---|
| 153 | /* These are required to support Java floating point metric values */ |
|---|
| 154 | #define ARM_METRIC_FORMAT_COUNTERFLOAT32 (20) |
|---|
| 155 | #define ARM_METRIC_FORMAT_GAUGEFLOAT32 (21) |
|---|
| 156 | |
|---|
| 157 | /* Define formats for printf and scanf */ |
|---|
| 158 | /* Needed to find out appropriate int32 and int64 types, limit.h is an */ |
|---|
| 159 | /* ANSI-C header file. Thus any ANSI-C compliant compiler works. */ |
|---|
| 160 | #ifdef __cplusplus |
|---|
| 161 | #include <climits> |
|---|
| 162 | #else |
|---|
| 163 | #include <limits.h> |
|---|
| 164 | #endif |
|---|
| 165 | |
|---|
| 166 | /* set-up arm_int32_t format */ |
|---|
| 167 | #if INT_MAX == 2147483647l |
|---|
| 168 | #define ARM4_FORMAT_INT32 "%d" |
|---|
| 169 | #define ARM4_FORMAT_UINT32 "%u" |
|---|
| 170 | #elif LONG_MAX == 2147483647l |
|---|
| 171 | #define ARM4_FORMAT_INT32 "%ld" |
|---|
| 172 | #define ARM4_FORMAT_UINT32 "%lu" |
|---|
| 173 | #else |
|---|
| 174 | /*#error "can't determine 32bit integer format"*/ |
|---|
| 175 | #define ARM4_FORMAT_INT32 "%d" |
|---|
| 176 | #define ARM4_FORMAT_UINT32 "%u" |
|---|
| 177 | #endif /* INT_MAX == 2147483647l */ |
|---|
| 178 | |
|---|
| 179 | /* now find appropriate 64 bit integer format */ |
|---|
| 180 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__WATCOMC__) |
|---|
| 181 | /* MSVC and compatible compiler native 64 bit types */ |
|---|
| 182 | #define ARM4_FORMAT_INT64 __int64 // Need to check this |
|---|
| 183 | #define ARM4_FORMAT_UINT64 __int64 |
|---|
| 184 | |
|---|
| 185 | #elif (defined(LLONG_MAX) && LLONG_MAX > 2147483647l) || \ |
|---|
| 186 | (defined(LONGLONG_MAX) && LONGLONG_MAX > 2147483647l) |
|---|
| 187 | /* LLONG_MAX and LONGLONG_MAX indicate usage of long long 64 bit types */ |
|---|
| 188 | #define ARM4_FORMAT_INT64 "%lld" |
|---|
| 189 | #define ARM4_FORMAT_UINT64 "%llu" |
|---|
| 190 | |
|---|
| 191 | #elif (defined(__GNUC__) && \ |
|---|
| 192 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))) |
|---|
| 193 | /* GNU supports long long. To be safe just use current V 2.95 or V3.x */ |
|---|
| 194 | /* Older versions have to be checked first! */ |
|---|
| 195 | #define ARM4_FORMAT_INT64 "%lld" |
|---|
| 196 | #define ARM4_FORMAT_UINT64 "%llu" |
|---|
| 197 | |
|---|
| 198 | #elif defined(__INTEL_COMPILER) |
|---|
| 199 | /* INTEL C compiler for Windows/Linux supports long long. */ |
|---|
| 200 | #define ARM4_FORMAT_INT64 "%lld" |
|---|
| 201 | #define ARM4_FORMAT_UINT64 "%llu" |
|---|
| 202 | |
|---|
| 203 | #elif LONG_MAX > 2147483647l |
|---|
| 204 | /* on 64-bit systems the normal long type could actually be a 64-bit type */ |
|---|
| 205 | #define ARM4_FORMAT_INT64 "%ld" |
|---|
| 206 | #define ARM4_FORMAT_UINT64 "%lu" |
|---|
| 207 | |
|---|
| 208 | #else |
|---|
| 209 | /* Raise a compile-time error if unsure. Note that assuming "long long" */ |
|---|
| 210 | /* for int64 might get past the compilation but may cause run-time problems */ |
|---|
| 211 | /* if it is not exactly 64-bit. */ |
|---|
| 212 | /*#error "can't determine 64bit integer format"*/ |
|---|
| 213 | #define ARM4_FORMAT_INT64 "%ld" |
|---|
| 214 | #define ARM4_FORMAT_UINT64 "%lu" |
|---|
| 215 | |
|---|
| 216 | #endif /* _MSC_VER ... */ |
|---|
| 217 | |
|---|
| 218 | /* Define a macro to handle unused arguments in functions */ |
|---|
| 219 | #ifdef UNUSED |
|---|
| 220 | #elif defined(__GNUC__) |
|---|
| 221 | # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) |
|---|
| 222 | #elif defined(__LCLINT__) |
|---|
| 223 | # define UNUSED(x) /*@unused@*/ x |
|---|
| 224 | #else |
|---|
| 225 | # define UNUSED(x) x |
|---|
| 226 | #endif |
|---|
| 227 | |
|---|
| 228 | #endif /* ARM4AGENT_H_INCLUDED */ |
|---|
| 229 | |
|---|