traceset position save fix
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.c
index 69b2e14fd19246ee268d4400f3e05cbce9c75f4c..58310b4090f8453558dfd2a1f522e4d0e4856b95 100644 (file)
@@ -623,6 +623,10 @@ static gboolean get_first(gpointer key, gpointer value, gpointer user_data) {
   return TRUE;
 }
 
+#ifdef DEBUG
+// Test to see if pqueue is traversed in the right order.
+static LttTime test_time;
+
 static gboolean test_tree(gpointer key, gpointer value, gpointer user_data) {
 
   LttvTracefileContext *tfc = (LttvTracefileContext *)key;
@@ -631,15 +635,22 @@ static gboolean test_tree(gpointer key, gpointer value, gpointer user_data) {
       g_quark_to_string(ltt_tracefile_name(tfc->tf)),
       tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec,
       tfc->index, tfc->t_context->index);
+  
+  if(user_data != NULL) {
+    if(((LttvTracefileContext *)user_data) == (LttvTracefileContext *)value) {
+      g_assert(compare_tracefile(user_data, value) == 0);
+    } else
+      g_assert(compare_tracefile(user_data, value) != 0);
+  }
+  g_assert(ltt_time_compare(test_time, tfc->timestamp) <= 0);
+  test_time.tv_sec = tfc->timestamp.tv_sec;
+  test_time.tv_nsec = tfc->timestamp.tv_nsec;
 
-  if(((LttvTracefileContext *)user_data) == (LttvTracefileContext *)value) {
-    g_assert(compare_tracefile(user_data, value) == 0);
-  } else
-    g_assert(compare_tracefile(user_data, value) != 0);
   
   //g_assert(((LttvTracefileContext *)user_data) != (LttvTracefileContext *)value);
   return FALSE;
 }
+#endif //DEBUG
 
 
 
@@ -722,12 +733,16 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
        and remove are consistent. */
  
 #ifdef DEBUG
+    test_time.tv_sec = 0;
+    test_time.tv_nsec = 0;
     g_debug("test tree before remove");
     g_tree_foreach(pqueue, test_tree, tfc);
 #endif //DEBUG
     g_tree_remove(pqueue, tfc);
 
 #ifdef DEBUG
+    test_time.tv_sec = 0;
+    test_time.tv_nsec = 0;
     g_debug("test tree after remove");
     g_tree_foreach(pqueue, test_tree, tfc);
 #endif //DEBUG
@@ -749,10 +764,17 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
     read_ret = ltt_tracefile_read(tfc->tf);
 
     if(likely(!read_ret)) {
-      g_debug("An event is ready");
+      //g_debug("An event is ready");
       tfc->timestamp = ltt_event_time(e);
-      
+      g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0);
            g_tree_insert(pqueue, tfc, tfc);
+#ifdef DEBUG
+      test_time.tv_sec = 0;
+      test_time.tv_nsec = 0;
+      g_debug("test tree after event ready");
+      g_tree_foreach(pqueue, test_tree, NULL);
+#endif //DEBUG
+
       last_read_state = LAST_OK;
     } else {
       tfc->timestamp = ltt_time_infinite;
@@ -786,7 +808,10 @@ void lttv_process_traceset_end(LttvTracesetContext *self,
 
 /* Subtile modification : 
  * if tracefile has no event at or after the time requested, it is not put in
- * the queue, as the next read would fail. */
+ * the queue, as the next read would fail.
+ *
+ * Don't forget to empty the traceset pqueue before calling this.
+ */
 void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
 {
   guint i, nb_tracefile;
@@ -795,25 +820,35 @@ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
   
   LttvTracefileContext **tfc;
 
-  GTree *pqueue = self->ts_context->pqueue;
-
   nb_tracefile = self->tracefiles->len;
 
+  GTree *pqueue = self->ts_context->pqueue;
+
   for(i = 0 ; i < nb_tracefile ; i++) {
     tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i);
 
-    g_tree_remove(pqueue, *tfc);
+    //g_tree_remove(pqueue, *tfc);
     
     ret = ltt_tracefile_seek_time((*tfc)->tf, start);
     if(ret == EPERM) g_error("error in lttv_process_trace_seek_time seek");
 
     if(ret == 0) { /* not ERANGE especially */
       (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf));
+      g_assert(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0);
       g_tree_insert(pqueue, (*tfc), (*tfc));
     } else {
       (*tfc)->timestamp = ltt_time_infinite;
     }
   }
+#ifdef DEBUG
+  test_time.tv_sec = 0;
+  test_time.tv_nsec = 0;
+  g_debug("test tree after seek_time");
+  g_tree_foreach(pqueue, test_tree, NULL);
+#endif //DEBUG
+
+
+
 }
 
 
@@ -823,6 +858,9 @@ void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start)
 
   LttvTraceContext *tc;
 
+  g_tree_destroy(self->pqueue);
+  self->pqueue = g_tree_new(compare_tracefile);
+
   nb_trace = lttv_traceset_number(self->ts);
   for(i = 0 ; i < nb_trace ; i++) {
     tc = self->traces[i];
@@ -849,12 +887,22 @@ gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self,
         if(ltt_tracefile_seek_position((*tfc)->tf, *ep) != 0)
           return 1;
         (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf));
+        g_assert(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0);
         g_tree_insert(self->pqueue, (*tfc), (*tfc));
       } else {
         (*tfc)->timestamp = ltt_time_infinite;
       }
     }
   }
+#ifdef DEBUG
+  test_time.tv_sec = 0;
+  test_time.tv_nsec = 0;
+  g_debug("test tree after seek_position");
+  g_tree_foreach(self->pqueue, test_tree, NULL);
+#endif //DEBUG
+
+
+
   return 0;
 }
 
@@ -1021,14 +1069,17 @@ LttvTracesetContextPosition *lttv_traceset_context_position_new()
   return pos;
 }
 
-/* Save all positions, the ones not in the pqueue will have NULL
+/* Save all positions, the ones with infinite time will have NULL
  * ep. */
 void lttv_traceset_context_position_save(const LttvTracesetContext *self,
                                     LttvTracesetContextPosition *pos)
 {
   guint i;
   guint num_traces = lttv_traceset_number(self->ts);
-
+  
+  pos->tfc = g_array_set_size(pos->tfc, 0);
+  pos->ep = g_array_set_size(pos->ep, 0);
+  
   for(i=0; i<num_traces;i++) {
     GArray * tracefiles = self->traces[i]->tracefiles;
     guint j;
@@ -1077,8 +1128,8 @@ void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest,
   int i;
   LttEventPosition **src_ep, **dest_ep;
   
-  g_array_set_size(dest->ep, src->ep->len);
-  g_array_set_size(dest->tfc, src->tfc->len);
+  dest->ep = g_array_set_size(dest->ep, src->ep->len);
+  dest->tfc = g_array_set_size(dest->tfc, src->tfc->len);
   
   for(i=0;i<src->ep->len;i++) {
     src_ep = &g_array_index(src->ep, LttEventPosition*, i);
This page took 0.026416 seconds and 4 git commands to generate.