/* This file is part of the Linux Trace Toolkit viewer
* Copyright (C) 2003-2004 Xiangxiu Yang
+ * 2006 Mathieu Desnoyers
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation;
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License Version 2.1 as published by the Free Software Foundation.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
-void compute_fields_offsets(LttTracefile *tf, LttField *field, off_t *offset,
- void *root);
-
-
+void compute_fields_offsets(LttTracefile *tf,
+ LttFacility *fac, LttField *field, off_t *offset, void *root);
LttEvent *ltt_event_new()
if(f->field_type.type_class != LTT_ARRAY &&
f->field_type.type_class != LTT_SEQUENCE)
- return ;
+ return NULL;
element_number = ltt_event_field_element_number(e,f);
event_type = ltt_event_eventtype(e);
/* Sanity check for i : 0..n-1 only, and must be lower or equal element_number
*/
- if(i >= element_number) return;
+ if(i >= element_number) return NULL;
if(f->field_type.type_class == LTT_ARRAY) {
field = &g_array_index(f->field_type.fields, LttField, 0);
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 */
+ return field; /* 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);
}
- compute_fields_offsets(e->tracefile, field, &new_offset, e->data);
+ compute_fields_offsets(e->tracefile,
+ ltt_event_facility(e), field, &new_offset, e->data);
return field;
}
+
+off_t ltt_event_field_offset(LttEvent *e, LttField *f)
+{
+ return f->offset_root;
+}
+
+
+
/*****************************************************************************
* These functions extract data from an event after architecture specific
* conversions
g_assert(field->fixed_size == FIELD_FIXED);
size = field->field_size;
align = ltt_align(field->offset_root,
- size, event_type->facility->has_alignment);
+ size, event_type->facility->alignment);
field->offset_root += align;
field->offset_parent += align;
size += align;
*Function name
* compute_fields_offsets : set the precomputable offset of the fields
*Input params
- * tf : tracefile
+ * fac : facility
* 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)
+void compute_fields_offsets(LttTracefile *tf,
+ LttFacility *fac, LttField *field, off_t *offset, void *root)
{
LttType *type = &field->field_type;
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);
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
/* remember offset */
field->offset_root = *offset;
/* Increment offset */
*offset += field->field_size;
+ } else {
+ //g_debug("type before offset : %llu %llu %u\n", *offset,
+ // field->offset_root,
+ // field->field_size);
+ *offset = field->offset_root;
+ *offset += field->field_size;
+ //g_debug("type after offset : %llu\n", *offset);
}
- /* 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;
+ /* Realign the data */
+ *offset += ltt_align(*offset, fac->pointer_size,
+ fac->alignment);
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);
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
/* remember offset */
field->offset_root = *offset;
field->array_offset = *offset;
0);
for(i=0; i<type->size; i++) {
g_array_append_val(field->dynamic_offsets, *offset);
- compute_fields_offsets(tf, child, offset, root);
+ compute_fields_offsets(tf, fac, child, offset, root);
}
}
// local_offset = field->array_offset;
// /* Set the offset at position 0 */
- // compute_fields_offsets(tf, child, &local_offset, root);
+ // compute_fields_offsets(tf, fac, child, &local_offset, root);
}
break;
case LTT_SEQUENCE:
off_t local_offset;
LttField *child;
guint i;
+ guint num_elem;
if(field->fixed_root == FIELD_VARIABLE) {
- *offset += ltt_align(*offset, get_alignment(tf, field),
- tf->has_alignment);
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
/* remember offset */
field->offset_root = *offset;
child = &g_array_index(type->fields, LttField, 0);
- compute_fields_offsets(tf, child, offset, root);
+ compute_fields_offsets(tf, fac, child, offset, root);
child = &g_array_index(type->fields, LttField, 1);
- *offset += ltt_align(*offset, get_alignment(tf, child),
- tf->has_alignment);
+ *offset += ltt_align(*offset, get_alignment(child),
+ fac->alignment);
field->array_offset = *offset;
} else {
*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++) {
+ num_elem = ltt_event_field_element_number(&tf->event, field);
+ for(i=0; i<num_elem; i++) {
g_array_append_val(field->dynamic_offsets, *offset);
- compute_fields_offsets(tf, child, offset, root);
+ compute_fields_offsets(tf, fac, child, offset, root);
}
+ g_assert(num_elem == field->dynamic_offsets->len);
+
+ /* Realign the data */
+ *offset += ltt_align(*offset, fac->pointer_size,
+ fac->alignment);
+
// local_offset = field->array_offset;
// /* Set the offset at position 0 */
- // compute_fields_offsets(tf, child, &local_offset, root);
+ // compute_fields_offsets(tf, fac, child, &local_offset, root);
}
break;
case LTT_STRUCT:
guint i;
gint ret=0;
if(field->fixed_root == FIELD_VARIABLE) {
- *offset += ltt_align(*offset, get_alignment(tf, field),
- tf->has_alignment);
+ *offset += ltt_align(*offset, get_alignment(fac, field),
+ fac->alignment);
/* remember offset */
field->offset_root = *offset;
} else {
}
for(i=0; i<type->fields->len; i++) {
child = &g_array_index(type->fields, LttField, i);
- compute_fields_offsets(tf, child, offset, root);
+ compute_fields_offsets(tf, fac, child, offset, root);
}
}
break;
guint i;
gint ret=0;
if(field->fixed_root == FIELD_VARIABLE) {
- *offset += ltt_align(*offset, get_alignment(tf, field),
- tf->has_alignment);
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->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);
+ compute_fields_offsets(tf, fac, child, offset, root);
}
*offset = field->offset_root + field->field_size;
}
* event : event type
*
****************************************************************************/
-void compute_offsets(LttTracefile *tf, LttEventType *event, off_t *offset,
- void *root)
+void compute_offsets(LttTracefile *tf, LttFacility *fac,
+ LttEventType *event, off_t *offset, void *root)
{
guint i;
- gint ret;
/* compute all variable offsets */
for(i=0; i<event->fields->len; i++) {
+ //g_debug("computing offset %u of %u\n", i, event->fields->len-1);
LttField *field = &g_array_index(event->fields, LttField, i);
- compute_fields_offsets(tf, field, offset, root);
- if(ret) break;
+ compute_fields_offsets(tf, fac, field, offset, root);
}
}