From c37440c8ca246648f25fcb2c16292af9404b00d8 Mon Sep 17 00:00:00 2001 From: pmf Date: Thu, 4 Oct 2007 23:56:07 +0000 Subject: [PATCH] event.{c,h}: restore field access functions ltt_event_get_float() and ltt_event_get_double() still disabled pending support in markers-fields.h git-svn-id: http://ltt.polymtl.ca/svn@2606 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/ltt/event.c | 185 ++++++++++++++++++++++++++++++++++ ltt/branches/poly/ltt/event.h | 22 ++++ 2 files changed, 207 insertions(+) diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index bcb013f1..4bbb0f91 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -117,3 +117,188 @@ LttTracefile *ltt_event_position_tracefile(LttEventPosition *ep) return ep->tracefile; } +/***************************************************************************** + * These functions extract data from an event after architecture specific + * conversions + ****************************************************************************/ +guint32 ltt_event_get_unsigned(LttEvent *e, struct marker_field *f) +{ + 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; + } +} + +gint32 ltt_event_get_int(LttEvent *e, struct marker_field *f) +{ + 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; + } +} + +guint64 ltt_event_get_long_unsigned(LttEvent *e, struct marker_field *f) +{ + 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; + } +} + +gint64 ltt_event_get_long_int(LttEvent *e, struct marker_field *f) +{ + 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; + } +} + +#if 0 +float ltt_event_get_float(LttEvent *e, struct marker_field *f) +{ + 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); + } + + g_assert(f->field_type.type_class == LTT_FLOAT && f->size == 4); + + if(reverse_byte_order == 0) return *(float *)(e->data + f->offset); + else{ + void *ptr = e->data + f->offset; + guint32 value = bswap_32(*(guint32*)ptr); + return *(float*)&value; + } +} + +double ltt_event_get_double(LttEvent *e, struct marker_field *f) +{ + 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->size == 4) + return ltt_event_get_float(e, f); + + g_assert(f->field_type.type_class == LTT_FLOAT && f->size == 8); + + 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. + ****************************************************************************/ +char *ltt_event_get_string(LttEvent *e, struct marker_field *f) +{ + g_assert(f->type == LTT_TYPE_STRING); + + return (gchar*)g_strdup((gchar*)(e->data + f->offset)); +} + + diff --git a/ltt/branches/poly/ltt/event.h b/ltt/branches/poly/ltt/event.h index b45595d9..3bb05a90 100644 --- a/ltt/branches/poly/ltt/event.h +++ b/ltt/branches/poly/ltt/event.h @@ -7,6 +7,7 @@ #include #include #include +#include /* * Structure LttEvent and LttEventPosition must begin with the _exact_ same @@ -82,4 +83,25 @@ void ltt_event_position_copy(LttEventPosition *dest, LttTracefile *ltt_event_position_tracefile(LttEventPosition *ep); +/* These functions extract data from an event after architecture specific + * conversions. */ + +guint32 ltt_event_get_unsigned(LttEvent *e, struct marker_field *f); + +gint32 ltt_event_get_int(LttEvent *e, struct marker_field *f); + +guint64 ltt_event_get_long_unsigned(LttEvent *e, struct marker_field *f); + +gint64 ltt_event_get_long_int(LttEvent *e, struct marker_field *f); + +float ltt_event_get_float(LttEvent *e, struct marker_field *f); + +double ltt_event_get_double(LttEvent *e, struct marker_field *f); + + +/* The string obtained is only valid until the next read from + * the same tracefile. */ + +gchar *ltt_event_get_string(LttEvent *e, struct marker_field *f); + #endif //_LTT_EVENT_H -- 2.34.1