git-svn-id: http://ltt.polymtl.ca/svn@151 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / ltt / event.c
CommitLineData
6cd62ccf 1#include <stdio.h>
2#include <asm/types.h>
3#include <linux/byteorder/swab.h>
fcdf0ec2 4#include <ltt/LTTTypes.h>
6cd62ccf 5#include "parser.h"
6#include <ltt/event.h>
7
8/*****************************************************************************
9 *Function name
963b5f2d 10 * ltt_event_eventtype_id: get event type id
11 * (base id + position of the event)
6cd62ccf 12 *Input params
963b5f2d 13 * e : an instance of an event type
6cd62ccf 14 *Return value
963b5f2d 15 * unsigned : event type id
6cd62ccf 16 ****************************************************************************/
17
963b5f2d 18unsigned ltt_event_eventtype_id(LttEvent *e)
6cd62ccf 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
963b5f2d 29 * LttFacility * : the facility of the event
6cd62ccf 30 ****************************************************************************/
31
963b5f2d 32LttFacility *ltt_event_facility(LttEvent *e)
6cd62ccf 33{
963b5f2d 34 LttTrace * trace = e->tracefile->trace;
35 unsigned id = e->event_id;
36 return ltt_trace_facility_by_id(trace,id);
6cd62ccf 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
963b5f2d 45 * LttEventType * : the event type of the event
6cd62ccf 46 ****************************************************************************/
47
963b5f2d 48LttEventType *ltt_event_eventtype(LttEvent *e)
6cd62ccf 49{
963b5f2d 50 LttFacility* facility = ltt_event_facility(e);
51 if(!facility) return NULL;
52 return facility->events[e->event_id - facility->base_id];
6cd62ccf 53}
54
55/*****************************************************************************
56 *Function name
963b5f2d 57 * ltt_event_field : get the root field of the event
6cd62ccf 58 *Input params
963b5f2d 59 * e : an instance of an event type
6cd62ccf 60 *Return value
963b5f2d 61 * LttField * : the root field of the event
6cd62ccf 62 ****************************************************************************/
63
963b5f2d 64LttField *ltt_event_field(LttEvent *e)
6cd62ccf 65{
963b5f2d 66 LttEventType * event_type = ltt_event_eventtype(e);
67 if(!event_type) return NULL;
68 return event_type->root_field;
6cd62ccf 69}
70
71/*****************************************************************************
72 *Function name
963b5f2d 73 * ltt_event_time : get the time of the event
6cd62ccf 74 *Input params
75 * e : an instance of an event type
76 *Return value
963b5f2d 77 * LttTime : the time of the event
6cd62ccf 78 ****************************************************************************/
79
963b5f2d 80LttTime ltt_event_time(LttEvent *e)
6cd62ccf 81{
963b5f2d 82 return e->event_time;
6cd62ccf 83}
84
85/*****************************************************************************
86 *Function name
963b5f2d 87 * ltt_event_time : get the cycle count of the event
6cd62ccf 88 *Input params
89 * e : an instance of an event type
90 *Return value
963b5f2d 91 * LttCycleCount : the cycle count of the event
6cd62ccf 92 ****************************************************************************/
93
963b5f2d 94LttCycleCount ltt_event_cycle_count(LttEvent *e)
6cd62ccf 95{
963b5f2d 96 return e->event_cycle_count;
6cd62ccf 97}
98
99/*****************************************************************************
100 *Function name
963b5f2d 101 * ltt_event_cpu_i: get the cpu id where the event happens
6cd62ccf 102 *Input params
103 * e : an instance of an event type
104 *Return value
963b5f2d 105 * unsigned : the cpu id
6cd62ccf 106 ****************************************************************************/
107
963b5f2d 108unsigned ltt_event_cpu_id(LttEvent *e)
109{
110 return (unsigned)atoi(e->tracefile->name);
6cd62ccf 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
963b5f2d 122void *ltt_event_data(LttEvent *e)
6cd62ccf 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
963b5f2d 140unsigned ltt_event_field_element_number(LttEvent *e, LttField *f)
6cd62ccf 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
6cd62ccf 158 ****************************************************************************/
159
963b5f2d 160void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i)
6cd62ccf 161{
162 if(f->field_type->type_class != LTT_ARRAY &&
163 f->field_type->type_class != LTT_SEQUENCE)
963b5f2d 164 return ;
6cd62ccf 165
963b5f2d 166 if(f->field_type->element_number < i || i == 0) return;
6cd62ccf 167
168 f->current_element = i - 1;
6cd62ccf 169}
170
171/*****************************************************************************
172 * These functions extract data from an event after architecture specific
173 * conversions
174 ****************************************************************************/
175
963b5f2d 176unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f)
6cd62ccf 177{
963b5f2d 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;
6cd62ccf 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
963b5f2d 210int ltt_event_get_int(LttEvent *e, LttField *f)
6cd62ccf 211{
963b5f2d 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;
6cd62ccf 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
963b5f2d 243unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f)
6cd62ccf 244{
963b5f2d 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;
6cd62ccf 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
963b5f2d 270long int ltt_event_get_long_int(LttEvent *e, LttField *f)
6cd62ccf 271{
963b5f2d 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;
6cd62ccf 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
963b5f2d 296float ltt_event_get_float(LttEvent *e, LttField *f)
6cd62ccf 297{
963b5f2d 298 int revFlag = e->tracefile->trace->my_arch_endian ==
299 e->tracefile->trace->system_description->endian ? 0:1;
6cd62ccf 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
963b5f2d 314double ltt_event_get_double(LttEvent *e, LttField *f)
6cd62ccf 315{
963b5f2d 316 int revFlag = e->tracefile->trace->my_arch_endian ==
317 e->tracefile->trace->system_description->endian ? 0:1;
6cd62ccf 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
963b5f2d 337char *ltt_event_get_string(LttEvent *e, LttField *f)
6cd62ccf 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}
This page took 0.036095 seconds and 4 git commands to generate.