Add functions to open trace from the traceset
authormdenis <mathieu.denis@polymtl.ca>
Wed, 28 Mar 2012 03:33:13 +0000 (23:33 -0400)
committerYannick Brosseau <yannick.brosseau@gmail.com>
Mon, 11 Jun 2012 21:34:33 +0000 (17:34 -0400)
Signed-off-by: Yannick Brosseau <yannick.brosseau@gmail.com>
lttv/lttv/batchtest.c
lttv/lttv/state.c
lttv/lttv/tracecontext.c
lttv/lttv/traceset.c
lttv/lttv/traceset.h
lttv/modules/text/batchAnalysis.c

index 08b892beb43d1894c02d7d333bae403fe052ad9f..a7e1642027d95e44d264597dba260cebbc3fb93d 100644 (file)
@@ -98,6 +98,7 @@ typedef struct _save_state {
 
 static void lttv_trace_option(void __UNUSED__ *hook_data)
 { 
+#ifdef BABEL_CLEANUP
        LttTrace *trace;
 
        trace = ltt_trace_open(a_trace);
@@ -106,6 +107,11 @@ static void lttv_trace_option(void __UNUSED__ *hook_data)
        } else {
                lttv_traceset_add(traceset, lttv_trace_new(trace));
        }
+#endif
+
+       if(lttv_traceset_add_path(traceset, a_trace) < 0) {
+                       g_critical("cannot open trace %s", a_trace);
+       }
 }
 
 static double get_time() 
@@ -390,6 +396,7 @@ close:
        fclose(fp);
 }
 
+// TODO mdenis: adapt to babeltrace
 static gboolean process_traceset(void __UNUSED__ *hook_data, 
                                void __UNUSED__ *call_data)
 {
@@ -408,10 +415,11 @@ static gboolean process_traceset(void __UNUSED__ *hook_data,
        //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal;
        guint i, j, count;
 
-       LttTrace *trace;
-
        LttTime max_time = { G_MAXULONG, G_MAXULONG };
 
+#ifdef BABEL_CLEANUP
+       LttTrace *trace;
+
        a_event_position = ltt_event_position_new();
 
        GData **tracefiles_groups;
@@ -431,6 +439,7 @@ static gboolean process_traceset(void __UNUSED__ *hook_data,
 
                }
        }
+#endif
 
        tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
        ts = &tscs->parent;
@@ -998,8 +1007,10 @@ static void destroy()
        for(i = 0 ; i < nb ; i++) {
                trace = lttv_traceset_get(traceset, i);
                lttv_traceset_remove(traceset,i);
+#ifdef BABEL_CLEANUP
                ltt_trace_close(lttv_trace(trace));
                lttv_trace_destroy(trace);
+#endif
        }
 
        lttv_traceset_destroy(traceset);
index 38d3ba4a5f8d8cfd6264428b1f72336e3dea0a59..f3c4bb7d16a76f2d2ce8d09a624ec431dda26f93 100644 (file)
@@ -660,6 +660,8 @@ static void init(LttvTracesetState *self, LttvTraceset *ts)
                        init((LttvTracesetContext *)self, ts);
 
        nb_trace = lttv_traceset_number(ts);
+
+#ifdef BABEL_CLEANUP
        for(i = 0 ; i < nb_trace ; i++) {
                tc = self->parent.traces[i];
                tcs = LTTV_TRACE_STATE(tc);
@@ -738,10 +740,12 @@ static void init(LttvTracesetState *self, LttvTraceset *ts)
                /* See if the trace has saved states */
                state_load_saved_states(tcs);
        }
+#endif
 }
 
 static void fini(LttvTracesetState *self)
 {
+#ifdef BABEL_CLEANUP
        guint i, nb_trace;
 
        LttvTraceState *tcs;
@@ -771,6 +775,7 @@ static void fini(LttvTracesetState *self)
                tcs->processes = NULL;
                tcs->usertraces = NULL;
        }
+#endif
        LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))->
                        fini((LttvTracesetContext *)self);
 }
