X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2FguiStatistic%2FguiStatistic.c;h=c7ed6e6dc42494deb780af974430d17b613bd3bb;hb=f5d980bfa2bc1aca750f5794bcb2e16f1d380c99;hp=64c1718897e69778ea20fb5e1ba0d385f4f3a09d;hpb=bca3b81f050faa6295485fc7dbc3fef45f706d14;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c b/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c index 64c17188..c7ed6e6d 100644 --- a/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c +++ b/ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c @@ -26,6 +26,7 @@ #define PATH_LENGTH 256 static LttvModule *statistic_main_win_module; +static GPtrArray * statistic_traceset; /** Array containing instanced objects. Used when module is unloaded */ static GSList *g_statistic_viewer_data_list = NULL ; @@ -33,9 +34,9 @@ static GSList *g_statistic_viewer_data_list = NULL ; typedef struct _StatisticViewerData StatisticViewerData; //! Statistic Viewer's constructor hook -GtkWidget *h_gui_statistic(MainWindow *parent_window); +GtkWidget *h_gui_statistic(MainWindow *parent_window, LttvTracesetSelector * s, char* key); //! Statistic Viewer's constructor -StatisticViewerData *gui_statistic(MainWindow *parent_window); +StatisticViewerData *gui_statistic(MainWindow *parent_window,LttvTracesetSelector * s, char* key); //! Statistic Viewer's destructor void gui_statistic_destructor(StatisticViewerData *statistic_viewer_data); void gui_statistic_free(StatisticViewerData *statistic_viewer_data); @@ -46,7 +47,6 @@ static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer dat 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); void show_tree(StatisticViewerData * statistic_viewer_data, LttvAttribute* stats, GtkTreeIter* parent); @@ -54,6 +54,17 @@ void show_statistic(StatisticViewerData * statistic_viewer_data, LttvAttribute* stats, GtkTextBuffer* buf); +/** hook functions for update time interval, current time ... */ +gboolean statistic_update_time_window(void * hook_data, void * call_data); +gboolean statistic_show_viewer(void * hook_data, void * call_data); +gboolean statistic_traceset_changed(void * hook_data, void * call_data); +void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, + LttvTracesetContext * tsc); +void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data, + LttvTracesetContext * tsc); + +gboolean statistic_insert_traceset_stats(void * stats); + enum { NAME_COLUMN, @@ -63,6 +74,12 @@ enum struct _StatisticViewerData{ MainWindow * mw; LttvTracesetStats * stats; + gboolean calculate_stats; + int size; + + TimeInterval time_span; + gboolean shown; //indicate if the statistic is shown or not + char * filter_key; GtkWidget * hpaned_v; GtkTreeStore * store_m; @@ -97,12 +114,14 @@ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { g_critical("Can't load Statistic Viewer : missing mainwin\n"); return; } - + + statistic_traceset = g_ptr_array_new (); + /* Register the toolbar insert button */ - ToolbarItemReg(hGuiStatisticInsert_xpm, "Insert Statistic Viewer", h_gui_statistic); + toolbar_item_reg(hGuiStatisticInsert_xpm, "Insert Statistic Viewer", h_gui_statistic); /* Register the menu item insert entry */ - MenuItemReg("/", "Insert Statistic Viewer", h_gui_statistic); + menu_item_reg("/", "Insert Statistic Viewer", h_gui_statistic); } @@ -124,12 +143,13 @@ G_MODULE_EXPORT void destroy() { g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL ); g_slist_free(g_statistic_viewer_data_list); } + g_ptr_array_free (statistic_traceset, TRUE); /* Unregister the toolbar insert button */ - ToolbarItemUnreg(h_gui_statistic); + toolbar_item_unreg(h_gui_statistic); /* Unregister the menu item insert entry */ - MenuItemUnreg(h_gui_statistic); + menu_item_unreg(h_gui_statistic); } @@ -137,7 +157,12 @@ void gui_statistic_free(StatisticViewerData *statistic_viewer_data) { if(statistic_viewer_data){ + unreg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); + unreg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); + unreg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); + g_hash_table_destroy(statistic_viewer_data->statistic_hash); + g_free(statistic_viewer_data->filter_key); g_statistic_viewer_data_list = g_slist_remove(g_statistic_viewer_data_list, statistic_viewer_data); g_free(statistic_viewer_data); } @@ -164,9 +189,9 @@ gui_statistic_destructor(StatisticViewerData *statistic_viewer_data) * @return The widget created. */ GtkWidget * -h_gui_statistic(MainWindow * parent_window) +h_gui_statistic(MainWindow * parent_window, LttvTracesetSelector * s, char* key) { - StatisticViewerData* statistic_viewer_data = gui_statistic(parent_window) ; + StatisticViewerData* statistic_viewer_data = gui_statistic(parent_window, s, key) ; if(statistic_viewer_data) return statistic_viewer_data->hpaned_v; @@ -174,6 +199,23 @@ h_gui_statistic(MainWindow * parent_window) } +gboolean statistic_insert_traceset_stats(void * stats) +{ + int i, len; + gpointer s; + + len = statistic_traceset->len; + for(i=0;imw = parent_window; - statistic_viewer_data->stats = getTracesetStats(statistic_viewer_data->mw); + statistic_viewer_data->stats = get_traceset_stats_api(statistic_viewer_data->mw); + statistic_viewer_data->calculate_stats = statistic_insert_traceset_stats((void *)statistic_viewer_data->stats); + + reg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); + reg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); + reg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash, g_str_equal, statistic_destroy_hash_key, @@ -251,6 +298,34 @@ gui_statistic(MainWindow *parent_window) gtk_widget_show(statistic_viewer_data->text_v); gtk_widget_show(statistic_viewer_data->hpaned_v); + //get the life span of the traceset and set the upper of the scroll bar + get_traceset_time_span(statistic_viewer_data->mw, &statistic_viewer_data->time_span); + + statistic_viewer_data->shown = FALSE; + statistic_viewer_data->filter_key = g_strdup(key); + g_object_set_data( + G_OBJECT(statistic_viewer_data->hpaned_v), + statistic_viewer_data->filter_key, + s); + + g_object_set_data( + G_OBJECT(statistic_viewer_data->hpaned_v), + TRACESET_TIME_SPAN, + &statistic_viewer_data->time_span); + + if(statistic_viewer_data->calculate_stats){ + if(lttv_stats_load_statistics(statistic_viewer_data->stats)) + statistic_viewer_data->calculate_stats = FALSE; + } + + if(statistic_viewer_data->calculate_stats == FALSE){ + statistic_viewer_data->size = 1; + g_object_set_data( + G_OBJECT(statistic_viewer_data->hpaned_v), + MAX_NUMBER_EVENT, + &statistic_viewer_data->size); + } + g_object_set_data_full( G_OBJECT(statistic_viewer_data->hpaned_v), "statistic_viewer_data", @@ -262,8 +337,6 @@ gui_statistic(MainWindow *parent_window) g_statistic_viewer_data_list, statistic_viewer_data); - get_traceset_stats(statistic_viewer_data); - return statistic_viewer_data; } @@ -271,7 +344,7 @@ void grab_focus(GtkWidget *widget, gpointer data) { StatisticViewerData *statistic_viewer_data = (StatisticViewerData *)data; MainWindow * mw = statistic_viewer_data->mw; - SetFocusedPane(mw, gtk_widget_get_parent(statistic_viewer_data->hpaned_v)); + set_focused_pane(mw, gtk_widget_get_parent(statistic_viewer_data->hpaned_v)); } static void @@ -319,27 +392,6 @@ void statistic_destroy_hash_data(gpointer data) // g_free(data); } -void get_traceset_stats(StatisticViewerData * statistic_viewer_data) -{ - LttTime start, end; - - start.tv_sec = 0; - start.tv_nsec = 0; - end.tv_sec = G_MAXULONG; - end.tv_nsec = G_MAXULONG; - - stateAddEventHooks(statistic_viewer_data->mw); - statsAddEventHooks(statistic_viewer_data->mw); - - processTraceset(statistic_viewer_data->mw, start, end, G_MAXULONG); - - stateRemoveEventHooks(statistic_viewer_data->mw); - statsRemoveEventHooks(statistic_viewer_data->mw); - - //establish tree view for stats - show_traceset_stats(statistic_viewer_data); -} - void show_traceset_stats(StatisticViewerData * statistic_viewer_data) { int i, nb; @@ -372,7 +424,8 @@ void show_traceset_stats(StatisticViewerData * statistic_viewer_data) tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]); desc = ltt_trace_system_description(tcs->parent.parent.t); sprintf(trace_str, "Trace on system %s at time %d secs", - desc->node_name,desc->trace_start.tv_sec); + ltt_trace_system_description_node_name(desc), + (ltt_trace_system_description_trace_start_time(desc)).tv_sec); gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1); @@ -485,4 +538,150 @@ void show_statistic(StatisticViewerData * statistic_viewer_data, } } +gboolean statistic_update_time_window(void * hook_data, void * call_data) +{ + StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; + LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); + + //if statistic is already calculated, do nothing + if(!statistic_viewer_data->calculate_stats){ + return FALSE; + } + + if(statistic_viewer_data->shown == FALSE){ + statistic_add_context_hooks(statistic_viewer_data, tsc); + } + return FALSE; +} + +gboolean statistic_show_viewer(void * hook_data, void * call_data) +{ + StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; + LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); + + if(statistic_viewer_data->shown == FALSE){ + statistic_viewer_data->shown = TRUE; + show_traceset_stats(statistic_viewer_data); + if(statistic_viewer_data->calculate_stats){ + statistic_remove_context_hooks(statistic_viewer_data,tsc); + lttv_stats_save_statistics((LttvTracesetStats*)tsc); + } + } + + return FALSE; +} + +gboolean statistic_traceset_changed(void * hook_data, void * call_data) +{ + StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; + + // gtk_tree_store_clear (statistic_viewer_data->store_m); + // statistic_viewer_data->shown = FALSE; + + return FALSE; +} + +void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, + LttvTracesetContext * tsc) +{ + gint i, j, nbi, nb_tracefile, nb_control, nb_per_cpu; + LttTrace *trace; + LttvTraceContext *tc; + LttvTracefileContext *tfc; + LttvTracesetSelector * ts_s; + LttvTraceSelector * t_s; + LttvTracefileSelector * tf_s; + gboolean selected; + + ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v), + statistic_viewer_data->filter_key); + + //if there are hooks for traceset, add them here + + nbi = lttv_traceset_number(tsc->ts); + for(i = 0 ; i < nbi ; i++) { + t_s = lttv_traceset_selector_trace_get(ts_s,i); + selected = lttv_trace_selector_get_selected(t_s); + if(!selected) continue; + tc = tsc->traces[i]; + trace = tc->t; + //if there are hooks for trace, add them here + + nb_control = ltt_trace_control_tracefile_number(trace); + nb_per_cpu = ltt_trace_per_cpu_tracefile_number(trace); + nb_tracefile = nb_control + nb_per_cpu; + + for(j = 0 ; j < nb_tracefile ; j++) { + tf_s = lttv_trace_selector_tracefile_get(t_s,j); + selected = lttv_tracefile_selector_get_selected(tf_s); + if(!selected) continue; + + if(j < nb_control) + tfc = tc->control_tracefiles[j]; + else + tfc = tc->per_cpu_tracefiles[j - nb_control]; + + //if there are hooks for tracefile, add them here + // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL, + // statistic_viewer_data->before_event_hooks,NULL); + } + } + + //add state and stats hooks + //state_add_event_hooks_api(statistic_viewer_data->mw); //it will be added in the main window + stats_add_event_hooks_api(statistic_viewer_data->mw); + +} + +void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data, + LttvTracesetContext * tsc) +{ + gint i, j, nbi, nb_tracefile, nb_control, nb_per_cpu; + LttTrace *trace; + LttvTraceContext *tc; + LttvTracefileContext *tfc; + LttvTracesetSelector * ts_s; + LttvTraceSelector * t_s; + LttvTracefileSelector * tf_s; + gboolean selected; + + ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v), + statistic_viewer_data->filter_key); + + //if there are hooks for traceset, remove them here + + nbi = lttv_traceset_number(tsc->ts); + for(i = 0 ; i < nbi ; i++) { + t_s = lttv_traceset_selector_trace_get(ts_s,i); + selected = lttv_trace_selector_get_selected(t_s); + if(!selected) continue; + tc = tsc->traces[i]; + trace = tc->t; + //if there are hooks for trace, remove them here + + nb_control = ltt_trace_control_tracefile_number(trace); + nb_per_cpu = ltt_trace_per_cpu_tracefile_number(trace); + nb_tracefile = nb_control + nb_per_cpu; + + for(j = 0 ; j < nb_tracefile ; j++) { + tf_s = lttv_trace_selector_tracefile_get(t_s,j); + selected = lttv_tracefile_selector_get_selected(tf_s); + if(!selected) continue; + + if(j < nb_control) + tfc = tc->control_tracefiles[j]; + else + tfc = tc->per_cpu_tracefiles[j - nb_control]; + + //if there are hooks for tracefile, remove them here + // lttv_tracefile_context_remove_hooks(tfc, NULL,NULL,NULL,NULL, + // statistic_viewer_data->before_event_hooks,NULL); + } + } + + //remove state and stats hooks + //state_remove_event_hooks_api(statistic_viewer_data->mw); //it will be done in the main window + stats_remove_event_hooks_api(statistic_viewer_data->mw); +} +