Add a module to compute various statistics
[lttv.git] / ltt / branches / poly / lttv / batchAnalysis.c
index 02b3dea4f1b9f65bccbdb2ab8b65fc66ecc13274..2db5783018d1db2f9a3334155c81b8754709acd1 100644 (file)
@@ -5,8 +5,11 @@
 #include <lttv/lttv.h>
 #include <lttv/attribute.h>
 #include <lttv/hook.h>
+#include <lttv/option.h>
+#include <lttv/module.h>
 #include <lttv/processTrace.h>
 #include <lttv/state.h>
+#include <lttv/stats.h>
 
 static LttvTraceset *traceset;
 
@@ -23,6 +26,7 @@ static LttvHooks
 
 static char *a_trace;
 
+static gboolean a_stats;
 
 void lttv_trace_option(void *hook_data)
 { 
@@ -34,46 +38,71 @@ void lttv_trace_option(void *hook_data)
 }
 
 
-static void process_traceset(void *hook_data, void *call_data)
+static gboolean process_traceset(void *hook_data, void *call_data)
 {
-  LttvTracesetState *tc;
+  LttvTracesetStats *tscs;
+
+  LttvTracesetContext *tc;
 
   LttTime start, end;
 
-  tc = g_object_new(LTTV_TRACESET_STATE);
-  lttv_context_init(LTTV_TRACESET_CONTEXT(tc), traceset);
+  g_info("BatchAnalysis begin process traceset");
+
+  tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
+  tc = &tscs->parent.parent;
+
+  g_info("BatchAnalysis initialize context");
 
-  lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc),
-  before_traceset, after_traceset, before_trace, after_trace,
-  before_tracefile, after_tracefile, before_event, after_event);
-  lttv_state_add_event_hooks(tc);
+  lttv_context_init(tc, traceset);
+  lttv_state_add_event_hooks(&tscs->parent);
+  if(a_stats) lttv_stats_add_event_hooks(tscs);
+
+  lttv_traceset_context_add_hooks(tc,
+  before_traceset, after_traceset, NULL, before_trace, after_trace,
+  NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
 
   start.tv_sec = 0;
   start.tv_nsec = 0;
   end.tv_sec = G_MAXULONG;
   end.tv_nsec = G_MAXULONG;
 
-  lttv_process_trace(start, end, traceset, tc);
-  lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc),
-  before_traceset, after_traceset, before_trace, after_trace,
-  before_tracefile, after_tracefile, before_event, after_event);
+  g_info("BatchAnalysis process traceset");
+
+  lttv_process_trace(start, end, traceset, tc, G_MAXULONG);
+
+  g_info("BatchAnalysis destroy context");
 
-  lttv_state_remove_event_hooks(tc);
-  lttv_context_fini(LTTV_TRACESET_CONTEXT(tc));
-  g_object_unref(tc);
+  lttv_traceset_context_remove_hooks(tc,
+  before_traceset, after_traceset, NULL, before_trace, after_trace,
+  NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
+  lttv_state_remove_event_hooks(&tscs->parent);
+  if(a_stats) lttv_stats_remove_event_hooks(tscs);
+  lttv_context_fini(tc);
+  g_object_unref(tscs);
+
+  g_info("BatchAnalysis end process traceset");
 }
 
 
-void init(int argc, char **argv)
+G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv)
 {
-  LttvAttribute_value *value;
+  LttvAttributeValue value;
+
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
 
-  LttvIAttributes *attributes = LTTV_IATTRIBUTES(lttv_global_attributes());
+  g_info("Init batchAnalysis.c");
 
   lttv_option_add("trace", 't', 
       "add a trace to the trace set to analyse", 
       "pathname of the directory containing the trace", 
-      LTTV_OPT_STRING, &aTrace, lttv_trace_option, NULL);
+      LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
+
+  a_stats = FALSE;
+  lttv_option_add("stats", 's', 
+      "write the traceset and trace statistics", 
+      "", 
+      LTTV_OPT_NONE, &a_stats, NULL, NULL);
+
 
   traceset = lttv_traceset_new();
 
@@ -88,43 +117,44 @@ void init(int argc, char **argv)
 
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = before_traceset;
+  *(value.v_pointer) = before_traceset;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = after_traceset;
+  *(value.v_pointer) = after_traceset;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = before_trace;
+  *(value.v_pointer) = before_trace;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = after_trace;
+  *(value.v_pointer) = after_trace;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = before_tracefile;
+  *(value.v_pointer) = before_tracefile;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = after_tracefile;
+  *(value.v_pointer) = after_tracefile;
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
       LTTV_POINTER, &value));
-  *(value->v_pointer) = before_event;
+  *(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) = after_event;
 
   g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
       LTTV_POINTER, &value));
-  g_assert((main_hooks = *(value->v_pointer)) != NULL);
+  g_assert((main_hooks = *(value.v_pointer)) != NULL);
   lttv_hooks_add(main_hooks, process_traceset, NULL);
 }
 
 
-void destroy()
+G_MODULE_EXPORT void destroy()
 {
   guint i, nb;
 
-  lttv_hooks_remove(main_hooks, process_traceset, NULL);
+  g_info("Destroy batchAnalysis.c");
 
   lttv_option_remove("trace");
+  lttv_option_remove("stats");
 
   lttv_hooks_destroy(before_traceset);
   lttv_hooks_destroy(after_traceset);
@@ -134,10 +164,13 @@ void destroy()
   lttv_hooks_destroy(after_tracefile);
   lttv_hooks_destroy(before_event);
   lttv_hooks_destroy(after_event);
+  lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
 
   nb = lttv_traceset_number(traceset);
-  for(i = 0 ; i < nb, i++) {
-    ltt_trace_close(lttv_traceset_get(traceset);
+  for(i = 0 ; i < nb ; i++) {
+    ltt_trace_close(lttv_traceset_get(traceset, i));
   }
+
+  lttv_traceset_destroy(traceset); 
 }
 
This page took 0.025313 seconds and 4 git commands to generate.