| 1 | #include <glib.h> |
| 2 | #include <gmodule.h> |
| 3 | #include <gtk/gtk.h> |
| 4 | #include <gdk/gdk.h> |
| 5 | |
| 6 | #include <lttv/module.h> |
| 7 | #include <lttv/gtkTraceSet.h> |
| 8 | #include <lttv/processTrace.h> |
| 9 | #include <lttv/hook.h> |
| 10 | #include <lttv/common.h> |
| 11 | #include <lttv/state.h> |
| 12 | #include <lttv/stats.h> |
| 13 | |
| 14 | #include <ltt/ltt.h> |
| 15 | #include <ltt/event.h> |
| 16 | #include <ltt/type.h> |
| 17 | #include <ltt/trace.h> |
| 18 | |
| 19 | #include <string.h> |
| 20 | |
| 21 | #include "../icons/hGuiStatisticInsert.xpm" |
| 22 | |
| 23 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
| 24 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
| 25 | |
| 26 | #define PATH_LENGTH 256 |
| 27 | |
| 28 | static LttvModule *statistic_main_win_module; |
| 29 | |
| 30 | /** Array containing instanced objects. Used when module is unloaded */ |
| 31 | static GSList *g_statistic_viewer_data_list = NULL ; |
| 32 | |
| 33 | typedef struct _StatisticViewerData StatisticViewerData; |
| 34 | |
| 35 | //! Statistic Viewer's constructor hook |
| 36 | GtkWidget *h_gui_statistic(MainWindow *parent_window, LttvTracesetSelector * s, char* key); |
| 37 | //! Statistic Viewer's constructor |
| 38 | StatisticViewerData *gui_statistic(MainWindow *parent_window,LttvTracesetSelector * s, char* key); |
| 39 | //! Statistic Viewer's destructor |
| 40 | void gui_statistic_destructor(StatisticViewerData *statistic_viewer_data); |
| 41 | void gui_statistic_free(StatisticViewerData *statistic_viewer_data); |
| 42 | |
| 43 | void grab_focus(GtkWidget *widget, gpointer data); |
| 44 | static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data); |
| 45 | |
| 46 | void statistic_destroy_hash_key(gpointer key); |
| 47 | void statistic_destroy_hash_data(gpointer data); |
| 48 | |
| 49 | void show_traceset_stats(StatisticViewerData * statistic_viewer_data); |
| 50 | void show_tree(StatisticViewerData * statistic_viewer_data, |
| 51 | LttvAttribute* stats, GtkTreeIter* parent); |
| 52 | void show_statistic(StatisticViewerData * statistic_viewer_data, |
| 53 | LttvAttribute* stats, GtkTextBuffer* buf); |
| 54 | |
| 55 | |
| 56 | /** hook functions for update time interval, current time ... */ |
| 57 | gboolean statistic_update_time_window(void * hook_data, void * call_data); |
| 58 | gboolean statistic_show_viewer(void * hook_data, void * call_data); |
| 59 | gboolean statistic_traceset_changed(void * hook_data, void * call_data); |
| 60 | void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, |
| 61 | LttvTracesetContext * tsc); |
| 62 | void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data, |
| 63 | LttvTracesetContext * tsc); |
| 64 | |
| 65 | enum |
| 66 | { |
| 67 | NAME_COLUMN, |
| 68 | N_COLUMNS |
| 69 | }; |
| 70 | |
| 71 | struct _StatisticViewerData{ |
| 72 | MainWindow * mw; |
| 73 | LttvTracesetStats * stats; |
| 74 | |
| 75 | TimeInterval time_span; |
| 76 | gboolean shown; //indicate if the statistic is shown or not |
| 77 | char * filter_key; |
| 78 | |
| 79 | GtkWidget * hpaned_v; |
| 80 | GtkTreeStore * store_m; |
| 81 | GtkWidget * tree_v; |
| 82 | |
| 83 | //scroll window containing Tree View |
| 84 | GtkWidget * scroll_win_tree; |
| 85 | |
| 86 | GtkWidget * text_v; |
| 87 | //scroll window containing Text View |
| 88 | GtkWidget * scroll_win_text; |
| 89 | |
| 90 | // Selection handler |
| 91 | GtkTreeSelection *select_c; |
| 92 | |
| 93 | //hash |
| 94 | GHashTable *statistic_hash; |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * plugin's init function |
| 100 | * |
| 101 | * This function initializes the Statistic Viewer functionnality through the |
| 102 | * gtkTraceSet API. |
| 103 | */ |
| 104 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
| 105 | |
| 106 | statistic_main_win_module = lttv_module_require(self, "mainwin", argc, argv); |
| 107 | |
| 108 | if(statistic_main_win_module == NULL){ |
| 109 | g_critical("Can't load Statistic Viewer : missing mainwin\n"); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | /* Register the toolbar insert button */ |
| 114 | toolbar_item_reg(hGuiStatisticInsert_xpm, "Insert Statistic Viewer", h_gui_statistic); |
| 115 | |
| 116 | /* Register the menu item insert entry */ |
| 117 | menu_item_reg("/", "Insert Statistic Viewer", h_gui_statistic); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | void statistic_destroy_walk(gpointer data, gpointer user_data) |
| 122 | { |
| 123 | gui_statistic_destructor((StatisticViewerData*)data); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * plugin's destroy function |
| 128 | * |
| 129 | * This function releases the memory reserved by the module and unregisters |
| 130 | * everything that has been registered in the gtkTraceSet API. |
| 131 | */ |
| 132 | G_MODULE_EXPORT void destroy() { |
| 133 | int i; |
| 134 | |
| 135 | if(g_statistic_viewer_data_list){ |
| 136 | g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL ); |
| 137 | g_slist_free(g_statistic_viewer_data_list); |
| 138 | } |
| 139 | |
| 140 | /* Unregister the toolbar insert button */ |
| 141 | toolbar_item_unreg(h_gui_statistic); |
| 142 | |
| 143 | /* Unregister the menu item insert entry */ |
| 144 | menu_item_unreg(h_gui_statistic); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | void |
| 149 | gui_statistic_free(StatisticViewerData *statistic_viewer_data) |
| 150 | { |
| 151 | if(statistic_viewer_data){ |
| 152 | unreg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); |
| 153 | unreg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); |
| 154 | unreg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); |
| 155 | |
| 156 | g_hash_table_destroy(statistic_viewer_data->statistic_hash); |
| 157 | g_free(statistic_viewer_data->filter_key); |
| 158 | g_statistic_viewer_data_list = g_slist_remove(g_statistic_viewer_data_list, statistic_viewer_data); |
| 159 | g_free(statistic_viewer_data); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void |
| 164 | gui_statistic_destructor(StatisticViewerData *statistic_viewer_data) |
| 165 | { |
| 166 | /* May already been done by GTK window closing */ |
| 167 | if(GTK_IS_WIDGET(statistic_viewer_data->hpaned_v)){ |
| 168 | gtk_widget_destroy(statistic_viewer_data->hpaned_v); |
| 169 | statistic_viewer_data = NULL; |
| 170 | } |
| 171 | //gui_statistic_free(statistic_viewer_data); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /** |
| 176 | * Statistic Viewer's constructor hook |
| 177 | * |
| 178 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 179 | * registration. It creates the list. |
| 180 | * @param parent_window A pointer to the parent window. |
| 181 | * @return The widget created. |
| 182 | */ |
| 183 | GtkWidget * |
| 184 | h_gui_statistic(MainWindow * parent_window, LttvTracesetSelector * s, char* key) |
| 185 | { |
| 186 | StatisticViewerData* statistic_viewer_data = gui_statistic(parent_window, s, key) ; |
| 187 | |
| 188 | if(statistic_viewer_data) |
| 189 | return statistic_viewer_data->hpaned_v; |
| 190 | else return NULL; |
| 191 | |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Statistic Viewer's constructor |
| 196 | * |
| 197 | * This constructor is used to create StatisticViewerData data structure. |
| 198 | * @return The Statistic viewer data created. |
| 199 | */ |
| 200 | StatisticViewerData * |
| 201 | gui_statistic(MainWindow *parent_window, LttvTracesetSelector * s, char* key) |
| 202 | { |
| 203 | GtkCellRenderer *renderer; |
| 204 | GtkTreeViewColumn *column; |
| 205 | |
| 206 | StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1); |
| 207 | |
| 208 | statistic_viewer_data->mw = parent_window; |
| 209 | statistic_viewer_data->stats = get_traceset_stats_api(statistic_viewer_data->mw); |
| 210 | |
| 211 | reg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); |
| 212 | reg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); |
| 213 | reg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); |
| 214 | |
| 215 | statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 216 | statistic_destroy_hash_key, |
| 217 | statistic_destroy_hash_data); |
| 218 | |
| 219 | statistic_viewer_data->hpaned_v = gtk_hpaned_new(); |
| 220 | statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING); |
| 221 | statistic_viewer_data->tree_v = gtk_tree_view_new_with_model (GTK_TREE_MODEL (statistic_viewer_data->store_m)); |
| 222 | g_object_unref (G_OBJECT (statistic_viewer_data->store_m)); |
| 223 | |
| 224 | g_signal_connect (G_OBJECT (statistic_viewer_data->tree_v), "grab-focus", |
| 225 | G_CALLBACK (grab_focus), |
| 226 | statistic_viewer_data); |
| 227 | |
| 228 | // Setup the selection handler |
| 229 | statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v)); |
| 230 | gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE); |
| 231 | g_signal_connect (G_OBJECT (statistic_viewer_data->select_c), "changed", |
| 232 | G_CALLBACK (tree_selection_changed_cb), |
| 233 | statistic_viewer_data); |
| 234 | |
| 235 | renderer = gtk_cell_renderer_text_new (); |
| 236 | column = gtk_tree_view_column_new_with_attributes ("Statistic Name", |
| 237 | renderer, |
| 238 | "text", NAME_COLUMN, |
| 239 | NULL); |
| 240 | gtk_tree_view_column_set_alignment (column, 0.0); |
| 241 | // gtk_tree_view_column_set_fixed_width (column, 45); |
| 242 | gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column); |
| 243 | |
| 244 | |
| 245 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE); |
| 246 | |
| 247 | statistic_viewer_data->scroll_win_tree = gtk_scrolled_window_new (NULL, NULL); |
| 248 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_tree), |
| 249 | GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); |
| 250 | |
| 251 | gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_tree), statistic_viewer_data->tree_v); |
| 252 | gtk_paned_pack1(GTK_PANED(statistic_viewer_data->hpaned_v),statistic_viewer_data->scroll_win_tree, TRUE, FALSE); |
| 253 | gtk_paned_set_position(GTK_PANED(statistic_viewer_data->hpaned_v), 160); |
| 254 | |
| 255 | statistic_viewer_data->scroll_win_text = gtk_scrolled_window_new (NULL, NULL); |
| 256 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_text), |
| 257 | GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); |
| 258 | |
| 259 | statistic_viewer_data->text_v = gtk_text_view_new (); |
| 260 | g_signal_connect (G_OBJECT (statistic_viewer_data->text_v), "grab-focus", |
| 261 | G_CALLBACK (grab_focus), |
| 262 | statistic_viewer_data); |
| 263 | |
| 264 | gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); |
| 265 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); |
| 266 | gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v); |
| 267 | gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE); |
| 268 | |
| 269 | gtk_widget_show(statistic_viewer_data->scroll_win_tree); |
| 270 | gtk_widget_show(statistic_viewer_data->scroll_win_text); |
| 271 | gtk_widget_show(statistic_viewer_data->tree_v); |
| 272 | gtk_widget_show(statistic_viewer_data->text_v); |
| 273 | gtk_widget_show(statistic_viewer_data->hpaned_v); |
| 274 | |
| 275 | //get the life span of the traceset and set the upper of the scroll bar |
| 276 | get_traceset_time_span(statistic_viewer_data->mw, &statistic_viewer_data->time_span); |
| 277 | |
| 278 | statistic_viewer_data->shown = FALSE; |
| 279 | statistic_viewer_data->filter_key = g_strdup(key); |
| 280 | g_object_set_data( |
| 281 | G_OBJECT(statistic_viewer_data->hpaned_v), |
| 282 | statistic_viewer_data->filter_key, |
| 283 | s); |
| 284 | |
| 285 | g_object_set_data( |
| 286 | G_OBJECT(statistic_viewer_data->hpaned_v), |
| 287 | TRACESET_TIME_SPAN, |
| 288 | &statistic_viewer_data->time_span); |
| 289 | |
| 290 | g_object_set_data_full( |
| 291 | G_OBJECT(statistic_viewer_data->hpaned_v), |
| 292 | "statistic_viewer_data", |
| 293 | statistic_viewer_data, |
| 294 | (GDestroyNotify)gui_statistic_free); |
| 295 | |
| 296 | /* Add the object's information to the module's array */ |
| 297 | g_statistic_viewer_data_list = g_slist_append( |
| 298 | g_statistic_viewer_data_list, |
| 299 | statistic_viewer_data); |
| 300 | |
| 301 | return statistic_viewer_data; |
| 302 | } |
| 303 | |
| 304 | void grab_focus(GtkWidget *widget, gpointer data) |
| 305 | { |
| 306 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData *)data; |
| 307 | MainWindow * mw = statistic_viewer_data->mw; |
| 308 | set_focused_pane(mw, gtk_widget_get_parent(statistic_viewer_data->hpaned_v)); |
| 309 | } |
| 310 | |
| 311 | static void |
| 312 | tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data) |
| 313 | { |
| 314 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*)data; |
| 315 | GtkTreeIter iter; |
| 316 | GtkTreeModel *model = GTK_TREE_MODEL(statistic_viewer_data->store_m); |
| 317 | gchar *event; |
| 318 | GtkTextBuffer* buf; |
| 319 | gchar * str; |
| 320 | GtkTreePath * path; |
| 321 | GtkTextIter text_iter; |
| 322 | LttvAttribute * stats; |
| 323 | |
| 324 | if (gtk_tree_selection_get_selected (selection, &model, &iter)) |
| 325 | { |
| 326 | gtk_tree_model_get (model, &iter, NAME_COLUMN, &event, -1); |
| 327 | |
| 328 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(model),&iter); |
| 329 | str = gtk_tree_path_to_string (path); |
| 330 | stats = (LttvAttribute*)g_hash_table_lookup (statistic_viewer_data->statistic_hash,str); |
| 331 | g_free(str); |
| 332 | |
| 333 | buf = gtk_text_view_get_buffer((GtkTextView*)statistic_viewer_data->text_v); |
| 334 | gtk_text_buffer_set_text(buf,"Statistic for '", -1); |
| 335 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
| 336 | gtk_text_buffer_insert(buf, &text_iter, event, strlen(event)); |
| 337 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
| 338 | gtk_text_buffer_insert(buf, &text_iter, "' :\n\n",5); |
| 339 | |
| 340 | show_statistic(statistic_viewer_data, stats, buf); |
| 341 | |
| 342 | g_free (event); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void statistic_destroy_hash_key(gpointer key) |
| 347 | { |
| 348 | g_free(key); |
| 349 | } |
| 350 | |
| 351 | void statistic_destroy_hash_data(gpointer data) |
| 352 | { |
| 353 | // g_free(data); |
| 354 | } |
| 355 | |
| 356 | void show_traceset_stats(StatisticViewerData * statistic_viewer_data) |
| 357 | { |
| 358 | int i, nb; |
| 359 | LttvTraceset *ts; |
| 360 | LttvTraceStats *tcs; |
| 361 | LttSystemDescription *desc; |
| 362 | LttvTracesetStats * tscs = statistic_viewer_data->stats; |
| 363 | gchar * str, trace_str[PATH_LENGTH]; |
| 364 | GtkTreePath * path; |
| 365 | GtkTreeIter iter; |
| 366 | GtkTreeStore * store = statistic_viewer_data->store_m; |
| 367 | |
| 368 | if(tscs->stats == NULL) return; |
| 369 | |
| 370 | gtk_tree_store_append (store, &iter, NULL); |
| 371 | gtk_tree_store_set (store, &iter, |
| 372 | NAME_COLUMN, "Traceset statistics", |
| 373 | -1); |
| 374 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
| 375 | str = gtk_tree_path_to_string (path); |
| 376 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
| 377 | (gpointer)str, tscs->stats); |
| 378 | show_tree(statistic_viewer_data, tscs->stats, &iter); |
| 379 | |
| 380 | //show stats for all traces |
| 381 | ts = tscs->parent.parent.ts; |
| 382 | nb = lttv_traceset_number(ts); |
| 383 | |
| 384 | for(i = 0 ; i < nb ; i++) { |
| 385 | tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]); |
| 386 | desc = ltt_trace_system_description(tcs->parent.parent.t); |
| 387 | sprintf(trace_str, "Trace on system %s at time %d secs", |
| 388 | ltt_trace_system_description_node_name(desc), |
| 389 | (ltt_trace_system_description_trace_start_time(desc)).tv_sec); |
| 390 | |
| 391 | gtk_tree_store_append (store, &iter, NULL); |
| 392 | gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1); |
| 393 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
| 394 | str = gtk_tree_path_to_string (path); |
| 395 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
| 396 | (gpointer)str,tcs->stats); |
| 397 | show_tree(statistic_viewer_data, tcs->stats, &iter); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void show_tree(StatisticViewerData * statistic_viewer_data, |
| 402 | LttvAttribute* stats, GtkTreeIter* parent) |
| 403 | { |
| 404 | int i, nb; |
| 405 | LttvAttribute *subtree; |
| 406 | LttvAttributeName name; |
| 407 | LttvAttributeValue value; |
| 408 | LttvAttributeType type; |
| 409 | gchar * str, dir_str[PATH_LENGTH]; |
| 410 | GtkTreePath * path; |
| 411 | GtkTreeIter iter; |
| 412 | GtkTreeStore * store = statistic_viewer_data->store_m; |
| 413 | |
| 414 | nb = lttv_attribute_get_number(stats); |
| 415 | for(i = 0 ; i < nb ; i++) { |
| 416 | type = lttv_attribute_get(stats, i, &name, &value); |
| 417 | switch(type) { |
| 418 | case LTTV_GOBJECT: |
| 419 | if(LTTV_IS_ATTRIBUTE(*(value.v_gobject))) { |
| 420 | sprintf(dir_str, "%s", g_quark_to_string(name)); |
| 421 | subtree = (LttvAttribute *)*(value.v_gobject); |
| 422 | gtk_tree_store_append (store, &iter, parent); |
| 423 | gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1); |
| 424 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
| 425 | str = gtk_tree_path_to_string (path); |
| 426 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
| 427 | (gpointer)str, subtree); |
| 428 | show_tree(statistic_viewer_data, subtree, &iter); |
| 429 | } |
| 430 | break; |
| 431 | default: |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | void show_statistic(StatisticViewerData * statistic_viewer_data, |
| 438 | LttvAttribute* stats, GtkTextBuffer* buf) |
| 439 | { |
| 440 | int i, nb , flag; |
| 441 | LttvAttribute *subtree; |
| 442 | LttvAttributeName name; |
| 443 | LttvAttributeValue value; |
| 444 | LttvAttributeType type; |
| 445 | gchar type_name[PATH_LENGTH], type_value[PATH_LENGTH]; |
| 446 | GtkTextIter text_iter; |
| 447 | |
| 448 | flag = 0; |
| 449 | nb = lttv_attribute_get_number(stats); |
| 450 | for(i = 0 ; i < nb ; i++) { |
| 451 | type = lttv_attribute_get(stats, i, &name, &value); |
| 452 | sprintf(type_name,"%s", g_quark_to_string(name)); |
| 453 | type_value[0] = '\0'; |
| 454 | switch(type) { |
| 455 | case LTTV_INT: |
| 456 | sprintf(type_value, " : %d\n", *value.v_int); |
| 457 | break; |
| 458 | case LTTV_UINT: |
| 459 | sprintf(type_value, " : %u\n", *value.v_uint); |
| 460 | break; |
| 461 | case LTTV_LONG: |
| 462 | sprintf(type_value, " : %ld\n", *value.v_long); |
| 463 | break; |
| 464 | case LTTV_ULONG: |
| 465 | sprintf(type_value, " : %lu\n", *value.v_ulong); |
| 466 | break; |
| 467 | case LTTV_FLOAT: |
| 468 | sprintf(type_value, " : %f\n", (double)*value.v_float); |
| 469 | break; |
| 470 | case LTTV_DOUBLE: |
| 471 | sprintf(type_value, " : %f\n", *value.v_double); |
| 472 | break; |
| 473 | case LTTV_TIME: |
| 474 | sprintf(type_value, " : %10u.%09u\n", value.v_time->tv_sec, |
| 475 | value.v_time->tv_nsec); |
| 476 | break; |
| 477 | case LTTV_POINTER: |
| 478 | sprintf(type_value, " : POINTER\n"); |
| 479 | break; |
| 480 | case LTTV_STRING: |
| 481 | sprintf(type_value, " : %s\n", *value.v_string); |
| 482 | break; |
| 483 | default: |
| 484 | break; |
| 485 | } |
| 486 | if(strlen(type_value)){ |
| 487 | flag = 1; |
| 488 | strcat(type_name,type_value); |
| 489 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
| 490 | gtk_text_buffer_insert(buf, &text_iter, type_name, strlen(type_name)); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if(flag == 0){ |
| 495 | sprintf(type_value, "No statistic information in this directory.\nCheck in subdirectories please.\n"); |
| 496 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
| 497 | gtk_text_buffer_insert(buf, &text_iter, type_value, strlen(type_value)); |
| 498 | |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | gboolean statistic_update_time_window(void * hook_data, void * call_data) |
| 503 | { |
| 504 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
| 505 | LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); |
| 506 | |
| 507 | if(statistic_viewer_data->shown == FALSE){ |
| 508 | statistic_add_context_hooks(statistic_viewer_data, tsc); |
| 509 | } |
| 510 | return FALSE; |
| 511 | } |
| 512 | |
| 513 | gboolean statistic_show_viewer(void * hook_data, void * call_data) |
| 514 | { |
| 515 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
| 516 | LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); |
| 517 | |
| 518 | if(statistic_viewer_data->shown == FALSE){ |
| 519 | statistic_viewer_data->shown = TRUE; |
| 520 | show_traceset_stats(statistic_viewer_data); |
| 521 | statistic_remove_context_hooks(statistic_viewer_data,tsc); |
| 522 | } |
| 523 | |
| 524 | return FALSE; |
| 525 | } |
| 526 | |
| 527 | gboolean statistic_traceset_changed(void * hook_data, void * call_data) |
| 528 | { |
| 529 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
| 530 | |
| 531 | // gtk_tree_store_clear (statistic_viewer_data->store_m); |
| 532 | // statistic_viewer_data->shown = FALSE; |
| 533 | |
| 534 | return FALSE; |
| 535 | } |
| 536 | |
| 537 | void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, |
| 538 | LttvTracesetContext * tsc) |
| 539 | { |
| 540 | gint i, j, nbi, nb_tracefile, nb_control, nb_per_cpu; |
| 541 | LttTrace *trace; |
| 542 | LttvTraceContext *tc; |
| 543 | LttvTracefileContext *tfc; |
| 544 | LttvTracesetSelector * ts_s; |
| 545 | LttvTraceSelector * t_s; |
| 546 | LttvTracefileSelector * tf_s; |
| 547 | gboolean selected; |
| 548 | |
| 549 | ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v), |
| 550 | statistic_viewer_data->filter_key); |
| 551 | |
| 552 | //if there are hooks for traceset, add them here |
| 553 | |
| 554 | nbi = lttv_traceset_number(tsc->ts); |
| 555 | for(i = 0 ; i < nbi ; i++) { |
| 556 | t_s = lttv_traceset_selector_trace_get(ts_s,i); |
| 557 | selected = lttv_trace_selector_get_selected(t_s); |
| 558 | if(!selected) continue; |
| 559 | tc = tsc->traces[i]; |
| 560 | trace = tc->t; |
| 561 | //if there are hooks for trace, add them here |
| 562 | |
| 563 | nb_control = ltt_trace_control_tracefile_number(trace); |
| 564 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(trace); |
| 565 | nb_tracefile = nb_control + nb_per_cpu; |
| 566 | |
| 567 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 568 | tf_s = lttv_trace_selector_tracefile_get(t_s,j); |
| 569 | selected = lttv_tracefile_selector_get_selected(tf_s); |
| 570 | if(!selected) continue; |
| 571 | |
| 572 | if(j < nb_control) |
| 573 | tfc = tc->control_tracefiles[j]; |
| 574 | else |
| 575 | tfc = tc->per_cpu_tracefiles[j - nb_control]; |
| 576 | |
| 577 | //if there are hooks for tracefile, add them here |
| 578 | // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL, |
| 579 | // statistic_viewer_data->before_event_hooks,NULL); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | //add state and stats hooks |
| 584 | state_add_event_hooks_api(statistic_viewer_data->mw); |
| 585 | stats_add_event_hooks_api(statistic_viewer_data->mw); |
| 586 | |
| 587 | } |
| 588 | |
| 589 | void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data, |
| 590 | LttvTracesetContext * tsc) |
| 591 | { |
| 592 | gint i, j, nbi, nb_tracefile, nb_control, nb_per_cpu; |
| 593 | LttTrace *trace; |
| 594 | LttvTraceContext *tc; |
| 595 | LttvTracefileContext *tfc; |
| 596 | LttvTracesetSelector * ts_s; |
| 597 | LttvTraceSelector * t_s; |
| 598 | LttvTracefileSelector * tf_s; |
| 599 | gboolean selected; |
| 600 | |
| 601 | ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v), |
| 602 | statistic_viewer_data->filter_key); |
| 603 | |
| 604 | //if there are hooks for traceset, remove them here |
| 605 | |
| 606 | nbi = lttv_traceset_number(tsc->ts); |
| 607 | for(i = 0 ; i < nbi ; i++) { |
| 608 | t_s = lttv_traceset_selector_trace_get(ts_s,i); |
| 609 | selected = lttv_trace_selector_get_selected(t_s); |
| 610 | if(!selected) continue; |
| 611 | tc = tsc->traces[i]; |
| 612 | trace = tc->t; |
| 613 | //if there are hooks for trace, remove them here |
| 614 | |
| 615 | nb_control = ltt_trace_control_tracefile_number(trace); |
| 616 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(trace); |
| 617 | nb_tracefile = nb_control + nb_per_cpu; |
| 618 | |
| 619 | for(j = 0 ; j < nb_tracefile ; j++) { |
| 620 | tf_s = lttv_trace_selector_tracefile_get(t_s,j); |
| 621 | selected = lttv_tracefile_selector_get_selected(tf_s); |
| 622 | if(!selected) continue; |
| 623 | |
| 624 | if(j < nb_control) |
| 625 | tfc = tc->control_tracefiles[j]; |
| 626 | else |
| 627 | tfc = tc->per_cpu_tracefiles[j - nb_control]; |
| 628 | |
| 629 | //if there are hooks for tracefile, remove them here |
| 630 | // lttv_tracefile_context_remove_hooks(tfc, NULL,NULL,NULL,NULL, |
| 631 | // statistic_viewer_data->before_event_hooks,NULL); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | //remove state and stats hooks |
| 636 | state_remove_event_hooks_api(statistic_viewer_data->mw); |
| 637 | stats_remove_event_hooks_api(statistic_viewer_data->mw); |
| 638 | } |
| 639 | |
| 640 | |