update lttctl
[lttv.git] / trunk / lttv / ltt / tracefile.c
index 7f0e3fb832b3ea321ed9e6c4395e971e47551d23..58b2a48319789a3543240f9fe34d9d90f191ce0c 100644 (file)
@@ -152,10 +152,10 @@ static int parse_trace_header(ltt_subbuffer_header_t *header,
     break;
   case 2:
     switch(header->minor_version) {
-    case 0:
+    case 2:
       {
-        struct ltt_subbuffer_header_2_0 *vheader = header;
-        tf->buffer_header_size = sizeof(struct ltt_subbuffer_header_2_0) ;
+        struct ltt_subbuffer_header_2_2 *vheader = header;
+        tf->buffer_header_size = ltt_subbuffer_header_size();
         tf->tscbits = 27;
         tf->eventbits = 5;
         tf->tsc_mask = ((1ULL << tf->tscbits) - 1);
@@ -183,7 +183,7 @@ static int parse_trace_header(ltt_subbuffer_header_t *header,
 
           t->start_time_from_tsc = ltt_time_from_uint64(
               (double)t->start_tsc
-              * (1000000000.0 / tf->trace->freq_scale)
+              * 1000000000.0 * tf->trace->freq_scale
               / (double)t->start_freq);
         }
       }
@@ -238,7 +238,7 @@ static 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(ltt_subbuffer_header_t))){
+      (off_t)(ltt_subbuffer_header_size())){
     g_print("The input data file %s does not contain a trace\n", fileName);
     goto close_file;
   }
@@ -246,7 +246,7 @@ static 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(ltt_subbuffer_header_t)), PROT_READ, 
+      PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ, 
       MAP_PRIVATE, tf->fd, 0);
   if(tf->buffer.head == MAP_FAILED) {
     perror("Error in allocating memory for buffer of tracefile");
@@ -265,11 +265,13 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf)
   tf->file_size = lTDFStat.st_size;
   tf->buf_size = ltt_get_uint32(LTT_GET_BO(tf), &header->buf_size);
   tf->num_blocks = tf->file_size / tf->buf_size;
+  tf->events_lost = 0;
+  tf->subbuf_corrupt = 0;
 
   if(munmap(tf->buffer.head,
-        PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)))) {
+        PAGE_ALIGN(ltt_subbuffer_header_size()))) {
     g_warning("unmap size : %u\n",
-        PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)));
+        PAGE_ALIGN(ltt_subbuffer_header_size()));
     perror("munmap error");
     g_assert(0);
   }
@@ -286,9 +288,9 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf)
   /* Error */
 unmap_file:
   if(munmap(tf->buffer.head,
-        PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)))) {
+        PAGE_ALIGN(ltt_subbuffer_header_size()))) {
     g_warning("unmap size : %u\n",
-        PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)));
+        PAGE_ALIGN(ltt_subbuffer_header_size()));
     perror("munmap error");
     g_assert(0);
   }
@@ -772,11 +774,18 @@ LttTrace *ltt_trace_open(const gchar *pathname)
     goto metadata_error;
   }
 
-  /* Get the trace information for the control/metadata_0 tracefile */
+  /*
+   * Get the trace information for the control/metadata_0 tracefile.
+   * Getting a correct trace start_time and start_tsc is insured by the fact
+   * that no subbuffers are supposed to be lost in the metadata channel.
+   * Therefore, the first subbuffer contains the start_tsc timestamp in its
+   * buffer header.
+   */
   g_assert(group->len > 0);
   tf = &g_array_index (group, LttTracefile, 0);
   header = (ltt_subbuffer_header_t *)tf->buffer.head;
-  g_assert(parse_trace_header(header, tf, t) == 0);
+  ret = parse_trace_header(header, tf, t);
+  g_assert(!ret);
 
   t->num_cpu = group->len;
   
@@ -1069,13 +1078,13 @@ LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc)
   if(tsc > tf->trace->start_tsc) {
     time = ltt_time_from_uint64(
         (double)(tsc - tf->trace->start_tsc) 
-                                    * (1000000000.0 / tf->trace->freq_scale)
+                                    * 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)
+                                    * 1000000000.0 * tf->trace->freq_scale
                                     / (double)tf->trace->start_freq);
     time = ltt_time_sub(tf->trace->start_time_from_tsc, time);
   }
@@ -1378,6 +1387,21 @@ static gint map_block(LttTracefile * tf, guint block_num)
   tf->event.block = block_num;
   tf->event.offset = 0;
   
+  if (header->events_lost) {
+    g_warning("%d events lost so far in tracefile %s at block %u",
+      (guint)header->events_lost,
+      g_quark_to_string(tf->long_name),
+      block_num);
+    tf->events_lost = header->events_lost;
+  }
+  if (header->subbuf_corrupt) {
+    g_warning("%d subbuffer(s) corrupted so far in tracefile %s at block %u",
+      (guint)header->subbuf_corrupt,
+      g_quark_to_string(tf->long_name),
+      block_num);
+    tf->subbuf_corrupt = header->subbuf_corrupt;
+  }
+
   return 0;
 
 map_error:
@@ -1468,7 +1492,8 @@ void ltt_update_event_size(LttTracefile *tf)
    */
   if (likely(info && info->fields)) {
     /* alignment */
-    tf->event.data += ltt_align((off_t)tf->event.data, info->largest_align,
+    tf->event.data += ltt_align((off_t)(unsigned long)tf->event.data,
+                            info->largest_align,
                              info->alignment);
     /* size, dynamically computed */
     if (info->size != -1)
This page took 0.025214 seconds and 4 git commands to generate.