index 1123bf7b40710ebeb4c123434ed098c12948dfad..e937789c1e5ac499fd8df0f1e9817aac92f7a44a 100644 (file)
@@ -120,6 +120,8 @@ lttv_context_new_tracefile_context(LttvTracesetContext *self)
 void lttv_traceset_context_compute_time_span(LttvTracesetContext *self,
        TimeInterval *time_span)
 {
+       //todo mdenis: adapt to babeltrace
+#ifdef BABEL_CLEANUP
        LttvTraceset * traceset = self->ts;
        int numTraces = lttv_traceset_number(traceset);
        int i;
@@ -134,6 +136,7 @@ void lttv_traceset_context_compute_time_span(LttvTracesetContext *self,
 
        for(i=0; i<numTraces;i++){
                tc = self->traces[i];
+
                trace = tc->t;
 
                ltt_trace_time_span_get(trace, &s, &e);
@@ -154,6 +157,7 @@ void lttv_traceset_context_compute_time_span(LttvTracesetContext *self,
                                time_span->end_time = e;
                }
        }
+#endif
 }
 
 static void init_tracefile_context(LttTracefile *tracefile,
@@ -202,7 +206,6 @@ init(LttvTracesetContext *self, LttvTraceset *ts)
                                        &begin_pos,
                                        NULL);
        self->event_hooks = lttv_hooks_new();
-#ifdef BABEL_CLEANUP
        for(i = 0 ; i < nb_trace ; i++) {
                tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self);
                self->traces[i] = tc;
@@ -210,12 +213,15 @@ init(LttvTracesetContext *self, LttvTraceset *ts)
                tc->ts_context = self;
                tc->index = i;
                tc->vt = lttv_traceset_get(ts, i);
+#ifdef BABEL_CLEANUP
                tc->t = lttv_trace(tc->vt);
+#endif
                tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
                tc->t_a = lttv_trace_attribute(tc->vt);
                tc->tracefiles = g_array_sized_new(FALSE, TRUE,
                                sizeof(LttvTracefileContext*), 10);
 
+#ifdef BABEL_CLEANUP
                tracefiles_groups = ltt_trace_get_tracefiles_groups(tc->t);
                if(tracefiles_groups != NULL) {
                        args.func = (ForEachTraceFileFunc)init_tracefile_context;
@@ -225,10 +231,10 @@ init(LttvTracesetContext *self, LttvTraceset *ts)
                                        (GDataForeachFunc)compute_tracefile_group,
                                        &args);
                }
+#endif
 
 
        }
-#endif
        self->sync_position = lttv_traceset_context_position_new(self);
        self->pqueue = g_tree_new(compare_tracefile);
        lttv_process_traceset_seek_time(self, ltt_time_zero);
@@ -878,9 +884,6 @@ void lttv_process_traceset_end(LttvTracesetContext *self,
  */
 void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
 {
-
-
-#ifdef BABEL_CLEANUP
        guint i, nb_tracefile;
 
        gint ret;
@@ -913,7 +916,6 @@ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
        g_debug("test tree after seek_time");
        g_tree_foreach(pqueue, test_tree, NULL);
 #endif //DEBUG
-#endif
 }
 
 /****************************************************************************
index 32553b5e475be7f1173d033cdcef11d867993c2b..b28efb3ac6f490c15377757ee6b2dc227a29fd0d 100644 (file)
@@ -40,12 +40,12 @@ struct _LttvTraceset {
 
 
 struct _LttvTrace {
-       LttTrace *t;
+  // Trace id for babeltrace
+       gint id;
        LttvAttribute *a;
        guint ref_count;
 };
 
-
 LttvTraceset *lttv_traceset_new() 
 {
        LttvTraceset *s;
@@ -63,17 +63,70 @@ char * lttv_traceset_name(LttvTraceset * s)
        return s->filename;
 }
 
-LttvTrace *lttv_trace_new(LttTrace *t) 
+#ifdef BABEL_CLEANUP
+LttvTrace *lttv_trace_new(LttTrace *t)
 {
        LttvTrace *new_trace;
 
        new_trace = g_new(LttvTrace, 1);
        new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
-       new_trace->t = t;
+       new_trace->id = t;
        new_trace->ref_count = 0;
        return new_trace;
 }
+#endif
 
+/*
+ * lttv_trace_create : Create a trace from a path
+ *
+ * ts is the traceset in which will be contained the trace
+ *
+ * path is the path where to find a trace. It is not recursive.
+ *
+ * This function is static since a trace should always be contained in a
+ * traceset.
+ *
+ * return the created trace or NULL on failure
+ */
+static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path)
+{
+  int id = bt_context_add_trace(lttv_traceset_get_context(ts),
+            path,
+            "ctf",
+            NULL,
+            NULL,
+            NULL);
+  if (id < 0) {
+    return NULL;
+  }
+  // Create the trace and save the trace handle id returned by babeltrace
+  LttvTrace *new_trace;
+
+  new_trace = g_new(LttvTrace, 1);
+  new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
+  new_trace->id = id;
+  new_trace->ref_count = 0;
+  return new_trace;
+}
+
+/*
+ * lttv_trace_create : Create and add a single trace to a traceset
+ *
+ * ts is the traceset in which will be contained the trace
+ *
+ * path is the path where to find a trace. It is not recursive.
+ *
+ * return a positive integer (>=0)on success or -1 on failure
+ */
+static int lttv_traceset_create_trace(LttvTraceset *ts, const char *path)
+{
+  LttvTrace *trace = lttv_trace_create(ts, path);
+  if (trace == NULL) {
+    return -1;
+  }
+  lttv_traceset_add(ts, trace);
+  return 0;
+}
 
 LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) 
 {
@@ -131,6 +184,8 @@ void lttv_traceset_destroy(LttvTraceset *s)
        for(i=0;i<s->traces->len;i++) {
                LttvTrace *trace = g_ptr_array_index(s->traces, i);
                lttv_trace_unref(trace);
+               // todo mdenis 2012-03-27: uncomment when babeltrace gets fixed
+               //bt_context_remove_trace(lttv_traceset_get_context(s), trace->id);
                if(lttv_trace_get_ref_number(trace) == 0)
                        lttv_trace_destroy(trace);
        }
@@ -158,6 +213,12 @@ void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
        g_ptr_array_add(s->traces, t);
 }
 
