X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftracefile.c;h=e7e213dc9d843b2dfd28d7f2ce9c57d30ee4d7a9;hb=f5d7967f8c41e4f380d3ea7c4304e68ab5bad8ec;hp=fc02bfed119c167c573978b421b6ffceb68db0dd;hpb=d2ace3a93efa61ccde967a32626090c77e20b583;p=lttv.git diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index fc02bfed..e7e213dc 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -78,28 +78,36 @@ GQuark LTT_TRACEFILE_NAME_FACILITIES; /* set the offset of the fields belonging to the event, need the information of the archecture */ -void set_fields_offsets(LttTracefile *tf, LttEventType *event_type); +//void set_fields_offsets(LttTracefile *tf, LttEventType *event_type); //size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data); /* get the size of the field type according to * The facility size information. */ +#if 0 static inline void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, off_t offset_root, off_t offset_parent, enum field_status *fixed_root, enum field_status *fixed_parent, LttField *field); +#endif //0 /* map a fixed size or a block information from the file (fd) */ static gint map_block(LttTracefile * tf, guint block_num); /* calculate nsec per cycles for current block */ -static double calc_nsecs_per_cycle(LttTracefile * t); +#if 0 +static guint32 calc_nsecs_per_cycle(LttTracefile * t); +static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles); +#endif //0 /* go to the next event */ static int ltt_seek_next_event(LttTracefile *tf); void ltt_update_event_size(LttTracefile *tf); + +void precompute_offsets(LttFacility *fac, LttEventType *event); + #if 0 /* Functions to parse system.xml file (using glib xml parser) */ static void parser_start_element (GMarkupParseContext __UNUSED__ *context, @@ -176,6 +184,8 @@ static void parser_characters (GMarkupParseContext __UNUSED__ *context, des->description = g_strdup(text); } #endif //0 + + LttFacility *ltt_trace_get_facility_by_num(LttTrace *t, guint num) { @@ -210,6 +220,7 @@ int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) /* Get float byte order : might be different from int byte order * (or is set to 0 if the trace has no float (kernel trace)) */ tf->float_word_order = any->float_word_order; + tf->has_alignment = any->has_alignment; if(t) { t->arch_type = ltt_get_uint32(LTT_GET_BO(tf), @@ -221,7 +232,6 @@ int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) t->ltt_minor_version = any->minor_version; t->flight_recorder = any->flight_recorder; t->has_heartbeat = any->has_heartbeat; - t->has_alignment = any->has_alignment; t->has_tsc = any->has_tsc; } @@ -235,10 +245,38 @@ int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) tf->buffer_header_size = sizeof(struct ltt_block_start_header) + sizeof(struct ltt_trace_header_0_3); + g_warning("Unsupported trace version : %hhu.%hhu", + any->major_version, any->minor_version); + return 1; + } + break; + case 6: + { + struct ltt_trace_header_0_6 *vheader = + (struct ltt_trace_header_0_6 *)header; + tf->buffer_header_size = + sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_0_6); + if(t) { + t->start_freq = ltt_get_uint64(LTT_GET_BO(tf), + &vheader->start_freq); + t->start_tsc = ltt_get_uint64(LTT_GET_BO(tf), + &vheader->start_tsc); + t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf), + &vheader->start_monotonic); + t->start_time.tv_sec = ltt_get_uint64(LTT_GET_BO(tf), + &vheader->start_time_sec); + t->start_time.tv_nsec = ltt_get_uint64(LTT_GET_BO(tf), + &vheader->start_time_usec); + t->start_time.tv_nsec *= 1000; /* microsec to nanosec */ + + t->start_time_from_tsc = ltt_time_from_uint64( + (double)t->start_tsc * 1000000.0 / (double)t->start_freq); + } } break; default: - g_warning("Unsupported trace version : %hhu.%hhu", + g_warning("Unsupported trace version : %hhu.%hhu", any->major_version, any->minor_version); return 1; } @@ -804,7 +842,7 @@ static int open_tracefiles(LttTrace *trace, gchar *root_path, /* ltt_get_facility_description * - * Opens the trace corresponding to the requested facility (identified by fac_id + * Opens the file corresponding to the requested facility (identified by fac_id * and checksum). * * The name searched is : %trace root%/eventdefs/facname_checksum.xml @@ -820,6 +858,8 @@ static int ltt_get_facility_description(LttFacility *f, const gchar *text; guint textlen; gint err; + gint arch_spec; + gint fac_name_len; text = g_quark_to_string(t->pathname); textlen = strlen(text); @@ -833,10 +873,22 @@ static int ltt_get_facility_description(LttFacility *f, strcat(desc_file_name, text); text = g_quark_to_string(f->name); - textlen+=strlen(text); + fac_name_len = strlen(text); + textlen+=fac_name_len; if(textlen >= PATH_MAX) goto name_error; strcat(desc_file_name, text); + /* arch specific facilities are named like this : name_arch */ + if(fac_name_len+1 < sizeof("_arch")) + arch_spec = 0; + else { + if(!strcmp(&text[fac_name_len+1-sizeof("_arch")], "_arch")) + arch_spec = 1; + else + arch_spec = 0; + } + +#if 0 text = "_"; textlen+=strlen(text); if(textlen >= PATH_MAX) goto name_error; @@ -848,11 +900,45 @@ static int ltt_get_facility_description(LttFacility *f, textlen=strlen(desc_file_name); +#endif //0 + + if(arch_spec) { + switch(t->arch_type) { + case LTT_ARCH_TYPE_I386: + text = "_i386"; + break; + case LTT_ARCH_TYPE_PPC: + text = "_ppc"; + break; + case LTT_ARCH_TYPE_SH: + text = "_sh"; + break; + case LTT_ARCH_TYPE_S390: + text = "_s390"; + break; + case LTT_ARCH_TYPE_MIPS: + text = "_mips"; + break; + case LTT_ARCH_TYPE_ARM: + text = "_arm"; + case LTT_ARCH_TYPE_PPC64: + text = "_ppc64"; + case LTT_ARCH_TYPE_X86_64: + text = "_x86_64"; + break; + default: + g_error("Trace from unsupported architecture."); + } + textlen+=strlen(text); + if(textlen >= PATH_MAX) goto name_error; + strcat(desc_file_name, text); + } + text = ".xml"; textlen+=strlen(text); if(textlen >= PATH_MAX) goto name_error; strcat(desc_file_name, text); - + err = ltt_facility_open(f, t, desc_file_name); if(err) goto facility_error; @@ -912,6 +998,7 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) struct LttFacilityLoad *fac_load_data; struct LttStateDumpFacilityLoad *fac_state_dump_load_data; char *fac_name; + void *pos; // FIXME align switch((enum ltt_core_events)tf->event.event_id) { @@ -919,24 +1006,28 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) fac_name = (char*)(tf->event.data); g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s", fac_name); - fac_load_data = - (struct LttFacilityLoad *) - (tf->event.data + strlen(fac_name) + 1); + pos = (tf->event.data + strlen(fac_name) + 1); + pos += ltt_align((size_t)pos, sizeof(guint32), tf->has_alignment); + fac_load_data = (struct LttFacilityLoad *)pos; + fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id)); - g_assert(fac->exists == 0); + /* facility may already exist if trace is paused/unpaused */ + if(fac->exists) continue; fac->name = g_quark_from_string(fac_name); fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->checksum); fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id); fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->pointer_size); + fac->int_size = ltt_get_uint32(LTT_GET_BO(tf), + &fac_load_data->int_size); fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->long_size); fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->size_t_size); fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), - &fac_load_data->alignment); + &fac_load_data->has_alignment); if(ltt_get_facility_description(fac, tf->trace, tf)) continue; /* error opening description */ @@ -946,7 +1037,7 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) /* Preset the field offsets */ for(i=0; ievents->len; i++){ et = &g_array_index(fac->events, LttEventType, i); - set_fields_offsets(tf, et); + precompute_offsets(fac, et); } fac->exists = 1; @@ -971,24 +1062,29 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) fac_name = (char*)(tf->event.data); g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s", fac_name); - fac_state_dump_load_data = - (struct LttStateDumpFacilityLoad *) - (tf->event.data + strlen(fac_name) + 1); + pos = (tf->event.data + strlen(fac_name) + 1); + pos += ltt_align((size_t)pos, sizeof(guint32), tf->has_alignment); + fac_state_dump_load_data = (struct LttStateDumpFacilityLoad *)pos; + fac = &g_array_index (tf->trace->facilities_by_num, LttFacility, ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->id)); - g_assert(fac->exists == 0); + /* facility may already exist if trace is paused/unpaused */ + if(fac->exists) continue; fac->name = g_quark_from_string(fac_name); fac->checksum = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->checksum); - fac->id = fac_state_dump_load_data->id; + fac->id = ltt_get_uint32(LTT_GET_BO(tf), + &fac_state_dump_load_data->id); fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->pointer_size); + fac->int_size = ltt_get_uint32(LTT_GET_BO(tf), + &fac_state_dump_load_data->int_size); fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->long_size); fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->size_t_size); fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), - &fac_state_dump_load_data->alignment); + &fac_state_dump_load_data->has_alignment); if(ltt_get_facility_description(fac, tf->trace, tf)) continue; /* error opening description */ @@ -997,7 +1093,7 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) /* Preset the field offsets */ for(i=0; ievents->len; i++){ et = &g_array_index(fac->events, LttEventType, i); - set_fields_offsets(tf, et); + precompute_offsets(fac, et); } fac->exists = 1; @@ -1431,7 +1527,7 @@ int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) if(ret == ERANGE) goto range; /* ERANGE or EPERM */ else if(ret) goto fail; - if(ltt_time_compare(time, tf->event.event_time) < 0) + if(ltt_time_compare(time, tf->event.event_time) <= 0) goto found; } @@ -1448,7 +1544,7 @@ int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) if(ret == ERANGE) goto range; /* ERANGE or EPERM */ else if(ret) goto fail; - if(ltt_time_compare(time, tf->event.event_time) < 0) + if(ltt_time_compare(time, tf->event.event_time) <= 0) break; } goto found; @@ -1504,10 +1600,13 @@ LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event) g_assert(tf->trace->has_tsc); +// time = ltt_time_from_uint64( +// cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count))); time = ltt_time_from_uint64( - (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count) * - tf->buffer.nsecs_per_cycle); - time = ltt_time_add(tf->buffer.begin.timestamp, time); + (double)(tf->buffer.tsc - tf->trace->start_tsc) * 1000000.0 + / (double)tf->trace->start_freq); + //time = ltt_time_add(tf->buffer.begin.timestamp, time); + time = ltt_time_add(tf->trace->start_time_from_tsc, time); return time; } @@ -1617,7 +1716,8 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) /* Read event header */ - //TODO align + /* Align the head */ + pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); if(tf->trace->has_tsc) { if(tf->trace->has_heartbeat) { @@ -1665,6 +1765,9 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) event->event_size = ltt_get_uint16(LTT_GET_BO(tf), pos); pos += sizeof(guint16); + /* Align the head */ + pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment); + event->data = pos; /* get the data size and update the event fields with the current @@ -1722,25 +1825,53 @@ static gint map_block(LttTracefile * tf, guint block_num) header = (struct ltt_block_start_header*)tf->buffer.head; - tf->buffer.begin.timestamp = ltt_get_time(LTT_GET_BO(tf), - &header->begin.timestamp); - tf->buffer.begin.timestamp.tv_nsec *= NSEC_PER_USEC; +#if 0 + tf->buffer.begin.timestamp = ltt_time_add( + ltt_time_from_uint64( + ltt_get_uint64(LTT_GET_BO(tf), + &header->begin.timestamp) + - tf->trace->start_monotonic), + tf->trace->start_time); +#endif //0 //g_debug("block %u begin : %lu.%lu", block_num, // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec); tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), &header->begin.cycle_count); - tf->buffer.end.timestamp = ltt_get_time(LTT_GET_BO(tf), - &header->end.timestamp); - tf->buffer.end.timestamp.tv_nsec *= NSEC_PER_USEC; + tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf), + &header->begin.freq); + tf->buffer.begin.timestamp = ltt_time_add( + ltt_time_from_uint64( + (double)(tf->buffer.begin.cycle_count + - tf->trace->start_tsc) * 1000000.0 + / (double)tf->trace->start_freq), + tf->trace->start_time_from_tsc); +#if 0 + + tf->buffer.end.timestamp = ltt_time_add( + ltt_time_from_uint64( + ltt_get_uint64(LTT_GET_BO(tf), + &header->end.timestamp) + - tf->trace->start_monotonic), + tf->trace->start_time); +#endif //0 //g_debug("block %u end : %lu.%lu", block_num, // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec); tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf), &header->end.cycle_count); + tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf), + &header->end.freq); tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf), - &header->lost_size); - + &header->lost_size); + tf->buffer.end.timestamp = ltt_time_add( + ltt_time_from_uint64( + (double)(tf->buffer.end.cycle_count + - tf->trace->start_tsc) * 1000000.0 + / (double)tf->trace->start_freq), + tf->trace->start_time_from_tsc); + tf->buffer.tsc = tf->buffer.begin.cycle_count; tf->event.tsc = tf->buffer.tsc; + tf->buffer.freq = tf->buffer.begin.freq; /* FIXME * eventually support variable buffer size : will need a partial pre-read of @@ -1751,7 +1882,8 @@ static gint map_block(LttTracefile * tf, guint block_num) /* Now that the buffer is mapped, calculate the time interpolation for the * block. */ - tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf); +// tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf); + //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf); /* Make the current event point to the beginning of the buffer : * it means that the event read must get the first event. */ @@ -1769,7 +1901,7 @@ map_error: /* It will update the fields offsets too */ void ltt_update_event_size(LttTracefile *tf) { - ssize_t size = 0; + off_t size = 0; /* Specific handling of core events : necessary to read the facility control * tracefile. */ @@ -1781,6 +1913,7 @@ void ltt_update_event_size(LttTracefile *tf) case LTT_EVENT_FACILITY_LOAD: size = strlen((char*)tf->event.data) + 1; //g_debug("Update Event facility load of facility %s", (char*)tf->event.data); + size += ltt_align(size, sizeof(guint32), tf->has_alignment); size += sizeof(struct LttFacilityLoad); break; case LTT_EVENT_FACILITY_UNLOAD: @@ -1789,6 +1922,7 @@ void ltt_update_event_size(LttTracefile *tf) break; case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: size = strlen((char*)tf->event.data) + 1; + size += ltt_align(size, sizeof(guint32), tf->has_alignment); //g_debug("Update Event facility load state dump of facility %s", // (char*)tf->event.data); size += sizeof(struct LttStateDumpFacilityLoad); @@ -1824,12 +1958,9 @@ void ltt_update_event_size(LttTracefile *tf) g_quark_to_string(tf->name)); goto event_type_error; } - - if(event_type->root_field) - size = get_field_type_size(tf, event_type, - 0, 0, event_type->root_field, tf->event.data); - else - size = 0; + + /* Compute the dynamic offsets */ + compute_offsets(tf, f, event_type, &size, tf->event.data); //g_debug("Event root field : f.e %hhu.%hhu size %zd", // tf->event.facility_id, @@ -1900,34 +2031,33 @@ error: return ENOPROTOOPT; } - +#if 0 /***************************************************************************** *Function name * calc_nsecs_per_cycle : calculate nsecs per cycle for current block + * + * 1.0 / (freq(khz) *1000) * 1000000000 *Input Params * t : tracefile ****************************************************************************/ - -static double calc_nsecs_per_cycle(LttTracefile * tf) +/* from timer_tsc.c */ +#define CYC2NS_SCALE_FACTOR 10 +static guint32 calc_nsecs_per_cycle(LttTracefile * tf) { - LttTime lBufTotalTime; /* Total time for this buffer */ - double lBufTotalNSec; /* Total time for this buffer in nsecs */ - LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */ - - /* Calculate the total time for this buffer */ - lBufTotalTime = ltt_time_sub(tf->buffer.end.timestamp, - tf->buffer.begin.timestamp); - - /* Calculate the total cycles for this bufffer */ - lBufTotalCycle = tf->buffer.end.cycle_count; - lBufTotalCycle -= tf->buffer.begin.cycle_count; - - /* Convert the total time to double */ - lBufTotalNSec = ltt_time_to_double(lBufTotalTime); + //return 1e6 / (double)tf->buffer.freq; + guint32 cpu_mhz = tf->buffer.freq / 1000; + guint32 cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz; - return lBufTotalNSec / (double)lBufTotalCycle; + return cyc2ns_scale; + // return 1e6 / (double)tf->buffer.freq; +} +static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles) +{ + return (cycles * tf->buffer.cyc2ns_scale) >> CYC2NS_SCALE_FACTOR; } +#endif //0 + #if 0 void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD) { @@ -1939,7 +2069,7 @@ void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD) evT, 0,0,rootFld, evD); } #endif //0 - +#if 0 /***************************************************************************** *Function name * set_fields_offsets : set the precomputable offset of the fields @@ -1959,6 +2089,370 @@ void set_fields_offsets(LttTracefile *tf, LttEventType *event_type) field); } +#endif //0 + + +/***************************************************************************** + *Function name + * get_alignment : Get the alignment needed for a field. + *Input params + * field : field + * + * returns : The size on which it must be aligned. + * + ****************************************************************************/ +off_t get_alignment(LttField *field) +{ + 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: + /* Align offset on type size */ + return field->field_size; + break; + case LTT_STRING: + return 0; + break; + case LTT_ARRAY: + g_assert(type->fields->len == 1); + { + LttField *child = &g_array_index(type->fields, LttField, 0); + return get_alignment(child); + } + break; + case LTT_SEQUENCE: + g_assert(type->fields->len == 2); + { + off_t localign = 0; + LttField *child = &g_array_index(type->fields, LttField, 0); + + localign = max(localign, get_alignment(child)); + + child = &g_array_index(type->fields, LttField, 1); + localign = max(localign, get_alignment(child)); + + return localign; + } + break; + case LTT_STRUCT: + case LTT_UNION: + { + guint i; + off_t localign = 0; + + for(i=0; ifields->len; i++) { + LttField *child = &g_array_index(type->fields, LttField, i); + localign = max(localign, get_alignment(child)); + } + return localign; + } + break; + case LTT_NONE: + default: + g_error("get_alignment : unknown type"); + } + +} + +/***************************************************************************** + *Function name + * field_compute_static_size : Determine the size of fields known by their + * sole definition. Unions, arrays and struct sizes might be known, but + * the parser does not give that information. + *Input params + * tf : tracefile + * field : field + * + ****************************************************************************/ + +void field_compute_static_size(LttFacility *fac, LttField *field) +{ + 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: + case LTT_STRING: + /* nothing to do */ + break; + case LTT_ARRAY: + /* note this : array type size is the number of elements in the array, + * while array field size of the length of the array in bytes */ + g_assert(type->fields->len == 1); + { + LttField *child = &g_array_index(type->fields, LttField, 0); + field_compute_static_size(fac, child); + + if(child->field_size != 0) { + field->field_size = type->size * child->field_size; + field->dynamic_offsets = g_array_sized_new(FALSE, TRUE, + sizeof(off_t), type->size); + } else { + field->field_size = 0; + } + } + break; + case LTT_SEQUENCE: + g_assert(type->fields->len == 2); + { + off_t local_offset = 0; + LttField *child = &g_array_index(type->fields, LttField, 1); + field_compute_static_size(fac, child); + field->field_size = 0; + type->size = 0; + if(child->field_size != 0) { + field->dynamic_offsets = g_array_sized_new(FALSE, TRUE, + sizeof(off_t), SEQUENCE_AVG_ELEMENTS); + } + } + break; + case LTT_STRUCT: + case LTT_UNION: + { + guint i; + for(i=0;ifields->len;i++) { + LttField *child = &g_array_index(type->fields, LttField, i); + field_compute_static_size(fac, child); + if(child->field_size != 0) { + type->size += ltt_align(type->size, get_alignment(child), + fac->alignment); + type->size += child->field_size; + } else { + /* As soon as we find a child with variable size, we have + * a variable size */ + type->size = 0; + break; + } + } + field->field_size = type->size; + } + break; + default: + g_error("field_static_size : unknown type"); + } + +} + + + +/***************************************************************************** + *Function name + * precompute_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 + * + * return : 1 : found a variable length field, stop the processing. + * 0 otherwise. + ****************************************************************************/ + + +gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset) +{ + 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: + g_assert(field->field_size != 0); + /* Align offset on type size */ + *offset += ltt_align(*offset, get_alignment(field), + fac->alignment); + /* remember offset */ + field->offset_root = *offset; + field->fixed_root = FIELD_FIXED; + /* Increment offset */ + *offset += field->field_size; + return 0; + break; + case LTT_STRING: + field->offset_root = *offset; + field->fixed_root = FIELD_FIXED; + return 1; + break; + case LTT_ARRAY: + g_assert(type->fields->len == 1); + { + LttField *child = &g_array_index(type->fields, LttField, 0); + + *offset += ltt_align(*offset, get_alignment(field), + fac->alignment); + + /* remember offset */ + field->offset_root = *offset; + field->array_offset = *offset; + field->fixed_root = FIELD_FIXED; + + /* Let the child be variable */ + //precompute_fields_offsets(tf, child, offset); + + if(field->field_size != 0) { + /* Increment offset */ + /* field_size is the array size in bytes */ + *offset += field->field_size; + return 0; + } else { + return 1; + } + } + break; + case LTT_SEQUENCE: + g_assert(type->fields->len == 2); + { + LttField *child; + guint ret; + + *offset += ltt_align(*offset, get_alignment(field), + fac->alignment); + + /* remember offset */ + field->offset_root = *offset; + field->fixed_root = FIELD_FIXED; + + child = &g_array_index(type->fields, LttField, 0); + ret = precompute_fields_offsets(fac, child, offset); + g_assert(ret == 0); /* Seq len cannot have variable len */ + + child = &g_array_index(type->fields, LttField, 1); + *offset += ltt_align(*offset, get_alignment(child), + fac->alignment); + field->array_offset = *offset; + /* Let the child be variable. */ + //ret = precompute_fields_offsets(fac, child, offset); + + /* Cannot precompute fields offsets of sequence members, and has + * variable length. */ + return 1; + } + break; + case LTT_STRUCT: + { + LttField *child; + guint i; + gint ret=0; + + *offset += ltt_align(*offset, get_alignment(field), + fac->alignment); + /* remember offset */ + field->offset_root = *offset; + field->fixed_root = FIELD_FIXED; + + for(i=0; i< type->fields->len; i++) { + child = &g_array_index(type->fields, LttField, i); + ret = precompute_fields_offsets(fac, child, offset); + + if(ret) break; + } + return ret; + } + break; + case LTT_UNION: + { + LttField *child; + guint i; + gint ret=0; + + *offset += ltt_align(*offset, get_alignment(field), + fac->alignment); + /* remember offset */ + field->offset_root = *offset; + field->fixed_root = FIELD_FIXED; + + for(i=0; i< type->fields->len; i++) { + *offset = field->offset_root; + child = &g_array_index(type->fields, LttField, i); + ret = precompute_fields_offsets(fac, child, offset); + + if(ret) break; + } + *offset = field->offset_root + field->field_size; + return ret; + } + + break; + case LTT_NONE: + default: + g_error("precompute_fields_offsets : unknown type"); + return 1; + } + +} + + +/***************************************************************************** + *Function name + * precompute_offsets : set the precomputable offset of an event type + *Input params + * tf : tracefile + * event : event type + * + ****************************************************************************/ +void precompute_offsets(LttFacility *fac, LttEventType *event) +{ + guint i; + off_t offset = 0; + gint ret; + + /* First, compute the size of fixed size fields. Will determine size for + * arrays, struct and unions, which is not done by the parser */ + for(i=0; ifields->len; i++) { + LttField *field = &g_array_index(event->fields, LttField, i); + field_compute_static_size(fac, field); + } + + /* Precompute all known offsets */ + for(i=0; ifields->len; i++) { + LttField *field = &g_array_index(event->fields, LttField, i); + ret = precompute_fields_offsets(fac, field, &offset); + if(ret) break; + } +} + + /***************************************************************************** @@ -1973,6 +2467,15 @@ void set_fields_offsets(LttTracefile *tf, LttEventType *event_type) * fixed_parent : Do we know a fixed offset to the parent ? * field : field ****************************************************************************/ + + + +// preset the fixed size offsets. Calculate them just like genevent-new : an +// increment of a *to value that represents the offset from the start of the +// event data. +// The preset information is : offsets up to (and including) the first element +// of variable size. All subsequent fields must be flagged "VARIABLE OFFSET". +#if 0 void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, off_t offset_root, off_t offset_parent, enum field_status *fixed_root, enum field_status *fixed_parent, @@ -2106,6 +2609,8 @@ void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, max_size = max(max_size, field->child[i]->field_size); } if(final_child_status != FIELD_FIXED) { + g_error("LTTV does not support variable size fields in unions."); + /* This will stop the application. */ *fixed_root = final_child_status; *fixed_parent = final_child_status; field->field_size = 0; @@ -2118,7 +2623,7 @@ void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, } } - +#endif //0 /***************************************************************************** *Function name @@ -2132,6 +2637,112 @@ void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, *Returns : 0 if identical * 1 if not. ****************************************************************************/ +// this function checks for equality of field types. Therefore, it does not use +// per se offsets. For instance, an aligned version of a structure is +// compatible with an unaligned version of the same structure. +gint check_fields_compatibility(LttEventType *event_type1, + LttEventType *event_type2, + LttField *field1, LttField *field2) +{ + guint different = 0; + LttType *type1; + LttType *type2; + + if(field1 == NULL) { + if(field2 == NULL) goto end; + else { + different = 1; + goto end; + } + } else if(field2 == NULL) { + different = 1; + goto end; + } + + type1 = &field1->field_type; + type2 = &field2->field_type; + + if(type1->type_class != type2->type_class) { + different = 1; + goto end; + } + + switch(type1->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(field1->field_size != field2->field_size) + different = 1; + break; + case LTT_STRING: + break; + case LTT_ARRAY: + { + LttField *child1 = &g_array_index(type1->fields, LttField, 0); + LttField *child2 = &g_array_index(type2->fields, LttField, 0); + + if(type1->size != type2->size) + different = 1; + if(check_fields_compatibility(event_type1, event_type2, child1, child2)) + different = 1; + } + break; + case LTT_SEQUENCE: + { + LttField *child1 = &g_array_index(type1->fields, LttField, 1); + LttField *child2 = &g_array_index(type2->fields, LttField, 1); + + if(check_fields_compatibility(event_type1, event_type2, child1, child2)) + different = 1; + } + break; + case LTT_STRUCT: + case LTT_UNION: + { + LttField *child; + guint i; + + if(type1->fields->len != type2->fields->len) { + different = 1; + goto end; + } + + for(i=0; i< type1->fields->len; i++) { + LttField *child1; + LttField *child2; + child1 = &g_array_index(type1->fields, LttField, i); + child2 = &g_array_index(type2->fields, LttField, i); + different = check_fields_compatibility(event_type1, + event_type2, child1, child2); + + if(different) break; + } + } + break; + case LTT_NONE: + default: + g_error("precompute_fields_offsets : unknown type"); + } + +end: + return different; +} + + +#if 0 gint check_fields_compatibility(LttEventType *event_type1, LttEventType *event_type2, LttField *field1, LttField *field2) @@ -2244,176 +2855,9 @@ gint check_fields_compatibility(LttEventType *event_type1, end: return different; } - - - - -#if 0 -/***************************************************************************** - *Function name - * getFieldtypeSize: get the size of the field type (primitive type) - *Input params - * evT : event type - * offsetRoot : offset from the root - * offsetParent : offset from the parrent - * fld : field - * evD : event data, it may be NULL - *Return value - * int : size of the field - ****************************************************************************/ - -static inline gint getFieldtypeSize(LttTracefile *tf, - LttEventType * evT, gint offsetRoot, - gint offsetParent, LttField * fld, void *evD) -{ - gint size, size1, element_number, i, offset1, offset2; - LttType * type = fld->field_type; - - /* This likely has been tested with gcov : half of them.. */ - if(unlikely(fld->field_fixed == 1)){ - /* tested : none */ - if(unlikely(fld == evT->root_field)) { - size = fld->field_size; - goto end_getFieldtypeSize; - } - } - - /* From gcov profiling : half string, half struct, can we gain something - * from that ? (Mathieu) */ - switch(type->type_class) { - case LTT_ARRAY: - element_number = (int) type->element_number; - if(fld->field_fixed == -1){ - size = getFieldtypeSize(tf, evT, offsetRoot, - 0,fld->child[0], NULL); - if(size == 0){ //has string or sequence - fld->field_fixed = 0; - }else{ - fld->field_fixed = 1; - size *= element_number; - } - }else if(fld->field_fixed == 0){// has string or sequence - size = 0; - for(i=0;ichild[0], evD+size); - } - }else size = fld->field_size; - if(unlikely(!evD)){ - fld->fixed_root = (offsetRoot==-1) ? 0 : 1; - fld->fixed_parent = (offsetParent==-1) ? 0 : 1; - } - - break; - - case LTT_SEQUENCE: - size1 = (int) ltt_type_size(fac, type); - if(fld->field_fixed == -1){ - fld->sequ_number_size = size1; - fld->field_fixed = 0; - size = getFieldtypeSize(evT, offsetRoot, - 0,fld->child[0], NULL); - fld->element_size = size; - }else{//0: sequence - element_number = getIntNumber(tf,size1,evD); - type->element_number = element_number; - if(fld->element_size > 0){ - size = element_number * fld->element_size; - }else{//sequence has string or sequence - size = 0; - for(i=0;ichild[0], evD+size+size1); - } - } - size += size1; - } - if(unlikely(!evD)){ - fld->fixed_root = (offsetRoot==-1) ? 0 : 1; - fld->fixed_parent = (offsetParent==-1) ? 0 : 1; - } - - break; - - case LTT_STRING: - size = 0; - if(fld->field_fixed == -1){ - fld->field_fixed = 0; - }else{//0: string - /* Hope my implementation is faster than strlen (Mathieu) */ - char *ptr=(char*)evD; - size = 1; - /* from gcov : many many strings are empty, make it the common case.*/ - while(unlikely(*ptr != '\0')) { size++; ptr++; } - //size = ptr - (char*)evD + 1; //include end : '\0' - } - fld->fixed_root = (offsetRoot==-1) ? 0 : 1; - fld->fixed_parent = (offsetParent==-1) ? 0 : 1; - - break; - - case LTT_STRUCT: - element_number = (int) type->element_number; - size = 0; - /* tested with gcov */ - if(unlikely(fld->field_fixed == -1)){ - offset1 = offsetRoot; - offset2 = 0; - for(i=0;ichild[i], NULL); - if(likely(size1 > 0 && size >= 0)){ - size += size1; - if(likely(offset1 >= 0)) offset1 += size1; - offset2 += size1; - }else{ - size = -1; - offset1 = -1; - offset2 = -1; - } - } - if(unlikely(size == -1)){ - fld->field_fixed = 0; - size = 0; - }else fld->field_fixed = 1; - }else if(likely(fld->field_fixed == 0)){ - offset1 = offsetRoot; - offset2 = 0; - for(i=0;unlikely(ichild[i], evD+offset2); - offset1 += size; - offset2 += size; - } - size = offset2; - }else size = fld->field_size; - fld->fixed_root = (offsetRoot==-1) ? 0 : 1; - fld->fixed_parent = (offsetParent==-1) ? 0 : 1; - break; - - default: - if(unlikely(fld->field_fixed == -1)){ - size = (int) ltt_type_size(LTT_GET_BO(tf), type); - fld->field_fixed = 1; - }else size = fld->field_size; - if(unlikely(!evD)){ - fld->fixed_root = (offsetRoot==-1) ? 0 : 1; - fld->fixed_parent = (offsetParent==-1) ? 0 : 1; - } - break; - } - - fld->offset_root = offsetRoot; - fld->offset_parent = offsetParent; - fld->field_size = size; - -end_getFieldtypeSize: - - return size; -} #endif //0 + /***************************************************************************** *Function name * ltt_get_int : get an integer number @@ -2496,13 +2940,17 @@ char * ltt_trace_system_description_description (LttSystemDescription * s) } -/* get the start time of the trace */ - -LttTime ltt_trace_system_description_trace_start_time(LttSystemDescription *s) +/* get the NTP corrected start time of the trace */ +LttTime ltt_trace_start_time(LttTrace *t) { - return s->trace_start; + return t->start_time; } +/* get the monotonic start time of the trace */ +LttTime ltt_trace_start_time_monotonic(LttTrace *t) +{ + return t->start_time_from_tsc; +} LttTracefile *ltt_tracefile_new() {