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