From: yangxx Date: Fri, 17 Oct 2003 14:48:36 +0000 (+0000) Subject: git-svn-id: http://ltt.polymtl.ca/svn@312 04897980-b3bd-0310-b5e0-8ef037075253 X-Git-Tag: v0.12.20~3177 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2176f95285d035b2bf5919c6921949d9713c49b6;p=lttv.git git-svn-id: ltt.polymtl.ca/svn@312 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/include/lttv/traceset.h b/ltt/branches/poly/include/lttv/traceset.h index 4675e719..2f43a228 100644 --- a/ltt/branches/poly/include/lttv/traceset.h +++ b/ltt/branches/poly/include/lttv/traceset.h @@ -43,5 +43,7 @@ LttvAttribute *lttv_trace_attribute(LttvTrace *t); LttTrace *lttv_trace(LttvTrace *t); +guint lttv_trace_get_ref_number(LttvTrace * t); + #endif // TRACESET_H diff --git a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c index 7862acfd..b3807205 100644 --- a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c @@ -30,6 +30,8 @@ static int gWinCount = 0; mainWindow * get_window_data_struct(GtkWidget * widget); char * get_unload_module(char ** loaded_module_name, int nb_module); +char * get_remove_trace(char ** all_trace_name, int nb_trace); +char * get_selection(char ** all_name, int nb, char *title, char * column_title); void * create_tab(GtkWidget* parent, GtkNotebook * notebook, char * label); void insertView(GtkWidget* widget, view_constructor constructor); @@ -167,18 +169,110 @@ void delete_viewer(GtkWidget * widget, gpointer user_data) void open_traceset(GtkWidget * widget, gpointer user_data) { - g_printf("Open a trace set\n"); + char ** dir; + gint id; + LttvTraceset * traceset; + mainWindow * mwData = get_window_data_struct(widget); + GtkFileSelection * fileSelector = + (GtkFileSelection *)gtk_file_selection_new("Select a traceset"); + + gtk_file_selection_hide_fileop_buttons(fileSelector); + id = gtk_dialog_run(GTK_DIALOG(fileSelector)); + switch(id){ + case GTK_RESPONSE_ACCEPT: + case GTK_RESPONSE_OK: + dir = gtk_file_selection_get_selections (fileSelector); + traceset = lttv_traceset_load(dir[0]); + g_printf("Open a trace set %s\n", dir[0]); + //Not finished yet + g_strfreev(dir); + case GTK_RESPONSE_REJECT: + case GTK_RESPONSE_CANCEL: + default: + gtk_widget_destroy((GtkWidget*)fileSelector); + break; + } } void add_trace(GtkWidget * widget, gpointer user_data) { + LttTrace *trace; + LttvTrace * trace_v; + LttvTraceset * traceset; + char * dir; + gint id; + mainWindow * mwData = get_window_data_struct(widget); + GtkDirSelection * fileSelector = (GtkDirSelection *)gtk_dir_selection_new("Select a trace"); + gtk_dir_selection_hide_fileop_buttons(fileSelector); + + id = gtk_dialog_run(GTK_DIALOG(fileSelector)); + switch(id){ + case GTK_RESPONSE_ACCEPT: + case GTK_RESPONSE_OK: + dir = gtk_dir_selection_get_dir (fileSelector); + trace = ltt_trace_open(dir); + if(trace == NULL) g_critical("cannot open trace %s", dir); + trace_v = lttv_trace_new(trace); + traceset = mwData->Traceset_Info->traceset; + if(mwData->Traceset_Info->TracesetContext != NULL){ + lttv_context_fini(LTTV_TRACESET_CONTEXT(mwData->Traceset_Info->TracesetContext)); + g_object_unref(mwData->Traceset_Info->TracesetContext); + } + lttv_traceset_add(traceset, trace_v); + mwData->Traceset_Info->TracesetContext = + g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); + lttv_context_init( + LTTV_TRACESET_CONTEXT(mwData->Traceset_Info->TracesetContext),traceset); + case GTK_RESPONSE_REJECT: + case GTK_RESPONSE_CANCEL: + default: + gtk_widget_destroy((GtkWidget*)fileSelector); + break; + } + g_printf("add a trace to a trace set\n"); } void remove_trace(GtkWidget * widget, gpointer user_data) { + LttTrace *trace; + LttvTrace * trace_v; + LttvTraceset * traceset; + gint i, nb_trace; + char ** name, *remove_trace_name; + mainWindow * mwData = get_window_data_struct(widget); + + nb_trace =lttv_traceset_number(mwData->Traceset_Info->traceset); + name = g_new(char*,nb_trace); + for(i = 0; i < nb_trace; i++){ + trace_v = lttv_traceset_get(mwData->Traceset_Info->traceset, i); + trace = lttv_trace(trace_v); + name[i] = trace->pathname; + } + + remove_trace_name = get_remove_trace(name, nb_trace); + + if(remove_trace_name){ + for(i=0; iTraceset_Info->traceset; + if(mwData->Traceset_Info->TracesetContext != NULL){ + lttv_context_fini(LTTV_TRACESET_CONTEXT(mwData->Traceset_Info->TracesetContext)); + g_object_unref(mwData->Traceset_Info->TracesetContext); + } + lttv_traceset_remove(traceset, i); + mwData->Traceset_Info->TracesetContext = + g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); + lttv_context_init( + LTTV_TRACESET_CONTEXT(mwData->Traceset_Info->TracesetContext),traceset); + break; + } + } + } + + g_free(name); g_printf("remove a trace from a trace set\n"); } @@ -716,7 +810,19 @@ on_MNotebook_switch_page (GtkNotebook *notebook, mw->CurrentTab = Tab; } +char * get_remove_trace(char ** all_trace_name, int nb_trace) +{ + return get_selection(all_trace_name, nb_trace, + "Select a trace", "Trace pathname"); +} char * get_unload_module(char ** loaded_module_name, int nb_module) +{ + return get_selection(loaded_module_name, nb_module, + "Select an unload module", "Module pathname"); +} + +char * get_selection(char ** loaded_module_name, int nb_module, + char *title, char * column_title) { GtkWidget * dialogue; GtkWidget * scroll_win; @@ -729,7 +835,7 @@ char * get_unload_module(char ** loaded_module_name, int nb_module) gint id, i; char * unload_module_name = NULL; - dialogue = gtk_dialog_new_with_buttons("Select an unload module", + dialogue = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK,GTK_RESPONSE_ACCEPT, @@ -748,7 +854,7 @@ char * get_unload_module(char ** loaded_module_name, int nb_module) g_object_unref (G_OBJECT (store)); renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("MODULE NAME", + column = gtk_tree_view_column_new_with_attributes (column_title, renderer, "text", MODULE_COLUMN, NULL); @@ -785,12 +891,12 @@ char * get_unload_module(char ** loaded_module_name, int nb_module) return unload_module_name; } -void destroy_hash_key(gpointer key) +void main_window_destroy_hash_key(gpointer key) { g_free(key); } -void destroy_hash_data(gpointer data) +void main_window_destroy_hash_data(gpointer data) { } @@ -954,9 +1060,11 @@ void constructMainWin(mainWindow * parent, WindowCreationData * win_creation_dat } newMWindow->hash_menu_item = g_hash_table_new_full (g_str_hash, g_str_equal, - destroy_hash_key, destroy_hash_data); + main_window_destroy_hash_key, + main_window_destroy_hash_data); newMWindow->hash_toolbar_item = g_hash_table_new_full (g_str_hash, g_str_equal, - destroy_hash_key, destroy_hash_data); + main_window_destroy_hash_key, + main_window_destroy_hash_data); insertMenuToolbarItem(newMWindow, NULL); @@ -1097,6 +1205,7 @@ void remove_toolbar_item(gpointer main_win, gpointer user_data) /** * Remove menu and toolbar item when a module unloaded */ + void main_window_remove_menu_item(lttv_constructor constructor) { int i; @@ -1113,7 +1222,9 @@ void main_window_remove_menu_item(lttv_constructor constructor) for(i=0;ilen;i++){ menuItem = &g_array_index(menu, lttv_menu_closure, i); if(menuItem->con != constructor) continue; - g_slist_foreach(Main_Window_List, remove_menu_item, menuItem); + if(Main_Window_List){ + g_slist_foreach(Main_Window_List, remove_menu_item, menuItem); + } break; } } @@ -1136,7 +1247,9 @@ void main_window_remove_toolbar_item(lttv_constructor constructor) for(i=0;ilen;i++){ toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i); if(toolbarItem->con != constructor) continue; - g_slist_foreach(Main_Window_List, remove_toolbar_item, toolbarItem); + if(Main_Window_List){ + g_slist_foreach(Main_Window_List, remove_toolbar_item, toolbarItem); + } break; } } diff --git a/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c b/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c index ed724a42..a7332680 100644 --- a/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c +++ b/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c @@ -84,9 +84,6 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data) return FALSE; } - - - G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { LttvAttributeValue value; @@ -115,7 +112,8 @@ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { void mainWindow_free(mainWindow * mw) { - guint i, nb; + guint i, nb, ref_count; + LttvTrace * trace; if(mw){ @@ -139,8 +137,10 @@ g_critical("end remove"); if(mw->Traceset_Info->traceset != NULL) { nb = lttv_traceset_number(mw->Traceset_Info->traceset); for(i = 0 ; i < nb ; i++) { - ltt_trace_close( - lttv_trace(lttv_traceset_get(mw->Traceset_Info->traceset, i))); + trace = lttv_traceset_get(mw->Traceset_Info->traceset, i); + ref_count = lttv_trace_get_ref_number(trace); + if(ref_count <= 1) + ltt_trace_close(lttv_trace(trace)); } } @@ -175,7 +175,7 @@ mainWindow_Destructor(mainWindow * mw) } -void destroy_walk(gpointer data, gpointer user_data) +void main_window_destroy_walk(gpointer data, gpointer user_data) { mainWindow_Destructor((mainWindow*)data); } @@ -199,8 +199,10 @@ G_MODULE_EXPORT void destroy() { g_critical("GUI destroy()"); - g_slist_foreach(Main_Window_List, destroy_walk, NULL ); - g_slist_free(Main_Window_List); + if(Main_Window_List){ + g_slist_foreach(Main_Window_List, main_window_destroy_walk, NULL ); + g_slist_free(Main_Window_List); + } } diff --git a/ltt/branches/poly/lttv/modules/guiEvents.c b/ltt/branches/poly/lttv/modules/guiEvents.c index 6de10222..c716521e 100644 --- a/ltt/branches/poly/lttv/modules/guiEvents.c +++ b/ltt/branches/poly/lttv/modules/guiEvents.c @@ -171,13 +171,12 @@ static LttvModule *Main_Win_Module; */ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { - Main_Win_Module = lttv_module_require(self, "mainwin", argc, argv); - - if(Main_Win_Module == NULL) - { - g_critical("Can't load Control Flow Viewer : missing mainwin\n"); - return; - } + Main_Win_Module = lttv_module_require(self, "mainwin", argc, argv); + + if(Main_Win_Module == NULL){ + g_critical("Can't load Control Flow Viewer : missing mainwin\n"); + return; + } g_critical("GUI Event Viewer init()"); @@ -190,7 +189,7 @@ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { } -void destroy_walk(gpointer data, gpointer user_data) +void event_destroy_walk(gpointer data, gpointer user_data) { GuiEvents_Destructor((EventViewerData*)data); } @@ -208,9 +207,10 @@ G_MODULE_EXPORT void destroy() { g_critical("GUI Event Viewer destroy()"); - g_slist_foreach(sEvent_Viewer_Data_List, destroy_walk, NULL ); - - g_slist_free(sEvent_Viewer_Data_List); + if(sEvent_Viewer_Data_List){ + g_slist_foreach(sEvent_Viewer_Data_List, event_destroy_walk, NULL ); + g_slist_free(sEvent_Viewer_Data_List); + } /* Unregister the toolbar insert button */ ToolbarItemUnreg(hGuiEvents); diff --git a/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c b/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c index 23d53a5c..951a9882 100644 --- a/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c +++ b/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c @@ -43,8 +43,8 @@ void GuiStatistic_free(StatisticViewerData *Statistic_Viewer_Data); void grab_focus(GtkWidget *widget, gpointer data); static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data); -void Destroy_hash_key(gpointer key); -void Destroy_hash_data(gpointer data); +void statistic_destroy_hash_key(gpointer key); +void statistic_destroy_hash_data(gpointer data); void get_traceset_stats(StatisticViewerData * Statistic_Viewer_Data); void show_traceset_stats(StatisticViewerData * Statistic_Viewer_Data); @@ -108,7 +108,7 @@ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { } -void destroy_walk(gpointer data, gpointer user_data) +void statistic_destroy_walk(gpointer data, gpointer user_data) { GuiStatistic_Destructor((StatisticViewerData*)data); } @@ -123,9 +123,11 @@ G_MODULE_EXPORT void destroy() { int i; g_critical("GUI Statistic Viewer destroy()"); - g_slist_foreach(gStatistic_Viewer_Data_List, destroy_walk, NULL ); - g_slist_free(gStatistic_Viewer_Data_List); + if(gStatistic_Viewer_Data_List){ + g_slist_foreach(gStatistic_Viewer_Data_List, statistic_destroy_walk, NULL ); + g_slist_free(gStatistic_Viewer_Data_List); + } /* Unregister the toolbar insert button */ ToolbarItemUnreg(hGuiStatistic); @@ -197,7 +199,8 @@ GuiStatistic(mainWindow *pmParentWindow) Statistic_Viewer_Data->stats = getTracesetStats(Statistic_Viewer_Data->mw); Statistic_Viewer_Data->Statistic_Hash = g_hash_table_new_full(g_str_hash, g_str_equal, - Destroy_hash_key, Destroy_hash_data); + statistic_destroy_hash_key, + statistic_destroy_hash_data); Statistic_Viewer_Data->HPaned_V = gtk_hpaned_new(); Statistic_Viewer_Data->Store_M = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING); @@ -313,12 +316,12 @@ tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data) } } -void Destroy_hash_key(gpointer key) +void statistic_destroy_hash_key(gpointer key) { g_free(key); } -void Destroy_hash_data(gpointer data) +void statistic_destroy_hash_data(gpointer data) { // g_free(data); } diff --git a/ltt/branches/poly/lttv/traceset.c b/ltt/branches/poly/lttv/traceset.c index 2192d212..508afb16 100644 --- a/ltt/branches/poly/lttv/traceset.c +++ b/ltt/branches/poly/lttv/traceset.c @@ -18,6 +18,7 @@ struct _LttvTraceset { struct _LttvTrace { LttTrace *t; LttvAttribute *a; + guint ref_count; }; @@ -39,6 +40,7 @@ LttvTrace *lttv_trace_new(LttTrace *t) new_trace = g_new(LttvTrace, 1); new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); new_trace->t = t; + new_trace->ref_count = 0; return new_trace; } @@ -47,12 +49,16 @@ LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) { int i; LttvTraceset *s; + LttvTrace * trace; s = g_new(LttvTraceset, 1); s->filename = NULL; s->traces = g_ptr_array_new(); for(i=0;itraces->len;i++) { + trace = g_ptr_array_index(s_orig->traces, i); + trace->ref_count++; + /*CHECK this used ltt_trace_copy while it may not be needed. Need to define how traces and tracesets are shared */ g_ptr_array_add( @@ -106,6 +112,7 @@ void lttv_trace_destroy(LttvTrace *t) void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) { + t->ref_count++; g_ptr_array_add(s->traces, t); } @@ -125,6 +132,10 @@ LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) void lttv_traceset_remove(LttvTraceset *s, unsigned i) { + LttvTrace * t; + g_assert(s->traces->len > i); + t = (LttvTrace *)s->traces->pdata[i]; + t->ref_count--; g_ptr_array_remove_index(s->traces, i); } @@ -149,3 +160,7 @@ LttTrace *lttv_trace(LttvTrace *t) return t->t; } +guint lttv_trace_get_ref_number(LttvTrace * t) +{ + return t->ref_count; +}