Add config.h support : will fix the LARGEFILE problem
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.c
index e0ddd00616f8ebc88931e68210f25bfad718c075..6179f95ecd4b5516afc395341e5bbc50b55ab2fc 100644 (file)
  * MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <string.h>
 #include <lttv/tracecontext.h>
 #include <ltt/event.h>
 
 
 
-gint compare_tracefile(gconstpointer a, gconstpointer b)
+static gint compare_tracefile(gconstpointer a, gconstpointer b)
 {
-  gint comparison;
+  gint comparison = 0;
 
   const LttvTracefileContext *trace_a = (const LttvTracefileContext *)a;
-
   const LttvTracefileContext *trace_b = (const LttvTracefileContext *)b;
 
-  if(trace_a == trace_b) return 0;
-  comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp);
-  if(comparison != 0) return comparison;
-  if(trace_a->index < trace_b->index) return -1;
-  else if(trace_a->index > trace_b->index) return 1;
-  if(trace_a->t_context->index < trace_b->t_context->index) return -1;
-  else if(trace_a->t_context->index > trace_b->t_context->index) return 1;
-  
-  g_assert(FALSE);
-  return 0; /* This should never happen */
+  if(likely(trace_a != trace_b)) {
+    comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp);
+    if(unlikely(comparison == 0)) {
+      if(trace_a->index < trace_b->index) comparison = -1;
+      else if(trace_a->index > trace_b->index) comparison = 1;
+      else if(trace_a->t_context->index < trace_b->t_context->index) 
+        comparison = -1;
+      else if(trace_a->t_context->index > trace_b->t_context->index)
+        comparison = 1;
+    }
+  }
+  return comparison;
 }
 
 struct _LttvTraceContextPosition {
@@ -359,9 +364,8 @@ void lttv_tracefile_context_add_hooks(LttvTracefileContext *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_get(self->event_by_id, i);
-      if(hook != NULL)
-        lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(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));
     }
 
 }
@@ -379,8 +383,9 @@ void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
   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_find(self->event_by_id, i);
-      lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, i));
+      hook = lttv_hooks_by_id_get(self->event_by_id, i);
+      if(hook != NULL)
+        lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, i));
     }
 
   lttv_hooks_call(after_tracefile, self);
@@ -577,7 +582,7 @@ lttv_tracefile_context_get_type(void)
 
 
 
-gboolean get_first(gpointer key, gpointer value, gpointer user_data) {
+static gboolean get_first(gpointer key, gpointer value, gpointer user_data) {
   *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value;
   return TRUE;
 }
@@ -666,7 +671,7 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
     tfc = NULL;
     g_tree_foreach(pqueue, get_first, &tfc);
     /* End of traceset : tfc is NULL */
-    if(tfc == NULL)
+    if(unlikely(tfc == NULL))
     {
       return count;
     }
@@ -679,11 +684,11 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
      * break the loop.
      */
 
-    if(last_ret == TRUE ||
-       count >= nb_events ||
+    if(unlikely(last_ret == TRUE ||
+                count >= nb_events ||
      (end_position!=NULL&&lttv_traceset_context_ctx_pos_compare(self,
                                                           end_position) == 0)||
-       ltt_time_compare(tfc->timestamp, end) >= 0)
+       ltt_time_compare(end, tfc->timestamp) <= 0))
     {
       return count;
     }
@@ -699,7 +704,7 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
     last_ret = lttv_hooks_call_merge(tfc->event, tfc,
                         lttv_hooks_by_id_get(tfc->event_by_id, id), tfc);
 
-    if(ltt_tracefile_read(tfc->tf, tfc->e) != NULL) {
+    if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) {
       tfc->timestamp = ltt_event_time(tfc->e);
            g_tree_insert(pqueue, tfc, tfc);
     }
@@ -739,7 +744,7 @@ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
     tfc = self->tracefiles[i];
     ltt_tracefile_seek_time(tfc->tf, start);
     g_tree_remove(pqueue, tfc);
-    if(ltt_tracefile_read(tfc->tf, tfc->e) != NULL) {
+    if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) {
       tfc->timestamp = ltt_event_time(tfc->e);
       g_tree_insert(pqueue, tfc, tfc);
     }
@@ -770,7 +775,7 @@ gboolean lttv_process_tracefile_seek_position(LttvTracefileContext *self,
   
   ltt_tracefile_seek_position(tfc->tf, pos);
   g_tree_remove(pqueue, tfc);
-  if(ltt_tracefile_read(tfc->tf, tfc->e) != NULL) {
+  if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) {
     tfc->timestamp = ltt_event_time(tfc->e);
     g_tree_insert(pqueue, tfc, tfc);
   }
@@ -861,10 +866,10 @@ lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type,
   guint nb, pos;
 
   nb = ltt_trace_facility_find(t, facility, &pos);
-  if(nb < 1) g_error("No %s facility", facility);
+  if(unlikely(nb < 1)) g_error("No %s facility", facility);
   f = ltt_trace_facility_get(t, pos);
   et = ltt_facility_eventtype_get_by_name(f, event_type);
-  if(et == NULL) g_error("Event %s does not exist", event_type);
+  if(unlikely(et == NULL)) g_error("Event %s does not exist", event_type);
 
   th->h = h;
   th->id = ltt_eventtype_id(et);
@@ -986,7 +991,7 @@ gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
 
   nb_trace = lttv_traceset_number(self->ts);
 
-  if(pos->nb_trace != nb_trace)
+  if(unlikely(pos->nb_trace != nb_trace))
     g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match.");
   
   for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
@@ -994,7 +999,7 @@ gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
     nb_tracefile =  ltt_trace_control_tracefile_number(tc->t) +
                     ltt_trace_per_cpu_tracefile_number(tc->t);
 
-    if(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile)
+    if(unlikely(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile))
       g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
 
     for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
@@ -1020,13 +1025,13 @@ gint lttv_traceset_context_pos_pos_compare(
   gint ret;
 
   nb_trace = pos1->nb_trace;
-  if(nb_trace != pos2->nb_trace)
+  if(unlikely(nb_trace != pos2->nb_trace))
     g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match.");
 
   for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
 
     nb_tracefile = pos1->t_pos[iter_trace].nb_tracefile;
-    if(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile)
+    if(unlikely(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile))
       g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
 
     for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
This page took 0.02797 seconds and 4 git commands to generate.