Basic babeltrace integration
authorYannick Brosseau <yannick.brosseau@gmail.com>
Fri, 9 Mar 2012 23:49:02 +0000 (18:49 -0500)
committerYannick Brosseau <yannick.brosseau@gmail.com>
Mon, 11 Jun 2012 21:34:33 +0000 (17:34 -0400)
Open a trace, read it, sent the event to textDump module
Display event name and timestamp

Signed-off-by: Yannick Brosseau <yannick.brosseau@gmail.com>
lttv/lttv/tracecontext.c
lttv/lttv/tracecontext.h
lttv/lttv/traceset.c
lttv/lttv/traceset.h
lttv/modules/text/batchAnalysis.c
lttv/modules/text/textDump.c

index 1c71ac214a6644bc4eb74ae1298b911dc9f8dbd4..0f08381a9864576f1f3218522760f83bb0e01c60 100644 (file)
 #include <errno.h>
 #include <ltt/time.h>
 
+#include <babeltrace/context.h>
+#include <babeltrace/iterator.h>
+
+#include <babeltrace/ctf/events.h>
+#include <babeltrace/ctf/iterator.h>
+
 gint compare_tracefile(gconstpointer a, gconstpointer b)
 {
        gint comparison = 0;
@@ -180,12 +186,22 @@ init(LttvTracesetContext *self, LttvTraceset *ts)
        GData **tracefiles_groups;
 
        struct compute_tracefile_group_args args;
+       
+       struct bt_iter_pos begin_pos;
 
        nb_trace = lttv_traceset_number(ts);
        self->ts = ts;
        self->traces = g_new(LttvTraceContext *, nb_trace);
        self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
        self->ts_a = lttv_traceset_attribute(ts);
+       
+       begin_pos.type = BT_SEEK_BEGIN;
+
+       self->iter = bt_ctf_iter_create(lttv_traceset_get_context(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;
@@ -209,34 +225,9 @@ init(LttvTracesetContext *self, LttvTraceset *ts)
                                        &args);
                }
 
-#if 0
-               nb_control = ltt_trace_control_tracefile_number(tc->t);
-               nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t);
-               nb_tracefile = nb_control + nb_per_cpu;
-               tc->tracefiles = g_new(LttvTracefileContext *, nb_tracefile);
-
-               for(j = 0 ; j < nb_tracefile ; j++) {
-                       tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self);
-                       tc->tracefiles[j] = tfc;
-                       tfc->index = j;
-
-                       if(j < nb_control) {
-                               tfc->control = TRUE;
-                               tfc->tf = ltt_trace_control_tracefile_get(tc->t, j);
-                       } else {
-                               tfc->control = FALSE;
-                               tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control);
-                       }
-
-                       tfc->t_context = tc;
-                       tfc->e = ltt_event_new();
-                       tfc->event = lttv_hooks_new();
-                       tfc->event_by_id = lttv_hooks_by_id_new();
-                       tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
-               }
-#endif //0
 
        }
+#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);
@@ -296,6 +287,8 @@ void lttv_traceset_context_add_hooks(LttvTracesetContext *self,
        LttvTraceContext *tc;
 
        lttv_hooks_call(before_traceset, self);
+       
+       lttv_hooks_add_list(self->event_hooks, event);
 
        nb_trace = lttv_traceset_number(ts);
 
@@ -682,6 +675,40 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
                gulong nb_events,
                const LttvTracesetContextPosition *end_position)
 {
+       
+       unsigned count = 0;
+               
+       struct bt_ctf_event *event;
+       
+       while(TRUE) {
+
+               if((count >= nb_events) && (nb_events != G_MAXULONG)) {
+                       break;
+               }
+
+               if((event = bt_ctf_iter_read_event(self->iter)) != NULL) {
+                       
+                       count++;
+
+                       /* TODO ybrosseau: encapsulate the event into something */
+                       lttv_hooks_call(self->event_hooks, event);
+
+                       if(bt_iter_next(bt_ctf_get_iter(self->iter)) < 0) {
+                               printf("ERROR NEXT\n");
+                               break;
+                       }
+               } else {
+                       /* READ FAILED */
+                       
+                       break;
+               
+               }
+       }
+       
+
+
+       return count;
+#ifdef BABEL_CLEANUP
        GTree *pqueue = self->pqueue;
 
        LttvTracefileContext *tfc;
@@ -814,6 +841,8 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self,
        } else {
                return count;
        }
+
+#endif /* BABEL_CLEANUP */
 }
 
 
