X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Ftracecontext.c;h=af39ffdcb57c6c2f51152c3ae618404e3444ed21;hb=21ff84a0d872ff069d4ec62d0a5bed21bcfeeac5;hp=56a483c2a37299228af6744c24cff29144039e2b;hpb=aa78b7113d761d1acbe3f3dae6a43b4c6cdfbd31;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/tracecontext.c b/ltt/branches/poly/lttv/lttv/tracecontext.c index 56a483c2..af39ffdc 100644 --- a/ltt/branches/poly/lttv/lttv/tracecontext.c +++ b/ltt/branches/poly/lttv/lttv/tracecontext.c @@ -16,7 +16,7 @@ * MA 02111-1307, USA. */ - +#include #include #include #include @@ -26,32 +26,36 @@ -gint compare_tracefile(gconstpointer a, gconstpointer b) +static gint compare_tracefile(gconstpointer a, gconstpointer b) { - gint comparison; - - LttvTracefileContext *trace_a = (LttvTracefileContext *)a; - - LttvTracefileContext *trace_b = (LttvTracefileContext *)b; - - if(trace_a == trace_b) return 0; - comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp); - if(comparison != 0) return comparison; - if(trace_a->index < trace_b->index) return -1; - else if(trace_a->index > trace_b->index) return 1; - if(trace_a->t_context->index < trace_b->t_context->index) return -1; - else if(trace_a->t_context->index > trace_b->t_context->index) return 1; - g_assert(FALSE); + gint comparison = 0; + + const LttvTracefileContext *trace_a = (const LttvTracefileContext *)a; + const LttvTracefileContext *trace_b = (const LttvTracefileContext *)b; + + if(likely(trace_a != trace_b)) { + comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp); + if(unlikely(comparison == 0)) { + if(trace_a->index < trace_b->index) comparison = -1; + else if(trace_a->index > trace_b->index) comparison = 1; + else if(trace_a->t_context->index < trace_b->t_context->index) + comparison = -1; + else if(trace_a->t_context->index > trace_b->t_context->index) + comparison = 1; + } + } + return comparison; } struct _LttvTraceContextPosition { - LttEventPosition **tf_pos; /* Position in each trace */ + LttEventPosition **tf_pos; /* Position in each tracefile */ guint nb_tracefile; /* Number of tracefiles (check) */ }; struct _LttvTracesetContextPosition { - LttvTraceContextPosition *t_pos; /* Position in each trace */ + LttvTraceContextPosition *t_pos; /* Position in each trace */ guint nb_trace; /* Number of traces (check) */ + LttTime timestamp; /* Current time at the saved position */ }; void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts) @@ -183,15 +187,16 @@ init(LttvTracesetContext *self, LttvTraceset *ts) 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); } } + self->pqueue = g_tree_new(compare_tracefile); lttv_process_traceset_seek_time(self, null_time); lttv_traceset_context_compute_time_span(self, &self->time_span); - self->pqueue = g_tree_new(compare_tracefile); } @@ -222,6 +227,7 @@ void fini(LttvTracesetContext *self) for(j = 0 ; j < nb_tracefile ; j++) { tfc = tc->tracefiles[j]; + ltt_event_destroy(tfc->e); lttv_hooks_destroy(tfc->event); lttv_hooks_by_id_destroy(tfc->event_by_id); g_object_unref(tfc->a); @@ -354,9 +360,8 @@ void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, lttv_hooks_add_list(self->event, event); if(event_by_id != NULL) for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) { - hook = lttv_hooks_by_id_get(self->event_by_id, i); - if(hook != NULL) - lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, i)); + hook = lttv_hooks_by_id_find(self->event_by_id, i); + lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, i)); } } @@ -374,8 +379,9 @@ void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, lttv_hooks_remove_list(self->event, event); if(event_by_id != NULL) for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) { - hook = lttv_hooks_by_id_find(self->event_by_id, i); - lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, i)); + hook = lttv_hooks_by_id_get(self->event_by_id, i); + if(hook != NULL) + lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, i)); } lttv_hooks_call(after_tracefile, self); @@ -462,7 +468,8 @@ lttv_traceset_context_get_type(void) NULL, /* class_data */ sizeof (LttvTracesetContext), 0, /* n_preallocs */ - (GInstanceInitFunc) traceset_context_instance_init /* instance_init */ + (GInstanceInitFunc) traceset_context_instance_init, /* instance_init */ + NULL /* Value handling */ }; type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", @@ -510,7 +517,8 @@ lttv_trace_context_get_type(void) NULL, /* class_data */ sizeof (LttvTraceContext), 0, /* n_preallocs */ - (GInstanceInitFunc) trace_context_instance_init /* instance_init */ + (GInstanceInitFunc) trace_context_instance_init, /* instance_init */ + NULL /* Value handling */ }; type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", @@ -558,7 +566,8 @@ lttv_tracefile_context_get_type(void) NULL, /* class_data */ sizeof (LttvTracefileContext), 0, /* n_preallocs */ - (GInstanceInitFunc) tracefile_context_instance_init /* instance_init */ + (GInstanceInitFunc) tracefile_context_instance_init, /* instance_init */ + NULL /* Value handling */ }; type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", @@ -569,12 +578,50 @@ lttv_tracefile_context_get_type(void) -gboolean get_first(gpointer key, gpointer value, gpointer user_data) { +static gboolean get_first(gpointer key, gpointer value, gpointer user_data) { *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; return TRUE; } +/* Put all the tracefiles at the tracefile context position */ +void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *self) +{ + guint iter_trace, nb_trace; + + LttvTraceContext *tc; + + nb_trace = lttv_traceset_number(self->ts); + + for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) { + tc = self->traces[iter_trace]; + { + /* each trace */ + guint iter_tf, nb_tracefile; + + LttvTracefileContext *tfc; + + nb_tracefile = ltt_trace_control_tracefile_number(tc->t) + + ltt_trace_per_cpu_tracefile_number(tc->t); + + for(iter_tf = 0 ; iter_tf < nb_tracefile ; iter_tf++) { + tfc = tc->tracefiles[iter_tf]; + { + /* each tracefile */ + //ltt_tracefile_copy(tfc->tf_sync_data, tfc->tf); + LttEventPosition *ep = ltt_event_position_new(); + + ltt_event_position(tfc->e, ep); + + ltt_tracefile_seek_position(tfc->tf, ep); + g_free(ep); + } + } + } + } +} + + void lttv_process_traceset_begin(LttvTracesetContext *self, LttvHooks *before_traceset, @@ -607,8 +654,6 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self, LttvTracefileContext *tfc; - LttEvent *event; - unsigned count = 0; gboolean last_ret = FALSE; /* return value of the last hook list called */ @@ -622,7 +667,7 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self, tfc = NULL; g_tree_foreach(pqueue, get_first, &tfc); /* End of traceset : tfc is NULL */ - if(tfc == NULL) + if(unlikely(tfc == NULL)) { return count; } @@ -635,11 +680,11 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self, * break the loop. */ - if(last_ret == TRUE || - count >= nb_events || - (end_position!=NULL)?FALSE:lttv_traceset_context_ctx_pos_compare(self, - end_position) >= 0 || - ltt_time_compare(tfc->timestamp, end) >= 0) + if(unlikely(last_ret == TRUE || + count >= nb_events || + (end_position!=NULL&<tv_traceset_context_ctx_pos_compare(self, + end_position) == 0)|| + ltt_time_compare(end, tfc->timestamp) <= 0)) { return count; } @@ -655,10 +700,8 @@ guint lttv_process_traceset_middle(LttvTracesetContext *self, last_ret = lttv_hooks_call_merge(tfc->event, tfc, lttv_hooks_by_id_get(tfc->event_by_id, id), tfc); - event = ltt_tracefile_read(tfc->tf); - if(event != NULL) { - tfc->e = event; - tfc->timestamp = ltt_event_time(event); + if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) { + tfc->timestamp = ltt_event_time(tfc->e); g_tree_insert(pqueue, tfc, tfc); } } @@ -688,8 +731,6 @@ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start) LttvTracefileContext *tfc; - LttEvent *event; - GTree *pqueue = self->ts_context->pqueue; nb_tracefile = ltt_trace_control_tracefile_number(self->t) + @@ -699,10 +740,8 @@ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start) tfc = self->tracefiles[i]; ltt_tracefile_seek_time(tfc->tf, start); g_tree_remove(pqueue, tfc); - event = ltt_tracefile_read(tfc->tf); - tfc->e = event; - if(event != NULL) { - tfc->timestamp = ltt_event_time(event); + if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) { + tfc->timestamp = ltt_event_time(tfc->e); g_tree_insert(pqueue, tfc, tfc); } } @@ -715,8 +754,6 @@ void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start) LttvTraceContext *tc; - LttvTracefileContext *tfc; - nb_trace = lttv_traceset_number(self->ts); for(i = 0 ; i < nb_trace ; i++) { tc = self->traces[i]; @@ -730,20 +767,16 @@ gboolean lttv_process_tracefile_seek_position(LttvTracefileContext *self, { LttvTracefileContext *tfc = self; - LttEvent *event; - GTree *pqueue = self->t_context->ts_context->pqueue; ltt_tracefile_seek_position(tfc->tf, pos); g_tree_remove(pqueue, tfc); - event = ltt_tracefile_read(tfc->tf); - tfc->e = event; - if(event != NULL) { - tfc->timestamp = ltt_event_time(event); + if(likely(ltt_tracefile_read(tfc->tf, tfc->e) != NULL)) { + tfc->timestamp = ltt_event_time(tfc->e); g_tree_insert(pqueue, tfc, tfc); } - + return TRUE; } gboolean lttv_process_trace_seek_position(LttvTraceContext *self, @@ -753,8 +786,6 @@ gboolean lttv_process_trace_seek_position(LttvTraceContext *self, LttvTracefileContext *tfc; - LttEvent *event; - nb_tracefile = ltt_trace_control_tracefile_number(self->t) + ltt_trace_per_cpu_tracefile_number(self->t); @@ -779,8 +810,6 @@ gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, LttvTraceContext *tc; - LttvTracefileContext *tfc; - nb_trace = lttv_traceset_number(self->ts); if(nb_trace != pos->nb_trace) @@ -830,15 +859,13 @@ lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, LttEventType *et; - guint nb, pos, i; - - char *name; + guint nb, pos; nb = ltt_trace_facility_find(t, facility, &pos); - if(nb < 1) g_error("No %s facility", facility); + if(unlikely(nb < 1)) g_error("No %s facility", facility); f = ltt_trace_facility_get(t, pos); et = ltt_facility_eventtype_get_by_name(f, event_type); - if(et == NULL) g_error("Event %s does not exist", event_type); + if(unlikely(et == NULL)) g_error("Event %s does not exist", event_type); th->h = h; th->id = ltt_eventtype_id(et); @@ -848,6 +875,12 @@ lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, } +LttvTracesetContextPosition *lttv_traceset_context_position_new() +{ + return g_new(LttvTracesetContextPosition,1); +} + + void lttv_traceset_context_position_save(const LttvTracesetContext *self, LttvTracesetContextPosition *pos) { @@ -860,6 +893,8 @@ void lttv_traceset_context_position_save(const LttvTracesetContext *self, LttEvent *event; + LttTime timestamp = self->time_span.end_time; + pos->nb_trace = nb_trace = lttv_traceset_number(self->ts); pos->t_pos = g_new(LttvTraceContextPosition, nb_trace); @@ -871,19 +906,26 @@ void lttv_traceset_context_position_save(const LttvTracesetContext *self, pos->t_pos[iter_trace].tf_pos = g_new(LttEventPosition*, nb_tracefile); for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) { - pos->t_pos[iter_trace].tf_pos[iter_tracefile] - = ltt_event_position_new(); tfc = tc->tracefiles[iter_tracefile]; event = tfc->e; - ltt_event_position(event, - pos->t_pos[iter_trace].tf_pos[iter_tracefile]); + if(event!=NULL) { + pos->t_pos[iter_trace].tf_pos[iter_tracefile] + = ltt_event_position_new(); + ltt_event_position(event, + pos->t_pos[iter_trace].tf_pos[iter_tracefile]); + } else { + pos->t_pos[iter_trace].tf_pos[iter_tracefile] = NULL; + } + if(ltt_time_compare(tfc->timestamp, timestamp) < 0) + timestamp = tfc->timestamp; } } + pos->timestamp = timestamp; } void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos) { - guint nb_trace, nb_tracefile; + guint nb_trace; guint iter_trace, iter_tracefile; nb_trace = pos->nb_trace; @@ -892,8 +934,8 @@ void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos) for(iter_tracefile = 0; iter_tracefile < pos->t_pos[iter_trace].nb_tracefile; iter_tracefile++) { - - g_free(pos->t_pos[iter_trace].tf_pos[iter_tracefile]); + if(pos->t_pos[iter_trace].tf_pos[iter_tracefile] != NULL) + g_free(pos->t_pos[iter_trace].tf_pos[iter_tracefile]); } g_free(pos->t_pos[iter_trace].tf_pos); } @@ -901,6 +943,35 @@ void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos) } +void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest, + const LttvTracesetContextPosition *src) +{ + guint nb_trace, nb_tracefile; + guint iter_trace, iter_tracefile; + + nb_trace = dest->nb_trace = src->nb_trace; + dest->t_pos = g_new(LttvTraceContextPosition, nb_trace); + + for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) { + + nb_tracefile = dest->t_pos[iter_trace].nb_tracefile = + src->t_pos[iter_trace].nb_tracefile; + + for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) { + dest->t_pos[iter_trace].tf_pos[iter_tracefile] = + ltt_event_position_new(); + if(src->t_pos[iter_trace].tf_pos[iter_tracefile] != NULL) + ltt_event_position_copy( + dest->t_pos[iter_trace].tf_pos[iter_tracefile], + src->t_pos[iter_trace].tf_pos[iter_tracefile]); + else + dest->t_pos[iter_trace].tf_pos[iter_tracefile] = NULL; + } + } + + dest->timestamp = src->timestamp; +} + gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, const LttvTracesetContextPosition *pos) { @@ -916,7 +987,7 @@ gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, nb_trace = lttv_traceset_number(self->ts); - if(pos->nb_trace != nb_trace) + if(unlikely(pos->nb_trace != nb_trace)) g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match."); for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) { @@ -924,17 +995,15 @@ gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, nb_tracefile = ltt_trace_control_tracefile_number(tc->t) + ltt_trace_per_cpu_tracefile_number(tc->t); - if(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile) + if(unlikely(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile)) g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match."); for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) { tfc = tc->tracefiles[iter_tracefile]; event = tfc->e; - if( - ret = - ltt_event_event_position_compare(event, - pos->t_pos[iter_trace].tf_pos[iter_tracefile]) - != 0) + ret = ltt_event_event_position_compare(event, + pos->t_pos[iter_trace].tf_pos[iter_tracefile]); + if(ret != 0) return ret; } } @@ -952,21 +1021,20 @@ gint lttv_traceset_context_pos_pos_compare( gint ret; nb_trace = pos1->nb_trace; - if(nb_trace != pos2->nb_trace) + if(unlikely(nb_trace != pos2->nb_trace)) g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match."); for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) { nb_tracefile = pos1->t_pos[iter_trace].nb_tracefile; - if(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile) + if(unlikely(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile)) g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match."); for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) { - if(ret = - ltt_event_position_compare( + ret = ltt_event_position_compare( pos1->t_pos[iter_trace].tf_pos[iter_tracefile], - pos2->t_pos[iter_trace].tf_pos[iter_tracefile]) - != 0) + pos2->t_pos[iter_trace].tf_pos[iter_tracefile]); + if(ret != 0) return ret; } } @@ -974,3 +1042,19 @@ gint lttv_traceset_context_pos_pos_compare( } +LttTime lttv_traceset_context_position_get_time( + const LttvTracesetContextPosition *pos) +{ + return pos->timestamp; +} + + +LttvTracefileContext *lttv_traceset_context_get_current_tfc(LttvTracesetContext *self) +{ + GTree *pqueue = self->pqueue; + LttvTracefileContext *tfc = NULL; + + g_tree_foreach(pqueue, get_first, &tfc); + + return tfc; +}