* MA 02111-1307, USA.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <glib.h>
#include <asm/types.h>
-#include <linux/byteorder/swab.h>
+#include <byteswap.h>
#include "parser.h"
#include <ltt/ltt.h>
#include <ltt/ltt-types.h>
+
+void compute_fields_offsets(LttTracefile *tf, LttField *field, off_t *offset,
+ void *root);
+
+
+
+
LttEvent *ltt_event_new()
{
return g_new(LttEvent, 1);
}
+#if 0
+/* Use get_field_type_size instead */
/*****************************************************************************
*Function name
* ltt_event_refresh_fields : refresh fields of an event
return size;
}
+#endif //0
+
/*****************************************************************************
*Function name
* unsigned : event type id
****************************************************************************/
-unsigned ltt_event_eventtype_id(LttEvent *e)
+unsigned ltt_event_eventtype_id(const LttEvent *e)
{
return (unsigned) e->event_id;
}
* LttFacility * : the facility of the event
****************************************************************************/
-LttFacility *ltt_event_facility(LttEvent *e)
+LttFacility *ltt_event_facility(const LttEvent *e)
{
LttTrace * trace = e->tracefile->trace;
- unsigned id = e->event_id;
- return ltt_trace_facility_by_id(trace,id);
+ unsigned id = e->facility_id;
+ LttFacility *facility = ltt_trace_facility_by_id(trace,id);
+
+ g_assert(facility->exists);
+
+ return facility;
}
/*****************************************************************************
*Function name
- * ltt_event_eventtype : get the event type of the event
+ * ltt_event_facility_id : get the facility id of the event
*Input params
- * e : an instance of an event type
+ * e : an instance of an event type
*Return value
- * LttEventType * : the event type of the event
+ * unsigned : the facility of the event
****************************************************************************/
-LttEventType *ltt_event_eventtype(LttEvent *e)
+unsigned ltt_event_facility_id(const LttEvent *e)
{
- LttFacility* facility = ltt_event_facility(e);
- if(!facility) return NULL;
- return facility->events[e->event_id - facility->base_id];
+ return e->facility_id;
}
/*****************************************************************************
*Function name
- * ltt_event_field : get the root field of the event
+ * ltt_event_eventtype : get the event type of the event
*Input params
- * e : an instance of an event type
+ * e : an instance of an event type
*Return value
- * LttField * : the root field of the event
+ * LttEventType * : the event type of the event
****************************************************************************/
-LttField *ltt_event_field(LttEvent *e)
+LttEventType *ltt_event_eventtype(const LttEvent *e)
{
- LttField * field;
- LttEventType * event_type = ltt_event_eventtype(e);
- if(unlikely(!event_type)) return NULL;
- field = event_type->root_field;
- if(unlikely(!field)) return NULL;
-
- //check if the field need refresh
- if(likely(e->which_block != event_type->latest_block ||
- e->which_event != event_type->latest_event)){
-
- event_type->latest_block = e->which_block;
- event_type->latest_event = e->which_event;
-
- if(unlikely(field->field_fixed != 1))
- ltt_event_refresh_fields(0, 0, field, e->data,
- e->tracefile->trace->reverse_byte_order);
- }
- return field;
+ LttFacility* facility = ltt_event_facility(e);
+ if(!facility) return NULL;
+ return &g_array_index(facility->events, LttEventType, e->event_id);
}
+
/*****************************************************************************
*Function name
* ltt_event_time : get the time of the event
* LttTime : the time of the event
****************************************************************************/
-LttTime ltt_event_time(LttEvent *e)
+LttTime ltt_event_time(const LttEvent *e)
{
return e->event_time;
}
* LttCycleCount : the cycle count of the event
****************************************************************************/
-LttCycleCount ltt_event_cycle_count(LttEvent *e)
+LttCycleCount ltt_event_cycle_count(const LttEvent *e)
{
- return e->event_cycle_count;
+ return e->tsc;
}
+
+
/*****************************************************************************
*Function name
- * ltt_event_position : get the event's position
+ * ltt_event_position_get : get the event position data
*Input params
* e : an instance of an event type
* ep : a pointer to event's position structure
+ * tf : tracefile pointer
+ * block : current block
+ * offset : current offset
+ * tsc : current tsc
****************************************************************************/
-
-void ltt_event_position(LttEvent *e, LttEventPosition *ep)
+void ltt_event_position_get(LttEventPosition *ep, LttTracefile **tf,
+ guint *block, guint *offset, guint64 *tsc)
{
- ep->block_num = e->which_block;
- ep->event_num = e->which_event;
- ep->event_time = e->event_time;
- ep->event_cycle_count = e->event_cycle_count;
- ep->heart_beat_number = e->tracefile->cur_heart_beat_number;
- ep->old_position = TRUE;
- ep->event_offset = e->data - e->tracefile->buffer - EVENT_HEADER_SIZE ;
- ep->tf = e->tracefile;
- ep->overflow_nsec = e->overflow_nsec;
- /* This is a workaround for fast position seek */
- ep->last_event_pos = e->last_event_pos;
- ep->prev_block_end_time = e->prev_block_end_time;
- ep->prev_event_time = e->prev_event_time;
- ep->pre_cycle_count = e->pre_cycle_count;
- ep->count = e->count;
- ep->last_heartbeat = e->last_heartbeat;
-
- /* end of workaround */
+ *tf = ep->tracefile;
+ *block = ep->block;
+ *offset = ep->offset;
+ *tsc = ep->tsc;
}
-LttEventPosition * ltt_event_position_new()
-{
- return g_new(LttEventPosition, 1);
-}
/*****************************************************************************
*Function name
- * ltt_event_position_get : get the block number and index of the event
+ * ltt_event_position : get the event's position
*Input params
- * ep : a pointer to event's position structure
- * block_number : the block number of the event
- * index_in_block : the index of the event within the block
+ * e : an instance of an event type
+ * ep : a pointer to event's position structure
****************************************************************************/
-void ltt_event_position_get(LttEventPosition *ep,
- unsigned *block_number, unsigned *index_in_block, LttTracefile ** tf)
+void ltt_event_position(LttEvent *e, LttEventPosition *ep)
{
- *block_number = ep->block_num;
- *index_in_block = ep->event_num;
- *tf = ep->tf;
+ ep->tracefile = e->tracefile;
+ ep->block = e->block;
+ ep->offset = e->offset;
+ ep->tsc = e->tsc;
}
-/*****************************************************************************
- *Function name
- * ltt_event_position_set : set the block number and index of the event
- * It does put the old_position gboolean to FALSE, as it is impossible
- * to know the quick position to seek in the tracefile.
- *Input params
- * ep : a pointer to event's position structure
- * block_number : the block number of the event
- * index_in_block : the index of the event within the block
- ****************************************************************************/
-
-void ltt_event_position_set(LttEventPosition *ep,
- unsigned block_number, unsigned index_in_block)
+LttEventPosition * ltt_event_position_new()
{
- if(ep->block_num != block_number || ep->event_num != index_in_block)
- ep->old_position = FALSE;
-
- ep->block_num = block_number;
- ep->event_num = index_in_block;
-
+ return g_new(LttEventPosition, 1);
}
+
/*****************************************************************************
* Function name
* ltt_event_position_compare : compare two positions
gint ltt_event_position_compare(const LttEventPosition *ep1,
const LttEventPosition *ep2)
{
- if(ep1->tf != ep2->tf)
- g_error("ltt_event_position_compare on different tracefiles makes no sense");
if(ep1 == NULL && ep2 == NULL)
return 0;
if(ep1 != NULL && ep2 == NULL)
return -1;
if(ep1 == NULL && ep2 != NULL)
return 1;
-
- if(ep1->block_num < ep2->block_num)
- return -1;
- if(ep1->block_num > ep2->block_num)
- return 1;
- if(ep1->event_num < ep2->event_num)
- return -1;
- if(ep1->event_num > ep2->event_num)
- return 1;
- return 0;
-}
-
-/*****************************************************************************
- * Function name
- * ltt_event_event_position_compare : compare two positions, one in event,
- * other in position opaque structure.
- * Input params
- * event : a pointer to event structure
- * ep : a pointer to event's position structure
- * Return
- * -1 is event < ep
- * 1 if event > ep
- * 0 if event == ep
- ****************************************************************************/
-
-gint ltt_event_event_position_compare(const LttEvent *event,
- const LttEventPosition *ep)
-{
- if(event == NULL && ep == NULL)
- return 0;
- if(event != NULL && ep == NULL)
- return -1;
- if(event == NULL && ep != NULL)
- return 1;
- g_assert(event->tracefile == ep->tf);
-
- if(event->which_block < ep->block_num)
+ 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(event->which_block > ep->block_num)
+ if(ep1->block > ep2->block)
return 1;
- if(event->which_event < ep->event_num)
+ if(ep1->offset < ep2->offset)
return -1;
- if(event->which_event > ep->event_num)
+ if(ep1->offset > ep2->offset)
return 1;
return 0;
}
}
+
+LttTracefile *ltt_event_position_tracefile(LttEventPosition *ep)
+{
+ return ep->tracefile;
+}
+
/*****************************************************************************
*Function name
* ltt_event_cpu_i: get the cpu id where the event happens
****************************************************************************/
unsigned ltt_event_cpu_id(LttEvent *e)
-{
- gchar * c1, * c2, * c3;
- c1 = strrchr(e->tracefile->name,'\\');
- c2 = strrchr(e->tracefile->name,'/');
- if(c1 == NULL && c2 == NULL){
- return (unsigned)atoi(e->tracefile->name);
- }else if(c1 == NULL){
- c2++;
- return (unsigned)atoi(c2);
- }else if(c2 == NULL){
- c1++;
- return (unsigned)atoi(c1);
- }else{
- c3 = (c1 > c2) ? c1 : c2;
- c3++;
- return (unsigned)atoi(c3);
- }
+{
+ return e->tracefile->cpu_num;
}
/*****************************************************************************
*Return value
* unsigned : the number of elements for an array/sequence field
****************************************************************************/
-
-unsigned ltt_event_field_element_number(LttEvent *e, LttField *f)
+guint64 ltt_event_field_element_number(LttEvent *e, LttField *f)
{
- if(f->field_type->type_class != LTT_ARRAY &&
- f->field_type->type_class != LTT_SEQUENCE)
+ if(f->field_type.type_class != LTT_ARRAY &&
+ f->field_type.type_class != LTT_SEQUENCE)
return 0;
- if(f->field_type->type_class == LTT_ARRAY)
- return f->field_type->element_number;
- return (unsigned) getIntNumber(e->tracefile->trace->reverse_byte_order,
- f->sequ_number_size, e + f->offset_root);
+ if(f->field_type.type_class == LTT_ARRAY)
+ return f->field_type.size;
+ return ltt_event_get_long_unsigned(e, &g_array_index(f->field_type.fields,
+ LttField, 0));
}
/*****************************************************************************
* ltt_event_field_element_select
* : Set the currently selected element for a sequence or
* array field
+ * O(1) because of offset array.
*Input params
* e : an instance of an event type
* f : a field of the instance
- * i : the ith element
+ * i : the ith element (0, ...)
+ *returns : the child field, at the right index, updated.
****************************************************************************/
-
-void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i)
+LttField *ltt_event_field_element_select(LttEvent *e, LttField *f, gulong i)
{
- unsigned element_number;
- LttField *fld;
+ gulong element_number;
+ LttField *field;
unsigned int k;
- int size;
- void *evD;
+ size_t size;
+ LttEventType *event_type;
+ off_t new_offset;
- if(f->field_type->type_class != LTT_ARRAY &&
- f->field_type->type_class != LTT_SEQUENCE)
+ if(f->field_type.type_class != LTT_ARRAY &&
+ f->field_type.type_class != LTT_SEQUENCE)
return ;
element_number = ltt_event_field_element_number(e,f);
- /* Sanity check for i : 1..n only, and must be lower or equal element_number
+ event_type = ltt_event_eventtype(e);
+ /* Sanity check for i : 0..n-1 only, and must be lower or equal element_number
*/
- if(element_number < i || i == 0) return;
-
- fld = f->child[0];
-
- evD = e->data + f->offset_root;
- size = 0;
- for(k=0;k<i;k++){
- size += ltt_event_refresh_fields(f->offset_root+size,size, fld, evD+size,
- e->tracefile->trace->reverse_byte_order);
+ if(i >= element_number) return;
+
+ if(f->field_type.type_class == LTT_ARRAY) {
+ field = &g_array_index(f->field_type.fields, LttField, 0);
+ } else {
+ field = &g_array_index(f->field_type.fields, LttField, 1);
+ }
+
+ if(field->field_size != 0) {
+ if(f->array_offset + (i * field->field_size) == field->offset_root)
+ return; /* fixed length child, already at the right offset */
+ else
+ new_offset = f->array_offset + (i * field->field_size);
+ } else {
+ /* Var. len. child */
+ new_offset = g_array_index(f->dynamic_offsets, off_t, i);
}
- f->current_element = i - 1;
+ compute_fields_offsets(e->tracefile, field, &new_offset, e->data);
+
+ return field;
}
/*****************************************************************************
* These functions extract data from an event after architecture specific
* conversions
****************************************************************************/
-
guint32 ltt_event_get_unsigned(LttEvent *e, LttField *f)
{
- //int revFlag = e->tracefile->trace->my_arch_endian ==
- // e->tracefile->trace->system_description->endian ? 0:1;
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
-
- LttTypeEnum t = f->field_type->type_class;
+ gboolean reverse_byte_order = LTT_GET_BO(e->tracefile);
- g_assert(t == LTT_UINT || t == LTT_ENUM);
+ LttTypeEnum t = f->field_type.type_class;
if(f->field_size == 1){
guint8 x = *(guint8 *)(e->data + f->offset_root);
gint32 ltt_event_get_int(LttEvent *e, LttField *f)
{
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
- //int revFlag = e->tracefile->trace->my_arch_endian ==
- // e->tracefile->trace->system_description->endian ? 0:1;
-
- g_assert(f->field_type->type_class == LTT_INT);
+ gboolean reverse_byte_order = LTT_GET_BO(e->tracefile);
if(f->field_size == 1){
gint8 x = *(gint8 *)(e->data + f->offset_root);
guint64 ltt_event_get_long_unsigned(LttEvent *e, LttField *f)
{
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
- //int revFlag = e->tracefile->trace->my_arch_endian ==
- // e->tracefile->trace->system_description->endian ? 0:1;
- LttTypeEnum t = f->field_type->type_class;
+ gboolean reverse_byte_order = LTT_GET_BO(e->tracefile);
- g_assert(t == LTT_UINT || t == LTT_ENUM);
+ LttTypeEnum t = f->field_type.type_class;
if(f->field_size == 1){
guint8 x = *(guint8 *)(e->data + f->offset_root);
{
//int revFlag = e->tracefile->trace->my_arch_endian ==
// e->tracefile->trace->system_description->endian ? 0:1;
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
-
- g_assert( f->field_type->type_class == LTT_INT);
+ gboolean reverse_byte_order = LTT_GET_BO(e->tracefile);
if(f->field_size == 1){
gint8 x = *(gint8 *)(e->data + f->offset_root);
float ltt_event_get_float(LttEvent *e, LttField *f)
{
- //int revFlag = e->tracefile->trace->my_arch_endian ==
- // e->tracefile->trace->system_description->endian ? 0:1;
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
+ g_assert(LTT_HAS_FLOAT(e->tracefile));
+ gboolean reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile);
- g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 4);
+ g_assert(f->field_type.type_class == LTT_FLOAT && f->field_size == 4);
if(reverse_byte_order == 0) return *(float *)(e->data + f->offset_root);
else{
- guint32 aInt;
- memcpy((void*)&aInt, e->data + f->offset_root, 4);
- aInt = ___swab32(aInt);
- return ((float)aInt);
+ void *ptr = e->data + f->offset_root;
+ guint32 value = bswap_32(*(guint32*)ptr);
+ return *(float*)&value;
}
}
double ltt_event_get_double(LttEvent *e, LttField *f)
{
- gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
- //int revFlag = e->tracefile->trace->my_arch_endian ==
- // e->tracefile->trace->system_description->endian ? 0:1;
+ g_assert(LTT_HAS_FLOAT(e->tracefile));
+ gboolean reverse_byte_order = LTT_GET_FLOAT_BO(e->tracefile);
- g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 8);
+ if(f->field_size == 4)
+ return ltt_event_get_float(e, f);
+
+ g_assert(f->field_type.type_class == LTT_FLOAT && f->field_size == 8);
if(reverse_byte_order == 0) return *(double *)(e->data + f->offset_root);
- else{
- guint64 aInt;
- memcpy((void*)&aInt, e->data + f->offset_root, 8);
- aInt = ___swab64(aInt);
- return ((double)aInt);
+ else {
+ void *ptr = e->data + f->offset_root;
+ guint64 value = bswap_64(*(guint64*)ptr);
+ return *(double*)&value;
}
}
* The string obtained is only valid until the next read from
* the same tracefile.
****************************************************************************/
-
char *ltt_event_get_string(LttEvent *e, LttField *f)
{
- g_assert(f->field_type->type_class == LTT_STRING);
+ g_assert(f->field_type.type_class == LTT_STRING);
return (gchar*)g_strdup((gchar*)(e->data + f->offset_root));
}
+
+
+/*****************************************************************************
+ *Function name
+ * get_field_type_size : set the fixed and dynamic sizes of the field type
+ * from the data read.
+ *Input params
+ * tf : tracefile
+ * event_type : event type
+ * offset_root : offset from the root
+ * offset_parent : offset from the parent
+ * field : field
+ * data : a pointer to the event data.
+ *Returns the field type size.
+ ****************************************************************************/
+ // TODO
+// Change this function so it uses a *to offset value incrementation, just like
+// genevent-new instead of returning a size. What is of interest here is the
+// offset needed to read each field.
+//
+// Precomputed ones can be returned directly. Otherwise, the field is flagged
+// "VARIABLE OFFSET" and must be computed dynamically. The dynamic processing
+// of an offset takes the last known fixed offset, and then dynamically
+// calculates all variable field offsets from it.
+//
+// After a VARIABLE SIZE element, all fields have a variable offset.
+// Also, is an array or a sequence has variable length child, we must pass
+// through all of them, saving the offsets in the dynamic_offsets array.
+
+#if 0
+size_t get_field_type_size(LttTracefile *tf, LttEventType *event_type,
+ off_t offset_root, off_t offset_parent,
+ LttField *field, void *data)
+{
+ size_t size = 0;
+ guint i;
+ LttType *type;
+ off_t align;
+
+ g_assert(field->fixed_root != FIELD_UNKNOWN);
+ g_assert(field->fixed_parent != FIELD_UNKNOWN);
+ g_assert(field->fixed_size != FIELD_UNKNOWN);
+
+ field->offset_root = offset_root;
+ field->offset_parent = offset_parent;
+
+ type = field->field_type;
+
+ switch(type->type_class) {
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ case LTT_POINTER:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ g_assert(field->fixed_size == FIELD_FIXED);
+ size = field->field_size;
+ align = ltt_align(field->offset_root,
+ size, event_type->facility->has_alignment);
+ field->offset_root += align;
+ field->offset_parent += align;
+ size += align;
+ break;
+ case LTT_SEQUENCE:
+ {
+ /* FIXME : check the type of sequence identifier */
+ gint seqnum = ltt_get_uint(LTT_GET_BO(tf),
+ field->sequ_number_size,
+ data + offset_root);
+
+ if(field->child[0]->fixed_size == FIELD_FIXED) {
+ size = field->sequ_number_size +
+ (seqnum * get_field_type_size(tf, event_type,
+ offset_root, offset_parent,
+ field->child[0], data));
+ } else {
+ size += field->sequ_number_size;
+ for(i=0;i<seqnum;i++) {
+ size_t child_size;
+ child_size = get_field_type_size(tf, event_type,
+ offset_root, offset_parent,
+ field->child[0], data);
+ offset_root += child_size;
+ offset_parent += child_size;
+ size += child_size;
+ }
+ }
+ field->field_size = size;
+ }
+ break;
+ case LTT_STRING:
+ size = strlen((char*)(data+offset_root)) + 1;// length + \0
+ field->field_size = size;
+ break;
+ case LTT_ARRAY:
+ if(field->fixed_size == FIELD_FIXED)
+ size = field->field_size;
+ else {
+ for(i=0;i<field->field_type->element_number;i++) {
+ size_t child_size;
+ child_size = get_field_type_size(tf, event_type,
+ offset_root, offset_parent,
+ field->child[0], data);
+ offset_root += child_size;
+ offset_parent += child_size;
+ size += child_size;
+ }
+ field->field_size = size;
+ }
+ break;
+ case LTT_STRUCT:
+ if(field->fixed_size == FIELD_FIXED)
+ size = field->field_size;
+ else {
+ size_t current_root_offset = offset_root;
+ size_t current_offset = 0;
+ size_t child_size = 0;
+ for(i=0;i<type->element_number;i++) {
+ child_size = get_field_type_size(tf,
+ event_type, current_root_offset, current_offset,
+ field->child[i], data);
+ current_offset += child_size;
+ current_root_offset += child_size;
+
+ }
+ size = current_offset;
+ field->field_size = size;
+ }
+ break;
+ case LTT_UNION:
+ if(field->fixed_size == FIELD_FIXED)
+ size = field->field_size;
+ else {
+ size_t current_root_offset = field->offset_root;
+ size_t current_offset = 0;
+ for(i=0;i<type->element_number;i++) {
+ size = get_field_type_size(tf, event_type,
+ current_root_offset, current_offset,
+ field->child[i], data);
+ size = max(size, field->child[i]->field_size);
+ }
+ field->field_size = size;
+ }
+ break;
+ }
+
+ return size;
+}
+#endif //0
+
+
+
+
+
+/*****************************************************************************
+ *Function name
+ * compute_fields_offsets : set the precomputable offset of the fields
+ *Input params
+ * tf : tracefile
+ * field : the field
+ * offset : pointer to the current offset, must be incremented
+ ****************************************************************************/
+
+
+void compute_fields_offsets(LttTracefile *tf, LttField *field, off_t *offset,
+ void *root)
+{
+ LttType *type = &field->field_type;
+
+ switch(type->type_class) {
+ case LTT_INT_FIXED:
+ case LTT_UINT_FIXED:
+ case LTT_POINTER:
+ case LTT_CHAR:
+ case LTT_UCHAR:
+ case LTT_SHORT:
+ case LTT_USHORT:
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ if(field->fixed_root == FIELD_VARIABLE) {
+ /* Align offset on type size */
+ *offset += ltt_align(*offset, get_alignment(tf, field),
+ tf->has_alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ /* Increment offset */
+ *offset += field->field_size;
+ }
+ /* None of these types has variable size, so we are sure that if
+ * this element has a fixed_root, then the following one will have
+ * a fixed root too, so it does not need the *offset at all.
+ */
+ break;
+ case LTT_STRING:
+ if(field->fixed_root == FIELD_VARIABLE) {
+ field->offset_root = *offset;
+ }
+ *offset += strlen((gchar*)(root+*offset)) + 1;
+ break;
+ case LTT_ARRAY:
+ g_assert(type->fields->len == 1);
+ {
+ off_t local_offset;
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(tf, field),
+ tf->has_alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ field->array_offset = *offset;
+ }
+
+ if(field->field_size != 0) {
+ /* Increment offset */
+ /* field_size is the array size in bytes */
+ *offset = field->offset_root + field->field_size;
+ } else {
+ guint i;
+ *offset = field->array_offset;
+ field->dynamic_offsets = g_array_set_size(field->dynamic_offsets,
+ 0);
+ for(i=0; i<type->size; i++) {
+ g_array_append_val(field->dynamic_offsets, *offset);
+ compute_fields_offsets(tf, child, offset, root);
+ }
+ }
+ // local_offset = field->array_offset;
+ // /* Set the offset at position 0 */
+ // compute_fields_offsets(tf, child, &local_offset, root);
+ }
+ break;
+ case LTT_SEQUENCE:
+ g_assert(type->fields->len == 2);
+ {
+ off_t local_offset;
+ LttField *child;
+ guint i;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(tf, field),
+ tf->has_alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+
+ child = &g_array_index(type->fields, LttField, 0);
+ compute_fields_offsets(tf, child, offset, root);
+ child = &g_array_index(type->fields, LttField, 1);
+ *offset += ltt_align(*offset, get_alignment(tf, child),
+ tf->has_alignment);
+ field->array_offset = *offset;
+
+ } else {
+ child = &g_array_index(type->fields, LttField, 1);
+ }
+ *offset = field->array_offset;
+ field->dynamic_offsets = g_array_set_size(field->dynamic_offsets,
+ 0);
+ for(i=0; i<ltt_event_field_element_number(&tf->event, field); i++) {
+ g_array_append_val(field->dynamic_offsets, *offset);
+ compute_fields_offsets(tf, child, offset, root);
+ }
+ // local_offset = field->array_offset;
+ // /* Set the offset at position 0 */
+ // compute_fields_offsets(tf, child, &local_offset, root);
+ }
+ break;
+ case LTT_STRUCT:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(tf, field),
+ tf->has_alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ } else {
+ *offset = field->offset_root;
+ }
+ for(i=0; i<type->fields->len; i++) {
+ child = &g_array_index(type->fields, LttField, i);
+ compute_fields_offsets(tf, child, offset, root);
+ }
+ }
+ break;
+ case LTT_UNION:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+ if(field->fixed_root == FIELD_VARIABLE) {
+ *offset += ltt_align(*offset, get_alignment(tf, field),
+ tf->has_alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ }
+ for(i=0; i<type->fields->len; i++) {
+ *offset = field->offset_root;
+ child = &g_array_index(type->fields, LttField, i);
+ compute_fields_offsets(tf, child, offset, root);
+ }
+ *offset = field->offset_root + field->field_size;
+ }
+ break;
+ case LTT_NONE:
+ default:
+ g_error("compute_fields_offsets : unknown type");
+ }
+
+}
+
+
+/*****************************************************************************
+ *Function name
+ * compute_offsets : set the dynamically computable offsets of an event type
+ *Input params
+ * tf : tracefile
+ * event : event type
+ *
+ ****************************************************************************/
+void compute_offsets(LttTracefile *tf, LttEventType *event, off_t *offset,
+ void *root)
+{
+ guint i;
+ gint ret;
+
+ /* compute all variable offsets */
+ for(i=0; i<event->fields->len; i++) {
+ LttField *field = &g_array_index(event->fields, LttField, i);
+ compute_fields_offsets(tf, field, offset, root);
+ if(ret) break;
+ }
+
+}
+