uninitialized variables checked, plus O2 optimisations checked : strict aliasing...
[lttv.git] / ltt / branches / poly / lttv / lttv / batchtest.c
index 2fc7fd99a4e38f7fcd381698d60cce2641216fd0..ab50262c708de894bb146ee0551d6bd2aada09d1 100644 (file)
@@ -19,7 +19,7 @@
 /* This module inserts a hook in the program main loop. This hook processes 
    all the events in the main tracefile while testing the speed and
    functionality of the state and stats computations. */
-
+#include <string.h>
 
 #include <lttv/lttv.h>
 #include <lttv/attribute.h>
@@ -32,6 +32,9 @@
 #include <ltt/trace.h>
 #include <ltt/event.h>
 #include <ltt/type.h>
+#include <ltt/facility.h>
+
+#define __UNUSED__ __attribute__((__unused__))
 
 static LttvTraceset *traceset;
 
@@ -42,8 +45,9 @@ static LttvHooks
   *after_trace,
   *before_tracefile,
   *after_tracefile,
-  *before_event,
-  *after_event,
+  //*before_event,
+  //*after_event,
+  *event_hook,
   *main_hooks;
 
 static char *a_trace;
@@ -55,6 +59,7 @@ static char *a_save_sample;
 static int
   a_sample_interval,
   a_sample_number,
+  a_seek_number,
   a_save_interval;
 
 static gboolean
@@ -82,7 +87,7 @@ typedef struct _save_state {
 } SaveState;
 
 
