X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftracefile.c;h=a84381e9ec5c07789f7711353fa638f7d513955e;hb=3054461acbbd00cc70e9e3046050f074e9eec4c9;hp=c9564bf444e8fa8540c72989a77f1f2f7179dce9;hpb=823820eb1852619c9a24af4a01622356214c01b4;p=lttv.git diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index c9564bf4..a84381e9 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -232,8 +232,6 @@ int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t) switch(any->minor_version) { case 3: { - struct ltt_trace_header_0_3 *header_0_3 = - (struct ltt_trace_header_0_3 *)header; tf->buffer_header_size = sizeof(struct ltt_block_start_header) + sizeof(struct ltt_trace_header_0_3); @@ -292,8 +290,8 @@ 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 - + sizeof(ltt_trace_header_any)))){ + (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; } @@ -301,8 +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 - + sizeof(struct ltt_trace_header_any))), 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"); @@ -312,7 +310,10 @@ gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) header = (struct ltt_block_start_header*)tf->buffer.head; - if(parse_trace_header(header->trace, tf, NULL)) goto unmap_file; + if(parse_trace_header(header->trace, tf, NULL)) { + g_warning("parse_trace_header error"); + goto unmap_file; + } //store the size of the file tf->file_size = lTDFStat.st_size; @@ -320,11 +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 - + sizeof(struct ltt_trace_header_any))))) { + 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 - + sizeof(struct ltt_trace_header_any)))); + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any))); perror("munmap error"); g_assert(0); } @@ -341,11 +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 - + sizeof(struct ltt_trace_header_any))))) { + 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 - + sizeof(struct ltt_trace_header_any)))); + PAGE_ALIGN(sizeof(struct ltt_block_start_header) + + sizeof(struct ltt_trace_header_any))); perror("munmap error"); g_assert(0); } @@ -1114,7 +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; - g_assert(parse_trace_header(header->trace, tf, t) == 0); + g_assert(parse_trace_header(header->trace, + tf, t) == 0); t->num_cpu = group->len; @@ -1429,10 +1431,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) { @@ -1860,8 +1862,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->buffer_header_size); + tf->event.offset += tf->buffer_header_size; if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) { ret = ERANGE; @@ -1882,6 +1883,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;