From 8284135eaaf40b6d7897c63a59a7df0b7f0cd2c7 Mon Sep 17 00:00:00 2001 From: Yannick Brosseau Date: Fri, 24 May 2013 13:24:16 -0400 Subject: [PATCH] Enable support for opening multiple trace Correctly display the trace name in the events view. Only the part different for all the traces is displayed Signed-off-by: Yannick Brosseau --- lttv/lttv/traceset.c | 52 +++++++++++++++++++ lttv/lttv/traceset.h | 9 ++++ lttv/modules/gui/controlflow/eventhooks.c | 22 ++++---- lttv/modules/gui/detailedevents/events.c | 2 +- .../gui/lttvwindow/lttvwindow/callbacks.c | 8 ++- lttv/modules/gui/resourceview/eventhooks.c | 17 +++--- 6 files changed, 88 insertions(+), 22 deletions(-) diff --git a/lttv/lttv/traceset.c b/lttv/lttv/traceset.c index 9c24f339..aafa3714 100644 --- a/lttv/lttv/traceset.c +++ b/lttv/lttv/traceset.c @@ -54,6 +54,7 @@ LttvTraceset *lttv_traceset_new(void) ts = g_new(LttvTraceset, 1); ts->filename = NULL; + ts->common_path = NULL; ts->traces = g_ptr_array_new(); ts->context = bt_context_create(); ts->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); @@ -153,6 +154,29 @@ static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path) g_ptr_array_set_size(ts->state_trace_handle_index,id+1); g_ptr_array_index(ts->state_trace_handle_index,id) = new_trace->state; + /* Find common path */ + if (ts->common_path == NULL) { + ts->common_path = strdup(path); + } else { + /* TODO ybrosseau 2013-05-24: consider put that in a function */ + int i,j; + for (i = 0; + ts->common_path != '\0'; + i++) { + if (path[i] != ts->common_path[i]) { + /* The common path has changed, redo the other traces */ + for(j = 0; j < ts->traces->len; j++) { + LttvTrace *t = g_ptr_array_index(ts->traces, j); + strncpy(t->short_name, t->full_path+i, TRACE_NAME_SIZE); + } + + break; + } + } + strncpy(new_trace->short_name, path+i, TRACE_NAME_SIZE); + } + new_trace->full_path = strdup(path); + return new_trace; } @@ -183,6 +207,7 @@ LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) s = g_new(LttvTraceset, 1); s->filename = NULL; + s->common_path = strdup(s_orig->common_path); s->traces = g_ptr_array_new(); s->state_trace_handle_index = g_ptr_array_new(); for(i=0;itraces->len;i++) @@ -242,6 +267,7 @@ void lttv_traceset_destroy(LttvTraceset *s) if(lttv_trace_get_ref_number(trace) == 0) lttv_trace_destroy(trace); } + free(s->common_path); g_ptr_array_free(s->traces, TRUE); bt_context_put(s->context); g_object_unref(s->a); @@ -265,6 +291,7 @@ LttvHooks *lttv_traceset_get_hooks(LttvTraceset *s) void lttv_trace_destroy(LttvTrace *t) { + free(t->full_path); g_object_unref(t->a); g_free(t); } @@ -275,6 +302,31 @@ void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) g_ptr_array_add(s->traces, t); } +int lttv_traceset_get_trace_index_from_event(LttvEvent *event) +{ + LttvTraceset *ts = event->state->trace->traceset; + + return lttv_traceset_get_trace_index_from_handle_id(ts, bt_ctf_event_get_handle_id(event->bt_event)); +} + +int lttv_traceset_get_trace_index_from_handle_id(LttvTraceset *ts, int handle_id) +{ + int i; + + /* TODO ybrosseau 2013-05-22: use a map to speedup the lookup */ + + for(i = 0; i < ts->traces->len; i++) { + LttvTrace *t = g_ptr_array_index(ts->traces, i); + if (t && t->id == handle_id) { + return i; + } + } + + /* Handle id not found */ + return -1; + +} + int lttv_traceset_add_path(LttvTraceset *ts, char *trace_path) { int ret = -1; diff --git a/lttv/lttv/traceset.h b/lttv/lttv/traceset.h index 5d57ca44..4f326fd8 100644 --- a/lttv/lttv/traceset.h +++ b/lttv/lttv/traceset.h @@ -45,8 +45,11 @@ struct _LttvTraceset { GPtrArray *state_trace_handle_index; gboolean has_precomputed_states; TimeInterval time_span; + char *common_path; }; +#define TRACE_NAME_SIZE 100 + struct _LttvTrace { // Trace id for babeltrace LttvTraceset *traceset; /* container traceset */ @@ -54,6 +57,8 @@ struct _LttvTrace { LttvAttribute *a; guint ref_count; LttvTraceState *state; + char short_name[TRACE_NAME_SIZE]; + char *full_path; }; /* In babeltrace, the position concept is an iterator. */ @@ -111,6 +116,10 @@ LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i); void lttv_traceset_remove(LttvTraceset *s, unsigned i); +int lttv_traceset_get_trace_index_from_event(LttvEvent *event); + +int lttv_traceset_get_trace_index_from_handle_id(LttvTraceset *ts, int handle_id); + /* An attributes table is attached to the set and to each trace in the set. */ LttvAttribute *lttv_traceset_attribute(LttvTraceset *s); diff --git a/lttv/modules/gui/controlflow/eventhooks.c b/lttv/modules/gui/controlflow/eventhooks.c index e311da65..f024cd35 100644 --- a/lttv/modules/gui/controlflow/eventhooks.c +++ b/lttv/modules/gui/controlflow/eventhooks.c @@ -500,7 +500,7 @@ int before_trywakeup_hook(void *hook_data, void *call_data) * draw items from the beginning of the read for it. If it is not * present, it's a new process and it was not present : it will * be added after the state update. TOCHECK: What does that last para mean? */ - guint trace_num = 0; /*TODO ybrosseau 2012-08-23: use right number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); LttvProcessState *process = lttv_state_find_process(ts, woken_cpu, woken_pid); if(process != NULL) { @@ -577,7 +577,7 @@ int before_schedchange_hook(void *hook_data, void *call_data) pid_out = lttv_event_get_long(event, "prev_tid"); pid_in = lttv_event_get_long(event, "next_tid"); state_out = lttv_event_get_long(event, "prev_state"); - guint trace_number = 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number + guint trace_number = lttv_traceset_get_trace_index_from_event(event); process = lttv_state_find_process(ts,cpu,pid_out); evtime = lttv_event_get_timestamp(event); @@ -718,7 +718,7 @@ int after_schedchange_hook(void *hook_data, void *call_data) //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); //process_in = tfs->process; guint cpu = lttv_traceset_get_cpuid_from_event(event); - guint trace_num = 0; /* TODO set right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); process_in = ts->running_process[cpu]; /* It should exist, because we are after the state update. */ #ifdef EXTRA_CHECK @@ -810,7 +810,7 @@ int before_execmode_hook(void *hook_data, void *call_data) cpu = lttv_traceset_get_cpuid_from_event(event); ts = event->state; - guint trace_number = 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number + guint trace_number = lttv_traceset_get_trace_index_from_event(event); //TODO ybrosseau 2013-04-09 validate that using the running process is the right choice //process = lttv_state_find_process(ts ,cpu ,pid); @@ -894,7 +894,7 @@ int before_process_exit_hook(void *hook_data, void *call_data) /* Add process to process list (if not present) */ //LttvProcessState *process = tfs->process; guint cpu = lttv_traceset_get_cpuid_from_event(event); - guint trace_num = 0; /* TODO set right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); LttvProcessState *process = ts->running_process[cpu]; guint pid = process->pid; @@ -963,7 +963,7 @@ int before_process_release_hook(void *hook_data, void *call_data) LttTime evtime = lttv_event_get_timestamp(event); - guint trace_num = 0; /* TODO set right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); guint pid; { @@ -1065,7 +1065,7 @@ int after_process_fork_hook(void *hook_data, void *call_data) /* It should exist, because we are after the state update. */ g_assert(process_child != NULL); - guint trace_num = 0; /* TODO put right */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); /* Cannot use current process, because this action is done by the parent * on its child. */ @@ -1159,7 +1159,7 @@ int after_process_exit_hook(void *hook_data, void *call_data) /* Add process to process list (if not present) */ //LttvProcessState *process = tfs->process; guint cpu = lttv_traceset_get_cpuid_from_event(event); - guint trace_num = 0; /* TODO set right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); LttvProcessState *process = ts->running_process[cpu]; /* It should exist, because we are after the state update. */ @@ -1311,7 +1311,7 @@ int after_event_enum_process_hook(void *hook_data, void *call_data) HashedProcessData *hashed_process_data_in = NULL; ProcessList *process_list = control_flow_data->process_list; - guint trace_num = 0; /* TODO put right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); guint pid_in; { @@ -1776,8 +1776,8 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data) #ifdef EXTRA_CHECK g_assert(lttv_traceset_number(tsc->ts) > 0); #endif //EXTRA_CHECK - //TODO Fdeslauriers 2012-07-17: adapt for multiple traces - LttvTrace *trace = lttv_traceset_get(ts,0); + + LttvTrace *trace = lttv_traceset_get(ts, process_info->trace_num); LttvTraceState *trace_state = trace->state; #if 0 diff --git a/lttv/modules/gui/detailedevents/events.c b/lttv/modules/gui/detailedevents/events.c index c1b44ff3..5a467546 100644 --- a/lttv/modules/gui/detailedevents/events.c +++ b/lttv/modules/gui/detailedevents/events.c @@ -1293,7 +1293,7 @@ int event_hook(void *hook_data, void *call_data) gtk_list_store_append (event_viewer_data->store_m, &iter); gtk_list_store_set (event_viewer_data->store_m, &iter, - TRACE_NAME_COLUMN, "TraceName", + TRACE_NAME_COLUMN, traceState->trace->short_name, CPUID_COLUMN, cpu, EVENT_COLUMN,name->str, TIME_S_COLUMN, time.tv_sec, diff --git a/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c b/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c index 42f75746..b5f416b2 100644 --- a/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c +++ b/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c @@ -1680,6 +1680,7 @@ void add_trace(GtkWidget * widget, gpointer user_data) ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin"); tab = ptab->tab; } +#if 0 //TODO fdeslauriers 2012-07-06: Remove this popup when we support multiple traces traceset = lttvwindow_get_traceset(tab); if(traceset != NULL && lttv_traceset_number(traceset) > 0){ @@ -1694,9 +1695,12 @@ void add_trace(GtkWidget * widget, gpointer user_data) gtk_widget_destroy(dialogue); return; } - +#endif /* Create a new traceset*/ - traceset = lttv_traceset_new(); + traceset = tab->traceset_info->traceset; + if(traceset == NULL) { + traceset = lttv_traceset_new(); + } /* File open dialog management */ #ifdef BABEL_CLEANUP GtkWidget *extra_live_button; diff --git a/lttv/modules/gui/resourceview/eventhooks.c b/lttv/modules/gui/resourceview/eventhooks.c index 3259f9b4..8075f27a 100644 --- a/lttv/modules/gui/resourceview/eventhooks.c +++ b/lttv/modules/gui/resourceview/eventhooks.c @@ -397,7 +397,8 @@ int before_schedchange_hook(void *hook_data, void *call_data) guint cpu = lttv_traceset_get_cpuid_from_event(event); ts = event->state; - guint trace_num = 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number + guint trace_num = lttv_traceset_get_trace_index_from_event(event); + /* Add process to process list (if not present) */ HashedResourceData *hashed_process_data = NULL; @@ -556,7 +557,7 @@ int after_schedchange_hook(void *hook_data, void *call_data) //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); //process_in = tfs->process; guint cpu = lttv_traceset_get_cpuid_from_event(event); - guint trace_num = 0; /* TODO set right trace number */ + guint trace_num = lttv_traceset_get_trace_index_from_event(event); process_in = ts->running_process[cpu]; /* It should exist, because we are after the state update. */ #ifdef EXTRA_CHECK @@ -653,7 +654,7 @@ int before_execmode_hook(void *hook_data, void *call_data) cpu = lttv_traceset_get_cpuid_from_event(event); ts = event->state; - guint trace_num = 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number + guint trace_num = lttv_traceset_get_trace_index_from_event(event); process = ts->running_process[cpu]; g_assert(process != NULL); @@ -826,7 +827,7 @@ int before_execmode_hook_irq(void *hook_data, void *call_data) } else return 0; - guint trace_num = 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number + guint trace_num = lttv_traceset_get_trace_index_from_event(event); /* Well, the process_out existed : we must get it in the process hash * or add it, and draw its items. @@ -1001,7 +1002,7 @@ int before_execmode_hook_soft_irq(void *hook_data, void *call_data) LttvTraceset *traceSet = lttvwindow_get_traceset(resourceview_data->tab); guint cpu = lttv_traceset_get_cpuid_from_event(event); ts = event->state; - guint trace_num = 0;//TODO change it to the right value; + guint trace_num = lttv_traceset_get_trace_index_from_event(event); /* Well, the process_out existed : we must get it in the process hash * or add it, and draw its items. @@ -1331,7 +1332,7 @@ LttvEvent *event; guint8 minor = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); gint devcode_gint = MKDEV(major,minor); - guint trace_num = 0; //TODO put the real trace_num; + guint trace_num = lttv_traceset_get_trace_index_from_event(event); LttvBdevState *bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); /* the result of the lookup might be NULL. that's ok, the rest of the function @@ -1868,8 +1869,8 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data) #ifdef EXTRA_CHECK g_assert(lttv_traceset_number(tsc->ts) > 0); #endif //EXTRA_CHECK - //TODO Fdeslauriers 2012-07-17: adapt for multiple traces - LttvTrace *trace = lttv_traceset_get(ts,0); + + LttvTrace *trace = lttv_traceset_get(ts,process_info->trace_num); LttvTraceState *ts = trace->state; /* Only draw for processes that are currently in the trace states */ -- 2.39.5