-static void lttv_trace_option(void *hook_data)
+static void lttv_trace_option(void __UNUSED__ *hook_data)
 { 
   LttTrace *trace;
 
@@ -103,11 +108,17 @@ static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
 {
   double t0, t1;
 
-  int i;
+  unsigned int i;
 
-  lttv_traceset_context_add_hooks(&ts->parent,
-  before_traceset, after_traceset, NULL, before_trace, after_trace,
-  NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
+  //lttv_traceset_context_add_hooks(&ts->parent,
+  //before_traceset, after_traceset, NULL, before_trace, after_trace,
+  //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
+  lttv_process_traceset_begin(&ts->parent,
+                              before_traceset,
+                              before_trace,
+                              before_tracefile,
+                              event_hook,
+                              NULL);
 
   for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) {
     ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval;
@@ -115,18 +126,28 @@ static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end)
 
   t0 = get_time();
   lttv_state_traceset_seek_time_closest(ts, start);
-  lttv_process_traceset(&ts->parent, end, G_MAXULONG);
+  //lttv_process_traceset(&ts->parent, end, G_MAXULONG);
+  lttv_process_traceset_middle(&ts->parent,
+                               end,
+                               G_MAXULONG,
+                               NULL);
   t1 = get_time();
 
-  lttv_traceset_context_remove_hooks(&ts->parent,
-  before_traceset, after_traceset, NULL, before_trace, after_trace,
-  NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
+  //lttv_traceset_context_remove_hooks(&ts->parent,
+  //before_traceset, after_traceset, NULL, before_trace, after_trace,
+  //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
+  lttv_process_traceset_end(&ts->parent,
+                            after_traceset,
+                            after_trace,
+                            after_tracefile,
+                            event_hook,
+                            NULL);
 
   return t1 - t0;
 }
 
 
-gboolean trace_event(void *hook_data, void *call_data)
+gboolean trace_event(void __UNUSED__ *hook_data, void *call_data)
 {
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
@@ -136,7 +157,7 @@ gboolean trace_event(void *hook_data, void *call_data)
 
   ltt_event_position(tfs->parent.e, a_event_position);
   ltt_event_position_get(a_event_position, &nb_block, &nb_event, &tf);
-  fprintf(stderr,"Event %s %lu.%09lu [%lu %lu]\n",
+  fprintf(stderr,"Event %s %lu.%09lu [%u %u]\n",
       ltt_eventtype_name(ltt_event_eventtype(tfs->parent.e)),
       tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec,
       nb_block, nb_event);
@@ -144,7 +165,7 @@ gboolean trace_event(void *hook_data, void *call_data)
 }
 
 
-gboolean count_event(void *hook_data, void *call_data)
+gboolean count_event(void *hook_data, void __UNUSED__ *call_data)
 {
   guint *pcount = (guint *)hook_data;
 
@@ -155,7 +176,7 @@ gboolean count_event(void *hook_data, void *call_data)
 
 gboolean save_state_copy_event(void *hook_data, void *call_data)
 {
-  SaveState *save_state = (SaveState *)hook_data;
+  SaveState __UNUSED__ *save_state = (SaveState *)hook_data;
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
@@ -215,7 +236,8 @@ gboolean save_state_event(void *hook_data, void *call_data)
 }
 
 
-static gboolean process_traceset(void *hook_data, void *call_data)
+static gboolean process_traceset(void __UNUSED__ *hook_data, 
+                                 void __UNUSED__ *call_data)
 {
   LttvTracesetStats *tscs;
 
@@ -235,17 +257,18 @@ static gboolean process_traceset(void *hook_data, void *call_data)
 
   LttTracefile *tracefile, *tf;
 
-  LttEvent *event;
+  LttEvent *event = ltt_event_new();
 
   LttFacility *facility;
 
-  LttType *type;
-
   LttEventType *event_type;
 
   LttTime time, previous_time;
 
-  long long unsigned cycle_count, start_count, delta_cycle;
+  /* start_count is always initialized in this function _if_ there is always
+   * a block_start before a block_end.
+   */
+  long long unsigned cycle_count, start_count=0, delta_cycle;
 
   long long unsigned start_nsec, end_nsec, delta_nsec, added_nsec, added_nsec2;
 
@@ -282,7 +305,7 @@ static gboolean process_traceset(void *hook_data, void *call_data)
         ltt_tracefile_seek_time(tracefile, zero_time);
         previous_time = zero_time;
         nb_equal = 0;
-        while((event = ltt_tracefile_read(tracefile)) != NULL) {
+        while((ltt_tracefile_read(tracefile, event)) != NULL) {
           facility = ltt_event_facility(event);
           event_type = ltt_event_eventtype(event);
           time = ltt_event_time(event);
@@ -347,9 +370,9 @@ static gboolean process_traceset(void *hook_data, void *call_data)
 
   if(a_test1 || a_test_all) {
     count = 0;
-    lttv_hooks_add(after_event, count_event, &count);
+    lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT);
     t = run_one_test(ts, zero_time, max_time);
-    lttv_hooks_remove_data(after_event, count_event, &count);
+    lttv_hooks_remove_data(event_hook, count_event, &count);
     g_warning(
         "Processing trace while counting events (%u events in %g seconds)",
        count, t);
@@ -381,10 +404,11 @@ static gboolean process_traceset(void *hook_data, void *call_data)
       save_state.position = 0;
       save_state.version = i;
       lttv_state_add_event_hooks(ts);
-      lttv_hooks_add(after_event, save_state_event, &save_state);
+      lttv_hooks_add(event_hook, save_state_event, &save_state,
+                        LTTV_PRIO_DEFAULT);
       t = run_one_test(ts, zero_time, max_time);
       lttv_state_remove_event_hooks(ts);
-      lttv_hooks_remove_data(after_event, save_state_event, &save_state);
+      lttv_hooks_remove_data(event_hook, save_state_event, &save_state);
       g_warning("Processing while updating/writing state (%g seconds)", t);
     }
   }
@@ -455,7 +479,8 @@ static gboolean process_traceset(void *hook_data, void *call_data)
 
   /* Run through all events computing and saving the state. */
 
-  if(a_trace_event) lttv_hooks_add(after_event, trace_event, NULL);
+  if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL,
+                                      LTTV_PRIO_DEFAULT);
 
   if(a_test6 || a_test_all) {
     if(lttv_profile_memory) {
@@ -466,12 +491,13 @@ static gboolean process_traceset(void *hook_data, void *call_data)
     lttv_state_add_event_hooks(ts);
     lttv_state_save_add_event_hooks(ts);
     if(a_save_state_copy)
-        lttv_hooks_add(after_event, save_state_copy_event, &save_state);
+        lttv_hooks_add(event_hook, save_state_copy_event, &save_state,
+                          LTTV_PRIO_DEFAULT);
     t = run_one_test(ts, zero_time, max_time);
     lttv_state_remove_event_hooks(ts);
     lttv_state_save_remove_event_hooks(ts);
     if(a_save_state_copy)
-        lttv_hooks_remove_data(after_event,save_state_copy_event, &save_state);
+        lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state);
 
     g_warning("Processing trace while updating/saving state (%g seconds)", t);
 
@@ -484,10 +510,11 @@ static gboolean process_traceset(void *hook_data, void *call_data)
   /* Seek a few times to each saved position */
 
   if((a_test7 && a_test3) || a_test_all) {
-    int i, j;
-
-    for(i = 0 ; i < 2 ; i++) {
-      for(j = save_state.position - 1 ; j >= 0 ; j--) {
+    g_assert(a_seek_number >= 0);
+    for(i = 0 ; i < (guint)a_seek_number ; i++) {
+      gint reverse_j; /* just to make sure j is unsigned */
+      for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) {
+        j = (guint)reverse_j;
         lttv_state_add_event_hooks(ts);
         t = run_one_test(ts, save_state.write_time[j], 
             save_state.write_time[j]);
@@ -512,12 +539,13 @@ static gboolean process_traceset(void *hook_data, void *call_data)
     }
   }
 
-  if(a_trace_event) lttv_hooks_remove_data(after_event, trace_event, NULL);
+  if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL);
 
   g_free(save_state.write_time);
   g_free(a_event_position);
   lttv_context_fini(tc);
   g_object_unref(tscs);
+  ltt_event_destroy(event);
 
   if(lttv_profile_memory) {
     g_message("Memory summary at the end of batchtest");
@@ -525,6 +553,7 @@ static gboolean process_traceset(void *hook_data, void *call_data)
   }
 
   g_info("BatchTest end process traceset");
+  return 0;
 }
 
 
@@ -577,6 +606,12 @@ static void init()
       "maximum number", 
       LTTV_OPT_INT, &a_sample_number, NULL, NULL);
 
+  a_seek_number = 200;
+  lttv_option_add("seek-number", 'K', 
+      "Number of seek", 
+      "number", 
+      LTTV_OPT_INT, &a_seek_number, NULL, NULL);
+
   a_test1 = FALSE;
   lttv_option_add("test1", '1', "Test just counting events", "", 
       LTTV_OPT_NONE, &a_test1, NULL, NULL);
@@ -617,8 +652,10 @@ static void init()
   after_trace = lttv_hooks_new();
   before_tracefile = lttv_hooks_new();
   after_tracefile = lttv_hooks_new();
-  before_event = lttv_hooks_new();
-  after_event = lttv_hooks_new();
+  //before_event = lttv_hooks_new();
+  //after_event = lttv_hooks_new();
+  event_hook = lttv_hooks_new();
+  
 
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
       LTTV_POINTER, &value));
@@ -638,17 +675,19 @@ static void init()
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
       LTTV_POINTER, &value));
   *(value.v_pointer) = after_tracefile;