@@ -842,6 +871,9 @@ 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;
@@ -874,6 +906,7 @@ 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
 }
 
 /****************************************************************************
@@ -954,9 +987,25 @@ guint lttv_process_traceset_update(LttvTracesetContext *self)
 }
 
 void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start)
-{
+{      
+#ifdef WAIT_FOR_BABELTRACE_FIX_SEEK_ZERO
+       struct bt_iter_pos seekpos;
+       int ret;
+       seekpos.type = BT_SEEK_TIME;
+       seekpos.u.seek_time = ltt_time_to_uint64(start);
+       ret = bt_iter_set_pos(bt_ctf_get_iter(self->iter), &seekpos);
+       if(ret < 0) {
+               printf("Seek by time error: %s,\n",strerror(-ret));
+       }
+#else
+#warning Seek time disabled because of babeltrace bugs
+#endif
+       
+#ifdef BABEL_CLEANUP
        guint i, nb_trace;
 
+
+
        LttvTraceContext *tc;
 
        //g_tree_destroy(self->pqueue);
@@ -967,6 +1016,7 @@ void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start)
                tc = self->traces[i];
                lttv_process_trace_seek_time(tc, start);
        }
+#endif
 }
 
 
index e509811701914f7ebea79d73b6819c704bdba399..785f7021984ef081403ac29bcc27569a97f10b1b 100644 (file)
@@ -100,6 +100,9 @@ struct _LttvTracesetContext {
        LttvAttribute *ts_a;
        TimeInterval time_span;
        GTree *pqueue;
+       struct bt_ctf_iter *iter;
+       /* TODO ybrosseau: Added for babeltrace proto */
+       LttvHooks *event_hooks;
 
        LttvTracesetContextPosition *sync_position;   /* position at which to sync the
                                                         trace context */
index 0aba1a10d310d3a9a21ef994328af6fa137622dd..32553b5e475be7f1173d033cdcef11d867993c2b 100644 (file)
@@ -140,6 +140,11 @@ void lttv_traceset_destroy(LttvTraceset *s)
        g_free(s);
 }
 
+struct bt_context *lttv_traceset_get_context(LttvTraceset *s)
+{
+       return s->context;
+}
+
 void lttv_trace_destroy(LttvTrace *t) 
 {
        g_object_unref(t->a);
index 7ef85be5c337a67bb195d59660447101b6d6211a..e9bbc2740f177f95f3f2f1a743a075114419570b 100644 (file)
@@ -29,6 +29,8 @@ typedef struct _LttvTraceset LttvTraceset;
 
 typedef struct _LttvTrace LttvTrace;
 
+struct bt_context;
+
 /* Tracesets may be added to, removed from and their content listed. */
 
 LttvTraceset *lttv_traceset_new();
@@ -41,6 +43,9 @@ LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig);
 
 LttvTraceset *lttv_traceset_load(const gchar *filename);
 
+struct bt_context *lttv_traceset_get_context(LttvTraceset *s);
+
+
 gint lttv_traceset_save(LttvTraceset *s);
 
 void lttv_traceset_destroy(LttvTraceset *s);
index d06f9c85a3e8d495cf24316edfb45793d224c962..6d6bfe0a70ff754c7dcc5c02a2434b29a53e2163 100644 (file)
@@ -37,6 +37,8 @@
 #include <ltt/trace.h>
 #include <lttv/sync/sync_chain_lttv.h>
 
+#include <babeltrace/context.h>
+
 static LttvTraceset *traceset;
 
 static LttvHooks
@@ -59,15 +61,26 @@ static int a_live_update_period;
 
 void lttv_trace_option(void *hook_data)
 { 
-  LttTrace *trace;
-  
+  //LttTrace *trace;
+  //trace_collection *trace;  
+  //format *fmt = bt_lookup_format(g_quark_from_static_string("ctf"));
+  /*
   if(a_live) {
-    trace = ltt_trace_open_live(a_trace);
+    //trace = ltt_trace_open_live(a_trace);
   } else {
-    trace = ltt_trace_open(a_trace);
+    bt_create_context();
+    //trace = bt_add_trace(a_trace,"ctf");
   }
   if(trace == NULL) g_critical("cannot open trace %s", a_trace);
-  lttv_traceset_add(traceset, lttv_trace_new(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);
+    }
 }
 
 
@@ -141,7 +154,7 @@ static gboolean process_traceset(void *hook_data, void *call_data)
   end.tv_nsec = G_MAXULONG;
 
   g_info("BatchAnalysis process traceset");
-
   lttv_process_traceset_seek_time(tc, start);
   /* Read as long a we do not reach the end (0) */
   unsigned int count;
index ddee070b119e78bcfc40b29610152b483aa22988..004384a8885321563bed9153a25e540f03618bae 100644 (file)
@@ -40,6 +40,8 @@
 #include <stdio.h>
 #include <inttypes.h>
 
+#include <babeltrace/ctf/events.h>
+
 static gboolean
   a_noevent,
   a_no_field_names,
@@ -309,6 +311,8 @@ static int write_event_content(void *hook_data, void *call_data)
 
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
   
+  struct bt_ctf_event *event = (struct bt_ctf_event *)call_data;
+#ifdef BABEL_CLEANUP  
   LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
@@ -340,17 +344,25 @@ static int write_event_content(void *hook_data, void *call_data)
     if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
                                tfc->t_context->t,tfc,NULL,NULL))
       return FALSE;
-  
+#endif  
+#ifdef BABEL_CLEANUP
   lttv_event_to_string(e, a_string, TRUE, !a_no_field_names, tfs);
-
+#endif
+  g_string_set_size(a_string,0);
+  g_string_append_printf(a_string, " %s %llu", 
+                        bt_ctf_event_name(event),
+                        bt_ctf_get_timestamp_raw(event));
+#ifdef BABEL_CLEANUP
   if(a_state) {
     g_string_append_printf(a_string, " %s ",
         g_quark_to_string(process->state->s));
   }
+#endif
 
   g_string_append_printf(a_string,"\n");
 
   fputs(a_string->str, a_file);
+
   return FALSE;
 }
 
This page took 0.028376 seconds and 4 git commands to generate.