X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftracefile.c;h=00e3444400e56ca1262e139f59ffe5394a8f6dcc;hb=01e5c8ac303294105046b1383fe923ae28bd4890;hp=5fbf53cb32fc2d1842b291787ef115d4068da5a8;hpb=743e50fd0105daeea4804d68989965399bf3a4d3;p=lttv.git diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 5fbf53cb..00e34444 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -3,19 +3,19 @@ * * Complete rewrite from the original version made by XangXiu Yang. * - * 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 @@ -232,7 +232,7 @@ 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_tsc = any->has_tsc; + t->freq_scale = any->freq_scale; } @@ -250,13 +250,13 @@ int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) return 1; } break; - case 6: + case 7: { - struct ltt_trace_header_0_6 *vheader = - (struct ltt_trace_header_0_6 *)header; + struct ltt_trace_header_0_7 *vheader = + (struct ltt_trace_header_0_7 *)header; tf->buffer_header_size = sizeof(struct ltt_block_start_header) - + sizeof(struct ltt_trace_header_0_6); + + sizeof(struct ltt_trace_header_0_7); if(t) { t->start_freq = ltt_get_uint64(LTT_GET_BO(tf), &vheader->start_freq); @@ -642,9 +642,12 @@ void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname) * The left side is the name, the right side is the number. */ -int get_tracefile_name_number(const gchar *raw_name, +int get_tracefile_name_number(gchar *raw_name, GQuark *name, - guint *num) + guint *num, + guint *tid, + guint *pgid, + guint64 *creation) { guint raw_name_len = strlen(raw_name); gchar char_name[PATH_MAX]; @@ -652,27 +655,84 @@ int get_tracefile_name_number(const gchar *raw_name, int underscore_pos; long int cpu_num; gchar *endptr; + gchar *tmpptr; for(i=raw_name_len-1;i>=0;i--) { if(raw_name[i] == '_') break; } - if(i==0) /* Either not found or name length is 0 */ - return -1; - underscore_pos = i; - - cpu_num = strtol(raw_name+underscore_pos+1, &endptr, 10); + if(i==-1) { /* Either not found or name length is 0 */ + /* This is a userspace tracefile */ + strncpy(char_name, raw_name, raw_name_len); + *name = g_quark_from_string(char_name); + *num = 0; /* unknown cpu */ + for(i=0;itracefiles, name); if(group == NULL) { @@ -858,6 +923,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); @@ -871,9 +938,21 @@ 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); @@ -887,6 +966,41 @@ 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"; + break; + case LTT_ARCH_TYPE_PPC64: + text = "_ppc64"; + break; + 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; @@ -1378,11 +1492,25 @@ GQuark ltt_tracefile_long_name(const LttTracefile *tf) -guint ltt_tracefile_num(LttTracefile *tf) +guint ltt_tracefile_cpu(LttTracefile *tf) { return tf->cpu_num; } +guint ltt_tracefile_tid(LttTracefile *tf) +{ + return tf->tid; +} + +guint ltt_tracefile_pgid(LttTracefile *tf) +{ + return tf->pgid; +} + +guint64 ltt_tracefile_creation(LttTracefile *tf) +{ + return tf->creation; +} /***************************************************************************** * Get the number of blocks in the tracefile ****************************************************************************/ @@ -1533,6 +1661,10 @@ int ltt_tracefile_seek_position(LttTracefile *tf, const LttEventPosition *ep) { tf->event.offset = ep->offset; + /* Put back the event real tsc */ + tf->event.tsc = ep->tsc; + tf->buffer.tsc = ep->tsc; + err = ltt_tracefile_read_update_event(tf); if(err) goto fail; err = ltt_tracefile_read_op(tf); @@ -1546,24 +1678,32 @@ fail: return 1; } -/* Calculate the real event time based on the buffer boundaries */ -LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event) +LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc) { LttTime time; - - 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( - (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); - + + if(tsc > tf->trace->start_tsc) { + time = ltt_time_from_uint64( + (double)(tsc - tf->trace->start_tsc) + * (1000000000.0 / tf->trace->freq_scale) + / (double)tf->trace->start_freq); + time = ltt_time_add(tf->trace->start_time_from_tsc, time); + } else { + time = ltt_time_from_uint64( + (double)(tf->trace->start_tsc - tsc) + * (1000000000.0 / tf->trace->freq_scale) + / (double)tf->trace->start_freq); + time = ltt_time_sub(tf->trace->start_time_from_tsc, time); + } return time; } +/* Calculate the real event time based on the buffer boundaries */ +LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event) +{ + return ltt_interpolate_time_from_tsc(tf, tf->buffer.tsc); +} + /* Get the current event of the tracefile : valid until the next read */ LttEvent *ltt_tracefile_get_event(LttTracefile *tf) @@ -1672,43 +1812,29 @@ int ltt_tracefile_read_update_event(LttTracefile *tf) /* 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) { - event->time.timestamp = ltt_get_uint32(LTT_GET_BO(tf), - pos); - /* 32 bits -> 64 bits tsc */ - /* note : still works for seek and non seek cases. */ - if(event->time.timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) { - tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL) - + 0x100000000ULL) - | (guint64)event->time.timestamp; - event->tsc = tf->buffer.tsc; - } else { - /* no overflow */ - tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL) - | (guint64)event->time.timestamp; - event->tsc = tf->buffer.tsc; - } - pos += sizeof(guint32); - } else { - event->tsc = ltt_get_uint64(LTT_GET_BO(tf), pos); - tf->buffer.tsc = event->tsc; - pos += sizeof(guint64); - } - - event->event_time = ltt_interpolate_time(tf, event); - } else { - event->time.delta.tv_sec = 0; - event->time.delta.tv_nsec = ltt_get_uint32(LTT_GET_BO(tf), - pos) * NSEC_PER_USEC; - tf->buffer.tsc = 0; - event->tsc = tf->buffer.tsc; - - event->event_time = ltt_time_add(tf->buffer.begin.timestamp, - event->time.delta); - pos += sizeof(guint32); - } - + if(tf->trace->has_heartbeat) { + event->timestamp = ltt_get_uint32(LTT_GET_BO(tf), + pos); + /* 32 bits -> 64 bits tsc */ + /* note : still works for seek and non seek cases. */ + if(event->timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) { + tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL) + + 0x100000000ULL) + | (guint64)event->timestamp; + event->tsc = tf->buffer.tsc; + } else { + /* no overflow */ + tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL) + | (guint64)event->timestamp; + event->tsc = tf->buffer.tsc; + } + pos += sizeof(guint32); + } else { + event->tsc = ltt_get_uint64(LTT_GET_BO(tf), pos); + tf->buffer.tsc = event->tsc; + pos += sizeof(guint64); + } + event->event_time = ltt_interpolate_time(tf, event); event->facility_id = *(guint8*)pos; pos += sizeof(guint8); @@ -1792,12 +1918,19 @@ static gint map_block(LttTracefile * tf, guint block_num) &header->begin.cycle_count); tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf), &header->begin.freq); - tf->buffer.begin.timestamp = ltt_time_add( + if(tf->buffer.begin.freq == 0) + tf->buffer.begin.freq = tf->trace->start_freq; + + tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf, + tf->buffer.begin.cycle_count); +#if 0 + 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); + tf->trace->start_time_from_tsc); +#endif //0 #if 0 tf->buffer.end.timestamp = ltt_time_add( @@ -1813,15 +1946,21 @@ static gint map_block(LttTracefile * tf, guint block_num) &header->end.cycle_count); tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf), &header->end.freq); + if(tf->buffer.end.freq == 0) + tf->buffer.end.freq = tf->trace->start_freq; + tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf), &header->lost_size); - tf->buffer.end.timestamp = ltt_time_add( + tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf, + tf->buffer.end.cycle_count); +#if 0 + 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); - +#endif //0 tf->buffer.tsc = tf->buffer.begin.cycle_count; tf->event.tsc = tf->buffer.tsc; tf->buffer.freq = tf->buffer.begin.freq; @@ -1894,7 +2033,7 @@ void ltt_update_event_size(LttTracefile *tf) } } else { if(!f->exists) { - g_error("Unknown facility %hhu (0x%hhx) in tracefile %s", + g_warning("Unknown facility %hhu (0x%hhx) in tracefile %s", tf->event.facility_id, tf->event.facility_id, g_quark_to_string(tf->name)); @@ -1905,7 +2044,7 @@ void ltt_update_event_size(LttTracefile *tf) ltt_facility_eventtype_get(f, tf->event.event_id); if(!event_type) { - g_error("Unknown event id %hhu in facility %s in tracefile %s", + g_warning("Unknown event id %hhu in facility %s in tracefile %s", tf->event.event_id, g_quark_to_string(f->name), g_quark_to_string(tf->name)); @@ -1923,6 +2062,10 @@ void ltt_update_event_size(LttTracefile *tf) tf->event.data_size = size; /* Check consistency between kernel and LTTV structure sizes */ + if(tf->event.event_size == 0xFFFF) { + /* Event size too big to fit in the event size field */ + tf->event.event_size = tf->event.data_size; + } g_assert(tf->event.data_size == tf->event.event_size); return; @@ -1930,7 +2073,12 @@ void ltt_update_event_size(LttTracefile *tf) facility_error: event_type_error: event_id_error: - tf->event.data_size = 0; + if(tf->event.event_size == 0xFFFF) { + g_error("Cannot jump over an unknown event bigger than 0xFFFE bytes"); + } + /* The facility is unknown : use the kernel information about this event + * to jump over it. */ + tf->event.data_size = tf->event.event_size; } @@ -2619,6 +2767,10 @@ gint check_fields_compatibility(LttEventType *event_type1, different = 1; goto end; } + if(type1->network != type2->network) { + different = 1; + goto end; + } switch(type1->type_class) { case LTT_INT_FIXED: