X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftracefile.c;h=d3c6537326956e6aff339706372496118b63104e;hb=348c6ba830cba63cc5486e2cea042c8a70cf1fb2;hp=20ba35dec91d9ccb1a628485299824d129e08212;hpb=79257ba540581e198c9d9b047fe0738a25c324ff;p=lttv.git diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 20ba35de..d3c65373 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -191,6 +191,71 @@ guint ltt_trace_get_num_cpu(LttTrace *t) } +/* trace can be NULL + * + * Return value : 0 success, 1 bad tracefile + */ +int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) +{ + guint32 *magic_number = (guint32*)header; + struct ltt_trace_header_any *any = (struct ltt_trace_header_any *)header; + + if(*magic_number == LTT_MAGIC_NUMBER) + tf->reverse_bo = 0; + else if(*magic_number == LTT_REV_MAGIC_NUMBER) + tf->reverse_bo = 1; + else /* invalid magic number, bad tracefile ! */ + return 1; + + /* 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; + + if(t) { + t->arch_type = ltt_get_uint32(LTT_GET_BO(tf), + &any->arch_type); + t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf), + &any->arch_variant); + t->arch_size = any->arch_size; + t->ltt_major_version = any->major_version; + 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; + } + + + switch(any->major_version) { + + case 0: + switch(any->minor_version) { + case 3: + { + tf->buffer_header_size = + sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_0_3); + } + break; + default: + g_warning("Unsupported trace version : %hhu.%hhu", + any->major_version, any->minor_version); + return 1; + } + break; + + default: + g_warning("Unsupported trace version : %hhu.%hhu", + any->major_version, any->minor_version); + return 1; + } + + + return 0; +} + + + /***************************************************************************** *Function name * ltt_tracefile_open : open a trace file, construct a LttTracefile @@ -224,7 +289,9 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) } // Is the file large enough to contain a trace - if(lTDFStat.st_size < (off_t)(sizeof(struct ltt_block_start_header))){ + if(lTDFStat.st_size < + (off_t)(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any))){ g_print("The input data file %s does not contain a trace\n", fileName); goto close_file; } @@ -232,7 +299,8 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) /* Temporarily map the buffer start header to get trace information */ /* Multiple of pages aligned head */ tf->buffer.head = mmap(0, - PAGE_ALIGN(sizeof(struct ltt_block_start_header)), PROT_READ, + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any)), PROT_READ, MAP_PRIVATE, tf->fd, 0); if(tf->buffer.head == MAP_FAILED) { perror("Error in allocating memory for buffer of tracefile"); @@ -242,15 +310,10 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) header = (struct ltt_block_start_header*)tf->buffer.head; - if(header->trace.magic_number == LTT_MAGIC_NUMBER) - tf->reverse_bo = 0; - else if(header->trace.magic_number == LTT_REV_MAGIC_NUMBER) - tf->reverse_bo = 1; - else /* invalid magic number, bad tracefile ! */ + if(parse_trace_header(header->trace, tf, NULL)) { + g_warning("parse_trace_header error"); goto unmap_file; - /* 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 = header->trace.float_word_order; + } //store the size of the file tf->file_size = lTDFStat.st_size; @@ -258,9 +321,11 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) tf->num_blocks = tf->file_size / tf->buf_size; if(munmap(tf->buffer.head, - PAGE_ALIGN(sizeof(struct ltt_block_start_header)))) { + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any)))) { g_warning("unmap size : %u\n", - PAGE_ALIGN(sizeof(struct ltt_block_start_header))); + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any))); perror("munmap error"); g_assert(0); } @@ -277,9 +342,11 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) /* Error */ unmap_file: if(munmap(tf->buffer.head, - PAGE_ALIGN(sizeof(struct ltt_block_start_header)))) { + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any)))) { g_warning("unmap size : %u\n", - PAGE_ALIGN(sizeof(struct ltt_block_start_header))); + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any))); perror("munmap error"); g_assert(0); } @@ -1048,15 +1115,8 @@ LttTrace *ltt_trace_open(const gchar *pathname) g_assert(group->len > 0); tf = &g_array_index (group, LttTracefile, 0); header = (struct ltt_block_start_header*)tf->buffer.head; - t->arch_type = ltt_get_uint32(LTT_GET_BO(tf), &header->trace.arch_type); - t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf), &header->trace.arch_variant); - t->arch_size = header->trace.arch_size; - t->ltt_major_version = header->trace.major_version; - t->ltt_minor_version = header->trace.minor_version; - t->flight_recorder = header->trace.flight_recorder; - t->has_heartbeat = header->trace.has_heartbeat; - t->has_alignment = header->trace.has_alignment; - t->has_tsc = header->trace.has_tsc; + g_assert(parse_trace_header(header->trace, + tf, t) == 0); t->num_cpu = group->len; @@ -1257,11 +1317,17 @@ void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end) *Get the name of a tracefile ****************************************************************************/ -GQuark ltt_tracefile_name(LttTracefile *tf) +GQuark ltt_tracefile_name(const LttTracefile *tf) { return tf->name; } +GQuark ltt_tracefile_long_name(const LttTracefile *tf) +{ + return tf->long_name; +} + + guint ltt_tracefile_num(LttTracefile *tf) { @@ -1371,10 +1437,10 @@ int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time) } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) { /* go to lower part */ - high = block_num; + high = block_num - 1; } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) { /* go to higher part */ - low = block_num; + low = block_num + 1; } else {/* The event is right in the buffer! (or in the next buffer first event) */ while(1) { @@ -1659,15 +1725,15 @@ static gint map_block(LttTracefile * tf, guint block_num) tf->buffer.begin.timestamp = ltt_get_time(LTT_GET_BO(tf), &header->begin.timestamp); tf->buffer.begin.timestamp.tv_nsec *= NSEC_PER_USEC; - g_debug("block %u begin : %lu.%lu", block_num, - tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec); + //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; - g_debug("block %u end : %lu.%lu", block_num, - tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec); + //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.lost_size = ltt_get_uint32(LTT_GET_BO(tf), @@ -1714,21 +1780,21 @@ void ltt_update_event_size(LttTracefile *tf) switch((enum ltt_core_events)tf->event.event_id) { 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); + //g_debug("Update Event facility load of facility %s", (char*)tf->event.data); size += sizeof(struct LttFacilityLoad); break; case LTT_EVENT_FACILITY_UNLOAD: - g_debug("Update Event facility unload"); + //g_debug("Update Event facility unload"); size = sizeof(struct LttFacilityUnload); break; case LTT_EVENT_STATE_DUMP_FACILITY_LOAD: size = strlen((char*)tf->event.data) + 1; - g_debug("Update Event facility load state dump of facility %s", - (char*)tf->event.data); + //g_debug("Update Event facility load state dump of facility %s", + // (char*)tf->event.data); size += sizeof(struct LttStateDumpFacilityLoad); break; case LTT_EVENT_HEARTBEAT: - g_debug("Update Event heartbeat"); + //g_debug("Update Event heartbeat"); size = sizeof(TimeHeartbeat); break; default: @@ -1765,9 +1831,9 @@ void ltt_update_event_size(LttTracefile *tf) else size = 0; - g_debug("Event root field : f.e %hhu.%hhu size %zd", - tf->event.facility_id, - tf->event.event_id, size); + //g_debug("Event root field : f.e %hhu.%hhu size %zd", + // tf->event.facility_id, + // tf->event.event_id, size); } tf->event.data_size = size; @@ -1802,7 +1868,7 @@ static int ltt_seek_next_event(LttTracefile *tf) /* seek over the buffer header if we are at the buffer start */ if(tf->event.offset == 0) { - tf->event.offset += sizeof(struct ltt_block_start_header); + tf->event.offset += tf->buffer_header_size; if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) { ret = ERANGE; @@ -1823,6 +1889,7 @@ static int ltt_seek_next_event(LttTracefile *tf) ret = ERANGE; goto found; } + g_assert(tf->event.offset < tf->buf_size - tf->buffer.lost_size); found: return ret;