-#include <stdio.h>
-#include <asm/types.h>
-#include <linux/byteorder/swab.h>
-#include <ltt/LTTTypes.h>
-#include "parser.h"
-#include <ltt/event.h>
-
-/*****************************************************************************
- *Function name
- * ltt_event_eventtype_id: get event type id
- * (base id + position of the event)
- *Input params
- * e : an instance of an event type
- *Return value
- * unsigned : event type id
- ****************************************************************************/
-unsigned ltt_event_eventtype_id(LttEvent *e)
-{
- return (unsigned) e->event_id;
-}
+#include <ltt/event.h>
+#include <ltt/ltt-types.h>
/*****************************************************************************
*Function name
- * ltt_event_facility : get the facility of the event
+ * ltt_event_position_get : get the event position data
*Input params
* e : an instance of an event type
- *Return value
- * LttFacility * : the facility of the event
+ * ep : a pointer to event's position structure
+ * tf : tracefile pointer
+ * block : current block
+ * offset : current offset
+ * tsc : current tsc
****************************************************************************/
-
-LttFacility *ltt_event_facility(LttEvent *e)
+void ltt_event_position_get(LttEventPosition *ep, LttTracefile **tf,
+ guint *block, guint *offset, guint64 *tsc)
{
- LttTrace * trace = e->tracefile->trace;
- unsigned id = e->event_id;
- return ltt_trace_facility_by_id(trace,id);
+ *tf = ep->tracefile;
+ *block = ep->block;
+ *offset = ep->offset;
+ *tsc = ep->tsc;
}
-/*****************************************************************************
- *Function name
- * ltt_event_eventtype : get the event type of the event
- *Input params
- * e : an instance of an event type
- *Return value
- * LttEventType * : the event type of the event
- ****************************************************************************/
-LttEventType *ltt_event_eventtype(LttEvent *e)
+void ltt_event_position_set(LttEventPosition *ep, LttTracefile *tf,
+ guint block, guint offset, guint64 tsc)
{
- LttFacility* facility = ltt_event_facility(e);
- if(!facility) return NULL;
- return facility->events[e->event_id - facility->base_id];
+ ep->tracefile = tf;
+ ep->block = block;
+ ep->offset = offset;
+ ep->tsc = tsc;
}
-/*****************************************************************************
- *Function name
- * ltt_event_field : get the root field of the event
- *Input params
- * e : an instance of an event type
- *Return value
- * LttField * : the root field of the event
- ****************************************************************************/
-
-LttField *ltt_event_field(LttEvent *e)
-{
- LttEventType * event_type = ltt_event_eventtype(e);
- if(!event_type) return NULL;
- return event_type->root_field;
-}
/*****************************************************************************
*Function name
- * ltt_event_time : get the time of the event
+ * ltt_event_position : get the event's position
*Input params
- * e : an instance of an event type
- *Return value
- * LttTime : the time of the event
+ * e : an instance of an event type
+ * ep : a pointer to event's position structure
****************************************************************************/
-LttTime ltt_event_time(LttEvent *e)
+void ltt_event_position(LttEvent *e, LttEventPosition *ep)
{
- return e->event_time;
+ ep->tracefile = e->tracefile;
+ ep->block = e->block;
+ ep->offset = e->offset;
+ ep->tsc = e->tsc;
}
-/*****************************************************************************
- *Function name
- * ltt_event_time : get the cycle count of the event
- *Input params
- * e : an instance of an event type
- *Return value
- * LttCycleCount : the cycle count of the event
- ****************************************************************************/
-
-LttCycleCount ltt_event_cycle_count(LttEvent *e)
+LttEventPosition * ltt_event_position_new()
{
- return e->event_cycle_count;
+ return g_new(LttEventPosition, 1);
}
-/*****************************************************************************
- *Function name
- * ltt_event_cpu_i: get the cpu id where the event happens
- *Input params
- * e : an instance of an event type
- *Return value
- * unsigned : the cpu id
- ****************************************************************************/
-
-unsigned ltt_event_cpu_id(LttEvent *e)
-{
- return (unsigned)atoi(e->tracefile->name);
-}
/*****************************************************************************
- *Function name
- * ltt_event_data : get the raw data for the event
- *Input params
- * e : an instance of an event type
- *Return value
- * void * : pointer to the raw data for the event
+ * Function name
+ * ltt_event_position_compare : compare two positions
+ * A NULL value is infinite.
+ * Input params
+ * ep1 : a pointer to event's position structure
+ * ep2 : a pointer to event's position structure
+ * Return
+ * -1 is ep1 < ep2
+ * 1 if ep1 > ep2
+ * 0 if ep1 == ep2
****************************************************************************/
-void *ltt_event_data(LttEvent *e)
+
+gint ltt_event_position_compare(const LttEventPosition *ep1,
+ const LttEventPosition *ep2)
{
- return e->data;
+ if(ep1 == NULL && ep2 == NULL)
+ return 0;
+ if(ep1 != NULL && ep2 == NULL)
+ return -1;
+ if(ep1 == NULL && ep2 != NULL)
+ return 1;
+
+ if(ep1->tracefile != ep2->tracefile)
+ g_error("ltt_event_position_compare on different tracefiles makes no sense");
+
+ if(ep1->block < ep2->block)
+ return -1;
+ if(ep1->block > ep2->block)
+ return 1;
+ if(ep1->offset < ep2->offset)
+ return -1;
+ if(ep1->offset > ep2->offset)
+ return 1;
+ return 0;
}
/*****************************************************************************
- *Function name
- * ltt_event_field_element_number
- * : The number of elements in a sequence field is specific
- * to each event. This function returns the number of
- * elements for an array or sequence field in an event.
- *Input params
- * e : an instance of an event type ????
- * f : a field of the instance
- *Return value
- * unsigned : the number of elements for an array/sequence field
+ * Function name
+ * ltt_event_position_copy : copy position
+ * Input params
+ * src : a pointer to event's position structure source
+ * dest : a pointer to event's position structure dest
+ * Return
+ * void
****************************************************************************/
-
-unsigned ltt_event_field_element_number(LttEvent *e, LttField *f)
+void ltt_event_position_copy(LttEventPosition *dest,
+ const LttEventPosition *src)
{
- if(f->field_type->type_class != LTT_ARRAY &&
- f->field_type->type_class != LTT_SEQUENCE)
- return 0;
-
- return f->field_type->element_number;
+ if(src == NULL)
+ dest = NULL;
+ else
+ *dest = *src;
}
-/*****************************************************************************
- *Function name
- * ltt_event_field_element_select
- * : Set the currently selected element for a sequence or
- * array field
- *Input params
- * e : an instance of an event type ????
- * f : a field of the instance
- * i : the ith element
- ****************************************************************************/
-void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i)
-{
- if(f->field_type->type_class != LTT_ARRAY &&
- f->field_type->type_class != LTT_SEQUENCE)
- return ;
-
- if(f->field_type->element_number < i || i == 0) return;
- f->current_element = i - 1;
+LttTracefile *ltt_event_position_tracefile(LttEventPosition *ep)
+{
+ return ep->tracefile;
}
/*****************************************************************************
* These functions extract data from an event after architecture specific
* conversions
****************************************************************************/
-
-unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f)
+guint32 ltt_event_get_unsigned(LttEvent *e, struct marker_field *f)
{
- LttArchSize rSize = e->tracefile->trace->system_description->size;
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
- LttTypeEnum t = f->field_type->type_class;
-
- if(t != LTT_UINT || t != LTT_ENUM)
- g_error("The type of the field is not unsigned int\n");
-
- if(rSize == LTT_LP32){
- if(f->field_size != 2)
- g_error("The type of the field is not unsigned int: uint16_t\n");
- else{
- uint16_t x = *(uint16_t *)(e->data + f->offset_root);
- return (unsigned) (revFlag ? BREV16(x) : x);
- }
- }else if(rSize == LTT_ILP32 || rSize == LTT_LP64){
- if(f->field_size != 4)
- g_error("The type of the field is not unsigned int: uint32_t\n");
- else{
- uint32_t x = *(uint32_t *)(e->data + f->offset_root);
- return (unsigned) (revFlag ? BREV32(x): x);
- }
- }else if(rSize == LTT_ILP64){
- if(f->field_size != 8)
- g_error("The type of the field is not unsigned int: uint64_t\n");
- else{
- uint64_t x = *(uint64_t *)(e->data + f->offset_root);
- return (unsigned) (revFlag ? BREV64(x): x);
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ reverse_byte_order = LTT_GET_BO(e->tracefile);
+ }
+
+ switch(f->size) {
+ case 1:
+ {
+ guint8 x = *(guint8 *)(e->data + f->offset);
+ return (guint32) x;
}
+ break;
+ case 2:
+ return (guint32)ltt_get_uint16(reverse_byte_order, e->data + f->offset);
+ break;
+ case 4:
+ return (guint32)ltt_get_uint32(reverse_byte_order, e->data + f->offset);
+ break;
+ case 8:
+ default:
+ g_critical("ltt_event_get_unsigned : field size %i unknown", f->size);
+ return 0;
+ break;
}
}
-int ltt_event_get_int(LttEvent *e, LttField *f)
+gint32 ltt_event_get_int(LttEvent *e, struct marker_field *f)
{
- LttArchSize rSize = e->tracefile->trace->system_description->size;
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
-
- if(f->field_type->type_class != LTT_INT)
- g_error("The type of the field is not int\n");
-
- if(rSize == LTT_LP32){
- if(f->field_size != 2)
- g_error("The type of the field is not int: int16_t\n");
- else{
- int16_t x = *(int16_t *)(e->data + f->offset_root);
- return (int) (revFlag ? BREV16(x) : x);
- }
- }else if(rSize == LTT_ILP32 || rSize == LTT_LP64){
- if(f->field_size != 4)
- g_error("The type of the field is not int: int32_t\n");
- else{
- int32_t x = *(int32_t *)(e->data + f->offset_root);
- return (int) (revFlag ? BREV32(x): x);
- }
- }else if(rSize == LTT_ILP64){
- if(f->field_size != 8)
- g_error("The type of the field is not int: int64_t\n");
- else{
- int64_t x = *(int64_t *)(e->data + f->offset_root);
- return (int) (revFlag ? BREV64(x): x);
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ reverse_byte_order = LTT_GET_BO(e->tracefile);
+ }
+
+ switch(f->size) {
+ case 1:
+ {
+ gint8 x = *(gint8 *)(e->data + f->offset);
+ return (gint32) x;
}
+ break;
+ case 2:
+ return (gint32)ltt_get_int16(reverse_byte_order, e->data + f->offset);
+ break;
+ case 4:
+ return (gint32)ltt_get_int32(reverse_byte_order, e->data + f->offset);
+ break;
+ case 8:
+ default:
+ g_critical("ltt_event_get_int : field size %i unknown", f->size);
+ return 0;
+ break;
}
}
-unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f)
+guint64 ltt_event_get_long_unsigned(LttEvent *e, struct marker_field *f)
{
- LttArchSize rSize = e->tracefile->trace->system_description->size;
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
- LttTypeEnum t = f->field_type->type_class;
-
- if(t != LTT_UINT || t != LTT_ENUM)
- g_error("The type of the field is not unsigned long\n");
-
- if(rSize == LTT_LP32 || rSize == LTT_ILP32 ){
- if(f->field_size != 4)
- g_error("The type of the field is not unsigned long: uint32_t\n");
- else{
- uint32_t x = *(uint32_t *)(e->data + f->offset_root);
- return (unsigned long) (revFlag ? BREV32(x) : x);
- }
- }else if(rSize == LTT_LP64 || rSize == LTT_ILP64){
- if(f->field_size != 8)
- g_error("The type of the field is not unsigned long: uint64_t\n");
- else{
- uint64_t x = *(uint64_t *)(e->data + f->offset_root);
- return (unsigned long) (revFlag ? BREV64(x): x);
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ reverse_byte_order = LTT_GET_BO(e->tracefile);
+ }
+
+ switch(f->size) {
+ case 1:
+ {
+ guint8 x = *(guint8 *)(e->data + f->offset);
+ return (guint64) x;
}
+ break;
+ case 2:
+ return (guint64)ltt_get_uint16(reverse_byte_order, e->data + f->offset);
+ break;
+ case 4:
+ return (guint64)ltt_get_uint32(reverse_byte_order, e->data + f->offset);
+ break;
+ case 8:
+ return ltt_get_uint64(reverse_byte_order, e->data + f->offset);
+ break;
+ default:
+ g_critical("ltt_event_get_long_unsigned : field size %i unknown", f->size);
+ return 0;
+ break;
}
}
-long int ltt_event_get_long_int(LttEvent *e, LttField *f)
+gint64 ltt_event_get_long_int(LttEvent *e, struct marker_field *f)
{
- LttArchSize rSize = e->tracefile->trace->system_description->size;
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
-
- if( f->field_type->type_class != LTT_INT)
- g_error("The type of the field is not long int\n");
-
- if(rSize == LTT_LP32 || rSize == LTT_ILP32 ){
- if(f->field_size != 4)
- g_error("The type of the field is not long int: int32_t\n");
- else{
- int32_t x = *(int32_t *)(e->data + f->offset_root);
- return (long) (revFlag ? BREV32(x) : x);
- }
- }else if(rSize == LTT_LP64 || rSize == LTT_ILP64){
- if(f->field_size != 8)
- g_error("The type of the field is not long int: int64_t\n");
- else{
- int64_t x = *(int64_t *)(e->data + f->offset_root);
- return (long) (revFlag ? BREV64(x): x);
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ reverse_byte_order = LTT_GET_BO(e->tracefile);
+ }
+
+ switch(f->size) {
+ case 1:
+ {
+ gint8 x = *(gint8 *)(e->data + f->offset);
+ return (gint64) x;
}
+ break;
+ case 2:
+ return (gint64)ltt_get_int16(reverse_byte_order, e->data + f->offset);
+ break;
+ case 4:
+ return (gint64)ltt_get_int32(reverse_byte_order, e->data + f->offset);
+ break;
+ case 8:
+ return ltt_get_int64(reverse_byte_order, e->data + f->offset);
+ break;
+ default:
+ g_critical("ltt_event_get_long_int : field size %i unknown", f->size);
+ return 0;
+ break;
}
}
-float ltt_event_get_float(LttEvent *e, LttField *f)
+#if 0
+float ltt_event_get_float(LttEvent *e, struct marker_field *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ g_assert(LTT_HAS_FLOAT(e->tracefile));
+ reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile);
+ }
- if(f->field_type->type_class != LTT_FLOAT ||
- (f->field_type->type_class == LTT_FLOAT && f->field_size != 4))
- g_error("The type of the field is not float\n");
+ g_assert(f->field_type.type_class == LTT_FLOAT && f->size == 4);
- if(revFlag == 0) return *(float *)(e->data + f->offset_root);
+ if(reverse_byte_order == 0) return *(float *)(e->data + f->offset);
else{
- uint32_t aInt;
- memcpy((void*)&aInt, e->data + f->offset_root, 4);
- aInt = ___swab32(aInt);
- return *((float*)&aInt);
+ void *ptr = e->data + f->offset;
+ guint32 value = bswap_32(*(guint32*)ptr);
+ return *(float*)&value;
}
}
-double ltt_event_get_double(LttEvent *e, LttField *f)
+double ltt_event_get_double(LttEvent *e, struct marker_field *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order;
+ if(unlikely(f->attributes & LTT_ATTRIBUTE_NETWORK_BYTE_ORDER)) {
+ reverse_byte_order = (g_ntohs(0x1) != 0x1);
+ } else {
+ g_assert(LTT_HAS_FLOAT(e->tracefile));
+ reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile);
+ }
- if(f->field_type->type_class != LTT_FLOAT ||
- (f->field_type->type_class == LTT_FLOAT && f->field_size != 8))
- g_error("The type of the field is not double\n");
+ if(f->size == 4)
+ return ltt_event_get_float(e, f);
+
+ g_assert(f->field_type.type_class == LTT_FLOAT && f->size == 8);
- if(revFlag == 0) return *(double *)(e->data + f->offset_root);
- else{
- uint64_t aInt;
- memcpy((void*)&aInt, e->data + f->offset_root, 8);
- aInt = ___swab64(aInt);
- return *((double *)&aInt);
+ if(reverse_byte_order == 0) return *(double *)(e->data + f->offset);
+ else {
+ void *ptr = e->data + f->offset;
+ guint64 value = bswap_64(*(guint64*)ptr);
+ return *(double*)&value;
}
}
+#endif
/*****************************************************************************
* The string obtained is only valid until the next read from
- * the same tracefile. ????
+ * the same tracefile.
****************************************************************************/
-
-char *ltt_event_get_string(LttEvent *e, LttField *f)
+char *ltt_event_get_string(LttEvent *e, struct marker_field *f)
{
- if(f->field_type->type_class != LTT_STRING)
- g_error("The field contains no string\n");
- return (char*)g_strdup((char*)(e->data + f->offset_root));
+ g_assert(f->type == LTT_TYPE_STRING);
+
+ return (gchar*)g_strdup((gchar*)(e->data + f->offset));
}
+
+