-  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+  //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+  //    LTTV_POINTER, &value));
+  //*(value.v_pointer) = before_event;
+  //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
+  //    LTTV_POINTER, &value));
+  //*(value.v_pointer) = after_event;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
       LTTV_POINTER, &value));
-  *(value.v_pointer) = before_event;
-  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
-      LTTV_POINTER, &value));
-  *(value.v_pointer) = after_event;
-
+  *(value.v_pointer) = event_hook;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
       LTTV_POINTER, &value));
   g_assert((main_hooks = *(value.v_pointer)) != NULL);
-  lttv_hooks_add(main_hooks, process_traceset, NULL);
+  lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
 }
 
 
@@ -666,6 +705,7 @@ static void destroy()
   lttv_option_remove("save-state-copy");
   lttv_option_remove("sample-interval");
   lttv_option_remove("sample-number");
+  lttv_option_remove("seek-number");
   lttv_option_remove("save-interval");
   lttv_option_remove("test1");
   lttv_option_remove("test2");
@@ -682,13 +722,15 @@ static void destroy()
   lttv_hooks_destroy(after_trace);
   lttv_hooks_destroy(before_tracefile);
   lttv_hooks_destroy(after_tracefile);
-  lttv_hooks_destroy(before_event);
-  lttv_hooks_destroy(after_event);
+  //lttv_hooks_destroy(before_event);
+  //lttv_hooks_destroy(after_event);
+  lttv_hooks_destroy(event_hook);
   lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
 
   nb = lttv_traceset_number(traceset);
   for(i = 0 ; i < nb ; i++) {
     trace = lttv_traceset_get(traceset, i);
+    lttv_traceset_remove(traceset,i);
     ltt_trace_close(lttv_trace(trace));
     lttv_trace_destroy(trace);
   }
This page took 0.030782 seconds and 4 git commands to generate.