fix note reserving byte order in calc_nsec_per_cycle
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.c
index 95462d9677bf50e3577cb5350417e1b3c90090c1..a73e3d6ce608e12a8e66ecdab293f8afd23a9371 100644 (file)
@@ -48,7 +48,10 @@ gint compare_tracefile(gconstpointer a, gconstpointer b)
       else if(trace_a->t_context->index > trace_b->t_context->index)
         comparison = 1;
     }
+  } else {
+    comparison = 0;
   }
+
   return comparison;
 }
 
@@ -385,18 +388,19 @@ void lttv_tracefile_context_add_hooks(LttvTracefileContext *self,
           LttvHooks *event, 
           LttvHooksById *event_by_id)
 {
-  guint i;
+  guint i, index;
 
   LttvHooks *hook;
   
   lttv_hooks_call(before_tracefile, self);
   lttv_hooks_add_list(self->event, event);
-  if(event_by_id != NULL)
-    for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) {
-      hook = lttv_hooks_by_id_find(self->event_by_id, i);
-      lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, i));
+  if(event_by_id != NULL) {
+    for(i = 0; i < event_by_id->array->len; i++) {
+      index = g_array_index(event_by_id->array, guint, i);
+      hook = lttv_hooks_by_id_find(self->event_by_id, index);
+      lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, index));
     }
-
+  }
 }
 
 void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
@@ -404,18 +408,19 @@ void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
            LttvHooks *event, 
            LttvHooksById *event_by_id)
 {
-  guint i;
+  guint i, index;
 
   LttvHooks *hook;
   
-
   lttv_hooks_remove_list(self->event, event);
-  if(event_by_id != NULL)
-    for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) {
-      hook = lttv_hooks_by_id_get(self->event_by_id, i);
+  if(event_by_id != NULL) {
+    for(i = 0; i < event_by_id->array->len; i++) {
+      index = g_array_index(event_by_id->array, guint, i);
+      hook = lttv_hooks_by_id_get(self->event_by_id, index);
       if(hook != NULL)
-        lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, i));
+        lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, index));
     }
+  }
 
   lttv_hooks_call(after_tracefile, self);
 }
@@ -616,6 +621,13 @@ static gboolean get_first(gpointer key, gpointer value, gpointer user_data) {
   return TRUE;
 }
 
+static gboolean test_tree(gpointer key, gpointer value, gpointer user_data) {
+
+  g_assert(((LttvTracefileContext *)user_data) != (LttvTracefileContext *)value);
+  return FALSE;
+}
+
+
 
 void lttv_process_traceset_begin(LttvTracesetContext *self,
                                  LttvHooks       *before_traceset,
@@ -644,7 +656,7 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
 {
   GTree *pqueue = self->pqueue;
 
-  guint id;
+  guint fac_id, ev_id, id;
 
   LttvTracefileContext *tfc;
 
@@ -652,6 +664,8 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
   
   unsigned count = 0;
 
+  guint read_ret = FALSE;
+
   gboolean last_ret = FALSE; /* return value of the last hook list called */
 
   /* Get the next event from the pqueue, call its hooks, 
@@ -677,7 +691,7 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
      */
 
     if(unlikely(last_ret == TRUE ||
-                count >= nb_events ||
+                ((count >= nb_events) && (nb_events != G_MAXULONG)) ||
      (end_position!=NULL&&lttv_traceset_context_ctx_pos_compare(self,
                                                           end_position) == 0)||
        ltt_time_compare(end, tfc->timestamp) <= 0))
@@ -688,18 +702,30 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
     /* Get the tracefile with an event for the smallest time found. If two
        or more tracefiles have events for the same time, hope that lookup
        and remove are consistent. */
-
+    
     g_tree_remove(pqueue, tfc);
+
+    g_tree_foreach(pqueue, test_tree, tfc);
     count++;
     
     e = ltt_tracefile_get_event(tfc->tf);
-    id = ltt_event_eventtype_id(e);
+    fac_id = ltt_event_facility_id(e);
+    ev_id = ltt_event_eventtype_id(e);
+    id = GET_HOOK_ID(fac_id, ev_id);
     last_ret = lttv_hooks_call_merge(tfc->event, tfc,
                         lttv_hooks_by_id_get(tfc->event_by_id, id), tfc);
 
-    if(likely(!ltt_tracefile_read(tfc->tf))) {
+    read_ret = ltt_tracefile_read(tfc->tf);
+
+    if(likely(!read_ret)) {
+      g_debug("got someting");
       tfc->timestamp = ltt_event_time(e);
            g_tree_insert(pqueue, tfc, tfc);
+    } else {
+      if(read_ret == ERANGE)
+        g_debug("End of trace");
+      else
+        g_error("Error happened in lttv_process_traceset_middle");
     }
   }
 }
@@ -842,7 +868,7 @@ lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event,
 
   GArray *facilities;
 
-  guint i, fac_id;
+  guint i, fac_id, ev_id;
 
   LttvTraceHookByFacility *thf, *first_thf;
 
@@ -869,8 +895,11 @@ lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event,
   thf = &g_array_index(th->fac_index, LttvTraceHookByFacility, fac_id);
   g_array_index(th->fac_list, LttvTraceHookByFacility*, 0)
         = thf;
+
+  ev_id = ltt_eventtype_id(et);
+  
   thf->h = h;
-  thf->id = ltt_eventtype_id(et);
+  thf->id = GET_HOOK_ID(fac_id, ev_id);
   thf->f1 = find_field(et, field1);
   thf->f2 = find_field(et, field2);
   thf->f3 = find_field(et, field3);
@@ -888,8 +917,9 @@ lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event,
     thf = &g_array_index(th->fac_index, LttvTraceHookByFacility, fac_id);
     g_array_index(th->fac_list, LttvTraceHookByFacility*, i)
           = thf;
+    ev_id = ltt_eventtype_id(et);
     thf->h = h;
-    thf->id = ltt_eventtype_id(et);
+    thf->id = GET_HOOK_ID(fac_id, ev_id);
     thf->f1 = find_field(et, field1);
     if(check_fields_compatibility(first_et, et,
         first_thf->f1, thf->f1))
This page took 0.024961 seconds and 4 git commands to generate.