| 1 | #include <stdio.h> |
| 2 | #include <asm/types.h> |
| 3 | #include <linux/byteorder/swab.h> |
| 4 | #include <ltt/LTTTypes.h> |
| 5 | #include "parser.h" |
| 6 | #include <ltt/event.h> |
| 7 | |
| 8 | /***************************************************************************** |
| 9 | *Function name |
| 10 | * ltt_event_eventtype_id: get event type id |
| 11 | * (base id + position of the event) |
| 12 | *Input params |
| 13 | * e : an instance of an event type |
| 14 | *Return value |
| 15 | * unsigned : event type id |
| 16 | ****************************************************************************/ |
| 17 | |
| 18 | unsigned ltt_event_eventtype_id(LttEvent *e) |
| 19 | { |
| 20 | return (unsigned) e->event_id; |
| 21 | } |
| 22 | |
| 23 | /***************************************************************************** |
| 24 | *Function name |
| 25 | * ltt_event_facility : get the facility of the event |
| 26 | *Input params |
| 27 | * e : an instance of an event type |
| 28 | *Return value |
| 29 | * LttFacility * : the facility of the event |
| 30 | ****************************************************************************/ |
| 31 | |
| 32 | LttFacility *ltt_event_facility(LttEvent *e) |
| 33 | { |
| 34 | LttTrace * trace = e->tracefile->trace; |
| 35 | unsigned id = e->event_id; |
| 36 | return ltt_trace_facility_by_id(trace,id); |
| 37 | } |
| 38 | |
| 39 | /***************************************************************************** |
| 40 | *Function name |
| 41 | * ltt_event_eventtype : get the event type of the event |
| 42 | *Input params |
| 43 | * e : an instance of an event type |
| 44 | *Return value |
| 45 | * LttEventType * : the event type of the event |
| 46 | ****************************************************************************/ |
| 47 | |
| 48 | LttEventType *ltt_event_eventtype(LttEvent *e) |
| 49 | { |
| 50 | LttFacility* facility = ltt_event_facility(e); |
| 51 | if(!facility) return NULL; |
| 52 | return facility->events[e->event_id - facility->base_id]; |
| 53 | } |
| 54 | |
| 55 | /***************************************************************************** |
| 56 | *Function name |
| 57 | * ltt_event_field : get the root field of the event |
| 58 | *Input params |
| 59 | * e : an instance of an event type |
| 60 | *Return value |
| 61 | * LttField * : the root field of the event |
| 62 | ****************************************************************************/ |
| 63 | |
| 64 | LttField *ltt_event_field(LttEvent *e) |
| 65 | { |
| 66 | LttEventType * event_type = ltt_event_eventtype(e); |
| 67 | if(!event_type) return NULL; |
| 68 | return event_type->root_field; |
| 69 | } |
| 70 | |
| 71 | /***************************************************************************** |
| 72 | *Function name |
| 73 | * ltt_event_time : get the time of the event |
| 74 | *Input params |
| 75 | * e : an instance of an event type |
| 76 | *Return value |
| 77 | * LttTime : the time of the event |
| 78 | ****************************************************************************/ |
| 79 | |
| 80 | LttTime ltt_event_time(LttEvent *e) |
| 81 | { |
| 82 | return e->event_time; |
| 83 | } |
| 84 | |
| 85 | /***************************************************************************** |
| 86 | *Function name |
| 87 | * ltt_event_time : get the cycle count of the event |
| 88 | *Input params |
| 89 | * e : an instance of an event type |
| 90 | *Return value |
| 91 | * LttCycleCount : the cycle count of the event |
| 92 | ****************************************************************************/ |
| 93 | |
| 94 | LttCycleCount ltt_event_cycle_count(LttEvent *e) |
| 95 | { |
| 96 | return e->event_cycle_count; |
| 97 | } |
| 98 | |
| 99 | /***************************************************************************** |
| 100 | *Function name |
| 101 | * ltt_event_cpu_i: get the cpu id where the event happens |
| 102 | *Input params |
| 103 | * e : an instance of an event type |
| 104 | *Return value |
| 105 | * unsigned : the cpu id |
| 106 | ****************************************************************************/ |
| 107 | |
| 108 | unsigned ltt_event_cpu_id(LttEvent *e) |
| 109 | { |
| 110 | return (unsigned)atoi(e->tracefile->name); |
| 111 | } |
| 112 | |
| 113 | /***************************************************************************** |
| 114 | *Function name |
| 115 | * ltt_event_data : get the raw data for the event |
| 116 | *Input params |
| 117 | * e : an instance of an event type |
| 118 | *Return value |
| 119 | * void * : pointer to the raw data for the event |
| 120 | ****************************************************************************/ |
| 121 | |
| 122 | void *ltt_event_data(LttEvent *e) |
| 123 | { |
| 124 | return e->data; |
| 125 | } |
| 126 | |
| 127 | /***************************************************************************** |
| 128 | *Function name |
| 129 | * ltt_event_field_element_number |
| 130 | * : The number of elements in a sequence field is specific |
| 131 | * to each event. This function returns the number of |
| 132 | * elements for an array or sequence field in an event. |
| 133 | *Input params |
| 134 | * e : an instance of an event type ???? |
| 135 | * f : a field of the instance |
| 136 | *Return value |
| 137 | * unsigned : the number of elements for an array/sequence field |
| 138 | ****************************************************************************/ |
| 139 | |
| 140 | unsigned ltt_event_field_element_number(LttEvent *e, LttField *f) |
| 141 | { |
| 142 | if(f->field_type->type_class != LTT_ARRAY && |
| 143 | f->field_type->type_class != LTT_SEQUENCE) |
| 144 | return 0; |
| 145 | |
| 146 | return f->field_type->element_number; |
| 147 | } |
| 148 | |
| 149 | /***************************************************************************** |
| 150 | *Function name |
| 151 | * ltt_event_field_element_select |
| 152 | * : Set the currently selected element for a sequence or |
| 153 | * array field |
| 154 | *Input params |
| 155 | * e : an instance of an event type ???? |
| 156 | * f : a field of the instance |
| 157 | * i : the ith element |
| 158 | ****************************************************************************/ |
| 159 | |
| 160 | void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) |
| 161 | { |
| 162 | if(f->field_type->type_class != LTT_ARRAY && |
| 163 | f->field_type->type_class != LTT_SEQUENCE) |
| 164 | return ; |
| 165 | |
| 166 | if(f->field_type->element_number < i || i == 0) return; |
| 167 | |
| 168 | f->current_element = i - 1; |
| 169 | } |
| 170 | |
| 171 | /***************************************************************************** |
| 172 | * These functions extract data from an event after architecture specific |
| 173 | * conversions |
| 174 | ****************************************************************************/ |
| 175 | |
| 176 | unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f) |
| 177 | { |
| 178 | LttArchSize rSize = e->tracefile->trace->system_description->size; |
| 179 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 180 | e->tracefile->trace->system_description->endian ? 0:1; |
| 181 | LttTypeEnum t = f->field_type->type_class; |
| 182 | |
| 183 | if(t != LTT_UINT || t != LTT_ENUM) |
| 184 | g_error("The type of the field is not unsigned int\n"); |
| 185 | |
| 186 | if(rSize == LTT_LP32){ |
| 187 | if(f->field_size != 2) |
| 188 | g_error("The type of the field is not unsigned int: uint16_t\n"); |
| 189 | else{ |
| 190 | uint16_t x = *(uint16_t *)(e->data + f->offset_root); |
| 191 | return (unsigned) (revFlag ? BREV16(x) : x); |
| 192 | } |
| 193 | }else if(rSize == LTT_ILP32 || rSize == LTT_LP64){ |
| 194 | if(f->field_size != 4) |
| 195 | g_error("The type of the field is not unsigned int: uint32_t\n"); |
| 196 | else{ |
| 197 | uint32_t x = *(uint32_t *)(e->data + f->offset_root); |
| 198 | return (unsigned) (revFlag ? BREV32(x): x); |
| 199 | } |
| 200 | }else if(rSize == LTT_ILP64){ |
| 201 | if(f->field_size != 8) |
| 202 | g_error("The type of the field is not unsigned int: uint64_t\n"); |
| 203 | else{ |
| 204 | uint64_t x = *(uint64_t *)(e->data + f->offset_root); |
| 205 | return (unsigned) (revFlag ? BREV64(x): x); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | int ltt_event_get_int(LttEvent *e, LttField *f) |
| 211 | { |
| 212 | LttArchSize rSize = e->tracefile->trace->system_description->size; |
| 213 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 214 | e->tracefile->trace->system_description->endian ? 0:1; |
| 215 | |
| 216 | if(f->field_type->type_class != LTT_INT) |
| 217 | g_error("The type of the field is not int\n"); |
| 218 | |
| 219 | if(rSize == LTT_LP32){ |
| 220 | if(f->field_size != 2) |
| 221 | g_error("The type of the field is not int: int16_t\n"); |
| 222 | else{ |
| 223 | int16_t x = *(int16_t *)(e->data + f->offset_root); |
| 224 | return (int) (revFlag ? BREV16(x) : x); |
| 225 | } |
| 226 | }else if(rSize == LTT_ILP32 || rSize == LTT_LP64){ |
| 227 | if(f->field_size != 4) |
| 228 | g_error("The type of the field is not int: int32_t\n"); |
| 229 | else{ |
| 230 | int32_t x = *(int32_t *)(e->data + f->offset_root); |
| 231 | return (int) (revFlag ? BREV32(x): x); |
| 232 | } |
| 233 | }else if(rSize == LTT_ILP64){ |
| 234 | if(f->field_size != 8) |
| 235 | g_error("The type of the field is not int: int64_t\n"); |
| 236 | else{ |
| 237 | int64_t x = *(int64_t *)(e->data + f->offset_root); |
| 238 | return (int) (revFlag ? BREV64(x): x); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) |
| 244 | { |
| 245 | LttArchSize rSize = e->tracefile->trace->system_description->size; |
| 246 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 247 | e->tracefile->trace->system_description->endian ? 0:1; |
| 248 | LttTypeEnum t = f->field_type->type_class; |
| 249 | |
| 250 | if(t != LTT_UINT || t != LTT_ENUM) |
| 251 | g_error("The type of the field is not unsigned long\n"); |
| 252 | |
| 253 | if(rSize == LTT_LP32 || rSize == LTT_ILP32 ){ |
| 254 | if(f->field_size != 4) |
| 255 | g_error("The type of the field is not unsigned long: uint32_t\n"); |
| 256 | else{ |
| 257 | uint32_t x = *(uint32_t *)(e->data + f->offset_root); |
| 258 | return (unsigned long) (revFlag ? BREV32(x) : x); |
| 259 | } |
| 260 | }else if(rSize == LTT_LP64 || rSize == LTT_ILP64){ |
| 261 | if(f->field_size != 8) |
| 262 | g_error("The type of the field is not unsigned long: uint64_t\n"); |
| 263 | else{ |
| 264 | uint64_t x = *(uint64_t *)(e->data + f->offset_root); |
| 265 | return (unsigned long) (revFlag ? BREV64(x): x); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | long int ltt_event_get_long_int(LttEvent *e, LttField *f) |
| 271 | { |
| 272 | LttArchSize rSize = e->tracefile->trace->system_description->size; |
| 273 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 274 | e->tracefile->trace->system_description->endian ? 0:1; |
| 275 | |
| 276 | if( f->field_type->type_class != LTT_INT) |
| 277 | g_error("The type of the field is not long int\n"); |
| 278 | |
| 279 | if(rSize == LTT_LP32 || rSize == LTT_ILP32 ){ |
| 280 | if(f->field_size != 4) |
| 281 | g_error("The type of the field is not long int: int32_t\n"); |
| 282 | else{ |
| 283 | int32_t x = *(int32_t *)(e->data + f->offset_root); |
| 284 | return (long) (revFlag ? BREV32(x) : x); |
| 285 | } |
| 286 | }else if(rSize == LTT_LP64 || rSize == LTT_ILP64){ |
| 287 | if(f->field_size != 8) |
| 288 | g_error("The type of the field is not long int: int64_t\n"); |
| 289 | else{ |
| 290 | int64_t x = *(int64_t *)(e->data + f->offset_root); |
| 291 | return (long) (revFlag ? BREV64(x): x); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | float ltt_event_get_float(LttEvent *e, LttField *f) |
| 297 | { |
| 298 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 299 | e->tracefile->trace->system_description->endian ? 0:1; |
| 300 | |
| 301 | if(f->field_type->type_class != LTT_FLOAT || |
| 302 | (f->field_type->type_class == LTT_FLOAT && f->field_size != 4)) |
| 303 | g_error("The type of the field is not float\n"); |
| 304 | |
| 305 | if(revFlag == 0) return *(float *)(e->data + f->offset_root); |
| 306 | else{ |
| 307 | uint32_t aInt; |
| 308 | memcpy((void*)&aInt, e->data + f->offset_root, 4); |
| 309 | aInt = ___swab32(aInt); |
| 310 | return *((float*)&aInt); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | double ltt_event_get_double(LttEvent *e, LttField *f) |
| 315 | { |
| 316 | int revFlag = e->tracefile->trace->my_arch_endian == |
| 317 | e->tracefile->trace->system_description->endian ? 0:1; |
| 318 | |
| 319 | if(f->field_type->type_class != LTT_FLOAT || |
| 320 | (f->field_type->type_class == LTT_FLOAT && f->field_size != 8)) |
| 321 | g_error("The type of the field is not double\n"); |
| 322 | |
| 323 | if(revFlag == 0) return *(double *)(e->data + f->offset_root); |
| 324 | else{ |
| 325 | uint64_t aInt; |
| 326 | memcpy((void*)&aInt, e->data + f->offset_root, 8); |
| 327 | aInt = ___swab64(aInt); |
| 328 | return *((double *)&aInt); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /***************************************************************************** |
| 333 | * The string obtained is only valid until the next read from |
| 334 | * the same tracefile. ???? |
| 335 | ****************************************************************************/ |
| 336 | |
| 337 | char *ltt_event_get_string(LttEvent *e, LttField *f) |
| 338 | { |
| 339 | if(f->field_type->type_class != LTT_STRING) |
| 340 | g_error("The field contains no string\n"); |
| 341 | return (char*)g_strdup((char*)(e->data + f->offset_root)); |
| 342 | } |