#include <ltt/trace.h>
#include <lttv/filter.h>
#include <errno.h>
+#include <ltt/time.h>
+#include <lttv/event.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)
{
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;
for(i=0; i<numTraces;i++){
tc = self->traces[i];
+
trace = tc->t;
ltt_trace_time_span_get(trace, &s, &e);
time_span->end_time = e;
}
}
+#endif
}
static void init_tracefile_context(LttTracefile *tracefile,
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();
for(i = 0 ; i < nb_trace ; i++) {
tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self);
self->traces[i] = tc;
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;
(GDataForeachFunc)compute_tracefile_group,
&args);
}
+#endif
-#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
}
self->sync_position = lttv_traceset_context_position_new(self);
LttvTraceContext *tc;
lttv_hooks_call(before_traceset, self);
+
+ lttv_hooks_add_list(self->event_hooks, event);
nb_trace = lttv_traceset_number(ts);
gulong nb_events,
const LttvTracesetContextPosition *end_position)
{
+
+ unsigned count = 0;
+
+ struct bt_ctf_event *bt_event;
+
+ LttvEvent event;
+ /* TODO ybrosseau 2012-03-16: Put in really in the traceset */
+ LttvTraceState state;
+
+ while(TRUE) {
+
+ if((count >= nb_events) && (nb_events != G_MAXULONG)) {
+ break;
+ }
+
+ if((bt_event = bt_ctf_iter_read_event(self->iter)) != NULL) {
+
+ count++;
+
+ event.bt_event = bt_event;
+ event.state = &state;
+
+ 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;
unsigned count = 0;
+ gboolean is_live = FALSE; /* set this flag if we detect a live trace */
+
guint read_ret;
//enum read_state last_read_state = LAST_NONE;
/* End of traceset : tfc is NULL */
if(unlikely(tfc == NULL))
{
- return count;
+ break;
}
/* Have we reached :
* then the read is finished. We leave the queue in the same state and
* break the loop.
*/
-
+ if(tfc->tf->trace->is_live && ltt_time_compare(tfc->timestamp, tfc->tf->trace->live_safe_timestamp) >= 0) {
+
+ break;
+ }
if(unlikely(last_ret == TRUE
|| ((count >= nb_events) && (nb_events != G_MAXULONG))
|| (end_position!=NULL&<tv_traceset_context_ctx_pos_compare(self,
end_position) == 0)
|| ltt_time_compare(end, tfc->timestamp) <= 0))
{
- return count;
+ break;
}
/* Get the tracefile with an event for the smallest time found. If two
if(unlikely(last_ret == 2)) {
/* This is a case where we want to stay at this position and stop read. */
g_tree_insert(pqueue, tfc, tfc);
- return count - 1;
+ count--;
+ break;
}
#endif //0
read_ret = ltt_tracefile_read(tfc->tf);
if(likely(!read_ret)) {
//g_debug("An event is ready");
tfc->timestamp = ltt_event_time(e);
+
+
g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0);
g_tree_insert(pqueue, tfc, tfc);
+ if(tfc->tf->trace->is_live && ltt_time_compare(tfc->timestamp, tfc->tf->trace->live_safe_timestamp) >= 0)
+ {
+ is_live |= TRUE;
+ break;
+ }
#ifdef DEBUG
test_time.tv_sec = 0;
test_time.tv_nsec = 0;
g_error("Error happened in lttv_process_traceset_middle");
}
}
+
+ if (unlikely((count == 0) && is_live)) {
+ return -1;
+ } else {
+ return count;
+ }
+
+#endif /* BABEL_CLEANUP */
}
#endif //DEBUG
}
+/****************************************************************************
+ * lttv_process_trace_update
+ *
+ * process the changes that occur in the trace. Use a regular file polling to
+ * monitor the tracefile.
+ *
+ * Return the number of tracefile updated
+ ***************************************************************************/
+guint lttv_process_trace_update(LttvTraceContext *self)
+{
+ guint i;
+ guint nb_tracefile = 0;
-void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start)
+ LttTracefile *tf = 0;
+ LttvTracefileContext **tfc;
+
+ /* Skip non live traces */
+ if(self->t->is_live) {
+
+ nb_tracefile = ltt_trace_update(self->t);
+
+ /* Recreate the pqueue following an update*/
+ GTree *pqueue = self->ts_context->pqueue;
+
+ for(i = 0 ; i < self->tracefiles->len ; i++) {
+ tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i);
+ tf = (*tfc)->tf;
+ if(g_tree_remove(pqueue, *tfc) == FALSE) {
+ if(tf->buf_index != NULL) {
+
+ if(ltt_tracefile_read(tf) == 0) {
+
+ (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf));
+ g_tree_insert(pqueue, (*tfc), (*tfc));
+
+ }
+ }
+ } else {
+ g_tree_insert(pqueue, (*tfc), (*tfc));
+
+ }
+
+
+ }
+ //Update self time span
+ self->time_span.end_time = LTT_TIME_MAX(self->t->live_safe_timestamp,
+ self->time_span.end_time);
+ //Update self tscontext time span
+ self->ts_context->time_span.end_time = LTT_TIME_MAX(self->time_span.end_time,
+ self->ts_context->time_span.end_time);
+ }
+ return nb_tracefile;
+
+}
+
+/****************************************************************************
+ * lttv_process_traceset_update
+ *
+ * process the changes that occur in the traceset.
+ *
+ * Return the number of file presently monitor(open for writting). If 0, the
+ * current traceset probably received all the data.
+ ***************************************************************************/
+guint lttv_process_traceset_update(LttvTracesetContext *self)
{
+ guint i;
+ guint nb_trace;
+ guint open_counter = 0;
+
+ nb_trace = lttv_traceset_number(self->ts);
+
+ for(i = 0 ; i < nb_trace ; i++) {
+ open_counter += lttv_process_trace_update(self->traces[i]);
+ }
+ return open_counter;
+}
+
+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);
tc = self->traces[i];
lttv_process_trace_seek_time(tc, start);
}
+#endif
}