+int lttv_traceset_add_path(LttvTraceset *ts, const char *trace_path)
+{
+  // todo mdenis 2012-03-27: add trace recursively and update comment
+  int ret = lttv_traceset_create_trace(ts, trace_path);
+  return ret;
+}
 
 unsigned lttv_traceset_number(LttvTraceset *s) 
 {
@@ -178,6 +239,7 @@ void lttv_traceset_remove(LttvTraceset *s, unsigned i)
        g_assert(s->traces->len > i);
        t = (LttvTrace *)s->traces->pdata[i];
        t->ref_count--;
+       bt_context_remove_trace(lttv_traceset_get_context(s), t->id);
        g_ptr_array_remove_index(s->traces, i);
 }
 
@@ -196,14 +258,21 @@ LttvAttribute *lttv_trace_attribute(LttvTrace *t)
        return t->a;
 }
 
-
+#ifdef BABEL_CLEANUP
 LttTrace *lttv_trace(LttvTrace *t)
 {
        return t->t;
 }
+#endif
+
+gint lttv_trace_get_id(LttvTrace *t)
+{
+  return t->id;
+}
 
 guint lttv_trace_get_ref_number(LttvTrace * t)
 {
+       // todo mdenis: adapt to babeltrace
        return t->ref_count;
 }
 
index e9bbc2740f177f95f3f2f1a743a075114419570b..6bce443cf317e291bbc9bf8ed192b5d8921f3473 100644 (file)
@@ -37,7 +37,9 @@ LttvTraceset *lttv_traceset_new();
 
 char * lttv_traceset_name(LttvTraceset * s);
 
+#ifdef BABEL_CLEANUP
 LttvTrace *lttv_trace_new(LttTrace *t);
+#endif
 
 LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig);
 
@@ -54,6 +56,20 @@ void lttv_trace_destroy(LttvTrace *t);
 
 void lttv_traceset_add(LttvTraceset *s, LttvTrace *t);
 
+/*
+ * lttv_traceset_add_path : Add all traces recursively to a traceset
+ *
+ * ts is the traceset in which will be contained the traces
+ *
+ * path is a path to a trace(s). It cannot be NULL and it is not parse
+ * recursively.
+ * todo mdenis: implement algorithm to go through all folders recursively to
+ * find all traces in the path
+ *
+ * @return 0 on success, -1 on failure
+ */
+int lttv_traceset_add_path(LttvTraceset *ts, const char *path);
+
 unsigned lttv_traceset_number(LttvTraceset *s);
 
 LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i);
