-/*****************************************************************************
- *Function name
- * compute_fields_offsets : set the precomputable offset of the fields
- *Input params
- * fac : facility
- * field : the field
- * offset : pointer to the current offset, must be incremented
- ****************************************************************************/
-
-
-void compute_fields_offsets(LttTracefile *tf,
- LttFacility *fac, LttField *field, off_t *offset, void *root, guint is_compact)
-{
- LttType *type = &field->field_type;
-
- if(unlikely(is_compact)) {
- g_assert(field->field_size != 0);
- /* FIXME THIS IS A HUUUUUGE hack :
- * offset is between the compact_data field in struct LttEvent
- * and the address of the field root in the memory map.
- * ark. Both will stay at the same addresses while the event
- * is readable, so it's ok.
- */
- field->offset_root = (unsigned long)(&tf->event.compact_data)
- - (unsigned long)root;
- field->fixed_root = FIELD_FIXED;
- return;
- }
-
- 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(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);
- }
- 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(field),
- fac->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, fac, child, offset, root, is_compact);
- }
- }
- // local_offset = field->array_offset;
- // /* Set the offset at position 0 */
- // compute_fields_offsets(tf, fac, child, &local_offset, root);
- }
- break;
- case LTT_SEQUENCE:
- g_assert(type->fields->len == 2);
- {
- off_t local_offset;
- LttField *child;
- guint i;
- guint num_elem;
- if(field->fixed_root == FIELD_VARIABLE) {
- *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, fac, child, offset, root, is_compact);
- child = &g_array_index(type->fields, LttField, 1);
- *offset += ltt_align(*offset, get_alignment(child),
- fac->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);
- 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, fac, child, offset, root, is_compact);
- }
- 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, fac, 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(field),
- fac->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, fac, child, offset, root, is_compact);
- }
- }
- break;
- case LTT_UNION:
- {
- LttField *child;
- guint i;
- gint ret=0;
- if(field->fixed_root == FIELD_VARIABLE) {
- *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, fac, child, offset, root, is_compact);
- }
- *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, LttFacility *fac,
- LttEventType *event, off_t *offset, void *root)
-{
- guint i;
-
- /* 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);
- if(event->has_compact_data && i == 0)
- compute_fields_offsets(tf, fac, field, offset, root, 1);
- else
- compute_fields_offsets(tf, fac, field, offset, root, 0);
- }
-
-}