#endif
#include <glib.h>
+#include <unistd.h>
#include <lttv/lttv.h>
#include <lttv/attribute.h>
#include <lttv/hook.h>
#include <lttv/stats.h>
#include <lttv/filter.h>
#include <ltt/trace.h>
+#include <lttv/sync/sync_chain_lttv.h>
+
+#include <babeltrace/context.h>
static LttvTraceset *traceset;
static char *a_trace;
static gboolean a_stats;
+static gboolean a_live;
+static int a_live_update_period;
+
+#define DEFAULT_LIVE_UPDATE_PERIOD 1
void lttv_trace_option(void *hook_data)
{
- LttTrace *trace;
-
- trace = ltt_trace_open(a_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);
+ } else {
+ 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);
+ }
}
LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
- LttvTracesetStats *tscs;
+ LttvTracesetStats *tscs = NULL;
LttvTracesetState *tss;
LttvTracesetContext *tc;
LttTime start, end;
+ gboolean retval;
g_info("BatchAnalysis begin process traceset");
g_info("BatchAnalysis initialize context");
lttv_context_init(tc, traceset);
- lttv_state_add_event_hooks(tc);
+
+ syncTraceset(tc);
+
+ lttv_state_add_event_hooks(tss);
if(a_stats) lttv_stats_add_event_hooks(tscs);
- g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
- LTTV_POINTER, &value_expression));
+ retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
+ LTTV_POINTER, &value_expression);
+ g_assert(retval);
+
+ retval= lttv_iattribute_find_by_path(attributes, "filter/lttv_filter",
+ LTTV_POINTER, &value_filter);
+ g_assert(retval);
- g_assert(lttv_iattribute_find_by_path(attributes, "filter/lttv_filter",
- LTTV_POINTER, &value_filter));
+ /* Repeat the search for the first element, the second search might have
+ * moved the first element (by creating the second element)
+ */
+ retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
+ LTTV_POINTER, &value_expression);
+ g_assert(retval);
*(value_filter.v_pointer) = lttv_filter_new();
//g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
end.tv_nsec = G_MAXULONG;
g_info("BatchAnalysis process traceset");
-
+
lttv_process_traceset_seek_time(tc, start);
- lttv_process_traceset_middle(tc,
- end,
- G_MAXULONG,
- NULL);
+ /* Read as long a we do not reach the end (0) */
+ unsigned int count;
+ unsigned int updated_count;
+ do {
+ count = lttv_process_traceset_middle(tc,
+ end,
+ G_MAXULONG,
+ NULL);
+
+ updated_count = lttv_process_traceset_update(tc);
+
+ sleep(a_live_update_period);
+ } while(count != 0 || updated_count > 0);
//lttv_traceset_context_remove_hooks(tc,
LttvAttributeValue value;
LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+ gboolean retval;
g_info("Init batchAnalysis.c");
"",
LTTV_OPT_NONE, &a_stats, NULL, NULL);
+ a_live = FALSE;
+ lttv_option_add("live", 0,
+ "define if the traceset is receiving live informations",
+ "",
+ LTTV_OPT_NONE, &a_live, NULL, NULL);
+
+ a_live_update_period = DEFAULT_LIVE_UPDATE_PERIOD;
+ lttv_option_add("live-period", 0,
+ "period to update a live trace",
+ "in seconds",
+ LTTV_OPT_INT,
+ &a_live_update_period,
+ NULL, NULL);
+
traceset = lttv_traceset_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));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = before_traceset;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = after_traceset;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = before_trace;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = after_trace;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = before_tracefile;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = after_tracefile;
//g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
// LTTV_POINTER, &value));
//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));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/event",
+ LTTV_POINTER, &value);
+ g_assert(retval);
*(value.v_pointer) = event_hook;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
- LTTV_POINTER, &value));
+ retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before",
+ LTTV_POINTER, &value);
+ g_assert(retval);
g_assert((main_hooks = *(value.v_pointer)) != NULL);
lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
}
lttv_option_remove("trace");
lttv_option_remove("stats");
+ lttv_option_remove("live");
+ lttv_option_remove("live-period");
lttv_hooks_destroy(before_traceset);
lttv_hooks_destroy(after_traceset);
LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
"Run through a trace calling all the registered hooks", \
- init, destroy, "state", "stats", "option","textFilter")
+ init, destroy, "state", "stats", "option","textFilter", "sync")