@@ -66,7 +82,9 @@ LttvAttribute *lttv_traceset_attribute(LttvTraceset *s);
 
 LttvAttribute *lttv_trace_attribute(LttvTrace *t);
 
+#ifdef BABEL_CLEANUP
 LttTrace *lttv_trace(LttvTrace *t);
+#endif
 
 guint lttv_trace_get_ref_number(LttvTrace * t);
 
index 6d6bfe0a70ff754c7dcc5c02a2434b29a53e2163..ae661d47ac2f8c7a74beffc171b3534ac8bc238a 100644 (file)
@@ -51,7 +51,7 @@ static LttvHooks
   *event_hook,
   *main_hooks;
 
-static char *a_trace;
+static char *trace_path;
 
 static gboolean a_stats;
 static gboolean a_live;
@@ -73,14 +73,10 @@ void lttv_trace_option(void *hook_data)
   }
   if(trace == NULL) g_critical("cannot open trace %s", a_trace);
   lttv_traceset_add(traceset, lttv_trace_new(trace));*/
-  if(bt_context_add_trace(lttv_traceset_get_context(traceset),
-                      a_trace,
-                      "ctf",
-                      NULL,
-                      NULL,
-                         NULL) < 0) {
-    printf("Cannot add trace %s", a_trace);
-    }
+
+  if(lttv_traceset_add_path(traceset, trace_path) < 0) {
+    printf("Cannot add trace %s", trace_path);
+  }
 }
 
 
@@ -113,10 +109,12 @@ static gboolean process_traceset(void *hook_data, void *call_data)
 
   lttv_context_init(tc, traceset);
 
+#ifdef BABEL_CLEANUP
   syncTraceset(tc);
 
   lttv_state_add_event_hooks(tss);
   if(a_stats) lttv_stats_add_event_hooks(tscs);
+#endif
 
   retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
     LTTV_POINTER, &value_expression);
@@ -165,10 +163,16 @@ static gboolean process_traceset(void *hook_data, void *call_data)
                                                          G_MAXULONG,
                                                          NULL);
          
-         updated_count = lttv_process_traceset_update(tc); 
+#ifdef BABEL_CLEANUP
+         updated_count = lttv_process_traceset_update(tc);
+#endif
                
          sleep(a_live_update_period);
-  } while(count != 0 || updated_count > 0);
+  } while(count != 0
+#ifdef BABEL_CLEANUP
+      || updated_count > 0
+#endif
+      );
 
 
   //lttv_traceset_context_remove_hooks(tc,
@@ -184,8 +188,10 @@ static gboolean process_traceset(void *hook_data, void *call_data)
   g_info("BatchAnalysis destroy context");
 
   lttv_filter_destroy(*(value_filter.v_pointer));
+#ifdef BABEL_CLEANUP
   lttv_state_remove_event_hooks(tss);
   if(a_stats) lttv_stats_remove_event_hooks(tscs);
+#endif
   lttv_context_fini(tc);
   if (a_stats)
     g_object_unref(tscs);
@@ -209,7 +215,7 @@ static void init()
   lttv_option_add("trace", 't', 
       "add a trace to the trace set to analyse", 
       "pathname of the directory containing the trace", 
-      LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
+      LTTV_OPT_STRING, &trace_path, lttv_trace_option, NULL);
 
   a_stats = FALSE;
   lttv_option_add("stats", 's', 
@@ -288,9 +294,11 @@ static void init()
 
 static void destroy()
 {
+#ifdef BABEL_CLEANUP
   guint i, nb;
 
   LttvTrace *trace;
+#endif
 
   g_info("Destroy batchAnalysis.c");
 
@@ -310,14 +318,14 @@ static void destroy()
   lttv_hooks_destroy(event_hook);
   lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
 
+#ifdef BABEL_CLEANUP
   nb = lttv_traceset_number(traceset);
   for(i = 0 ; i < nb ; i++) {
     trace = lttv_traceset_get(traceset, i);
     ltt_trace_close(lttv_trace(trace));
-    /* This will be done by lttv_traceset_destroy */
-    //lttv_trace_destroy(trace);
+    lttv_trace_destroy(trace);
   }
-
+#endif
   lttv_traceset_destroy(traceset); 
 }
 
This page took 0.0323830000000001 seconds and 4 git commands to generate.