1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #include "ltt-private.h"
31 static unsigned intSizes
[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
35 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
36 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
40 static unsigned floatSizes
[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
43 #define FLOAT_SIZES_NUMBER 7
46 /*****************************************************************************
48 * ltt_eventtype_name : get the name of the event type
52 * GQuark : the name of the event type
53 ****************************************************************************/
55 GQuark
ltt_eventtype_name(LttEventType
*et
)
60 /*****************************************************************************
62 * ltt_eventtype_description : get the description of the event type
66 * char * : the description of the event type
67 ****************************************************************************/
69 gchar
*ltt_eventtype_description(LttEventType
*et
)
71 return et
->description
;
74 /*****************************************************************************
76 * ltt_eventtype_facility : get the facility which contains the event type
80 * LttFacility * : the facility
81 ****************************************************************************/
83 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
88 /*****************************************************************************
90 * ltt_eventtype_id : get the id of the event type
95 ****************************************************************************/
97 guint8
ltt_eventtype_id(LttEventType
*et
)
102 /*****************************************************************************
104 * ltt_field_name : get the name of the field
108 * char * : the name of the type
109 ****************************************************************************/
111 GQuark
ltt_field_name(LttField
*f
)
115 /*****************************************************************************
117 * ltt_type_class : get the type class of the type
121 * LttTypeEnum : the type class of the type
122 ****************************************************************************/
124 LttTypeEnum
ltt_type_class(LttType
*t
)
126 return t
->type_class
;
129 /*****************************************************************************
131 * ltt_type_size : obtain the type size. The size is the number of bytes
132 * for primitive types (INT, UINT, FLOAT, ENUM)
133 * or the size for the unsigned integer length count for
140 * returns 0 if erroneous, and show a critical warning message.
141 ****************************************************************************/
143 size_t ltt_type_size(LttTrace
* trace
, LttType
*t
)
147 switch(t
->type_class
) {
153 if(likely(t
->size
< INT_SIZES_NUMBER
))
154 size
= intSizes
[t
->size
];
159 if(likely(t
->size
< FLOAT_SIZES_NUMBER
))
160 size
= floatSizes
[t
->size
];
182 g_warning("no size known for the type");
186 /*****************************************************************************
188 * ltt_type_element_type : obtain the type of nested elements for arrays
193 * LttType : the type of nested element of array or sequence
194 ****************************************************************************/
196 LttType
*ltt_type_element_type(LttType
*t
)
198 LttType
*element_type
;
201 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
204 if(t
->type_class
== LTT_ARRAY
)
205 field
= &g_array_index(t
->fields
, LttField
, 0);
207 field
= &g_array_index(t
->fields
, LttField
, 1);
208 element_type
= ltt_field_type(field
);
214 /*****************************************************************************
216 * ltt_type_element_number : obtain the number of elements for enums
220 * unsigned : the number of elements for arrays
221 ****************************************************************************/
222 unsigned ltt_type_element_number(LttType
*t
)
226 if(likely(t
->type_class
== LTT_ENUM
))
227 ret
= g_hash_table_size(t
->enum_map
);
232 /*****************************************************************************
234 * ltt_type_member_number : obtain the number of data members for structure
238 * unsigned : the number of members for structure
239 ****************************************************************************/
241 unsigned ltt_type_member_number(LttType
*t
)
245 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
246 ret
= t
->fields
->len
;
252 /*****************************************************************************
254 * ltt_enum_string_get : for enumerations, obtain the symbolic string
255 * associated with a value (0 to n - 1 for an
256 * enumeration of n elements)
259 * i : index of the member
261 * char * : symbolic string associated with a value
262 ****************************************************************************/
264 GQuark
ltt_enum_string_get(LttType
*t
, gulong i
)
266 if(likely(t
->type_class
== LTT_ENUM
))
267 return (GQuark
)g_hash_table_lookup(t
->enum_map
, (gpointer
)i
);
272 /*****************************************************************************
274 * ltt_field_element : obtain the field of nested elements for arrays and
279 * LttField * : the field of the nested element
280 ****************************************************************************/
282 LttField
*ltt_field_element(LttField
*f
)
284 LttField
*nest
= NULL
;
286 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
287 f
->field_type
->type_class
== LTT_SEQUENCE
))
294 /*****************************************************************************
296 * ltt_field_member_by_name : obtain the field of data members for structure
299 * name : name of the field
301 * LttField * : the field of the nested element
302 ****************************************************************************/
304 LttField
*ltt_field_member_by_name(LttField
*f
, GQuark name
)
306 LttField
*field_member
;
308 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
309 f
->field_type
.type_class
== LTT_UNION
);
311 field_member
= g_datalist_id_get_data(&f
->field_type
.fields_by_name
, name
);
317 /*****************************************************************************
319 * ltt_field_member : obtain the field of data members for structure
322 * i : index of member field
324 * LttField * : the field of the nested element
325 ****************************************************************************/
327 LttField
*ltt_field_member(LttField
*f
, guint i
)
329 LttField
*field_member
;
331 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
332 f
->field_type
.type_class
== LTT_UNION
);
333 g_assert(i
< f
->field_type
.fields
->len
);
335 field_member
= &g_array_index(f
->field_type
.fields
, LttField
, i
);
340 /*****************************************************************************
342 * ltt_field_type : obtain the type of the field
346 * ltt_tyoe * : the type of field
347 ****************************************************************************/
349 LttType
*ltt_field_type(LttField
*f
)
351 if(unlikely(!f
))return NULL
;
352 return &f
->field_type
;
355 int ltt_field_size(LttField
* f
)
357 if(unlikely(!f
))return 0;
358 return f
->field_size
;
362 /*****************************************************************************
364 * ltt_eventtype_num_fields : get the number of fields of the event
366 * e : an instance of an event type
368 * guint : number of fields
369 ****************************************************************************/
371 guint
ltt_eventtype_num_fields(LttEventType
*event_type
)
373 if(unlikely(!event_type
)) return NULL
;
375 return event_type
->fields
->len
;
378 /*****************************************************************************
380 * ltt_eventtype_field : get the i th field of the event
382 * e : an instance of an event type
385 * LttField * : The requested field, or NULL
386 ****************************************************************************/
388 LttField
*ltt_eventtype_field(LttEventType
*event_type
, guint i
)
390 if(unlikely(!event_type
)) return NULL
;
392 if(i
>= event_type
->fields
->len
) return NULL
;
394 return &g_array_index(event_type
->fields
, LttField
, i
);
398 /*****************************************************************************
400 * ltt_eventtype_field_by_name : get a field of the event
402 * e : an instance of an event type
405 * LttField * : The requested field, or NULL
406 ****************************************************************************/
408 LttField
*ltt_eventtype_field_by_name(LttEventType
*event_type
, GQuark name
)
410 if(unlikely(!event_type
)) return NULL
;
412 return (LttField
*)g_datalist_id_get_data(&event_type
->fields_by_name
, name
);
This page took 0.038101 seconds and 4 git commands to generate.