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