ce7186299af8d49959282ed74addb7ea00171b0c
[lttv.git] / lttv / modules / gui / statistics / statistics.c
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 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <glib.h>
24 #include <string.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdk.h>
27
28 #include <ltt/ltt.h>
29 #include <ltt/event.h>
30 #include <ltt/trace.h>
31
32 #include <lttv/lttv.h>
33 #include <lttv/module.h>
34 #include <lttv/tracecontext.h>
35 #include <lttv/hook.h>
36 #include <lttv/state.h>
37 #include <lttv/stats.h>
38
39 #include <lttvwindow/lttvwindow.h>
40 #include <lttvwindow/lttvwindowtraces.h>
41 #include <lttvwindow/lttv_plugin_tab.h>
42
43 #include "hGuiStatisticInsert.xpm"
44
45 #define PATH_LENGTH 256 /* CHECK */
46 #define MAX_NUMBER_EVENT "max_number_event"
47
48 //???????????????6
49 //static GPtrArray * statistic_traceset;
50
51 /** Array containing instanced objects. Used when module is unloaded */
52 static GSList *g_statistic_viewer_data_list = NULL ;
53
54 typedef struct _StatisticViewerData StatisticViewerData;
55
56 static void request_background_data(StatisticViewerData *svd);
57 GtkWidget *guistatistic_get_widget(StatisticViewerData *svd);
58
59 //! Statistic Viewer's constructor hook
60 GtkWidget *h_gui_statistic(LttvPlugin *plugin);
61 //! Statistic Viewer's constructor
62 StatisticViewerData *gui_statistic(LttvPluginTab *ptab);
63 //! Statistic Viewer's destructor
64 void gui_statistic_destructor(StatisticViewerData *statistic_viewer_data);
65
66 static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data);
67
68 void statistic_destroy_hash_key(gpointer key);
69 void statistic_destroy_hash_data(gpointer data);
70
71 void show_traceset_stats(StatisticViewerData * statistic_viewer_data);
72 void show_tree(StatisticViewerData * statistic_viewer_data,
73 LttvAttribute* stats, GtkTreeIter* parent);
74 void show_statistic(StatisticViewerData * statistic_viewer_data,
75 LttvAttribute* stats, GtkTextBuffer* buf);
76
77
78 gboolean statistic_traceset_changed(void * hook_data, void * call_data);
79 //void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data,
80 // LttvTracesetContext * tsc);
81 //void statistic_remove_context_hooks(StatisticViewerData *statistic_viewer_data,
82 // LttvTracesetContext * tsc);
83
84 //gboolean statistic_insert_traceset_stats(void * stats);
85
86 enum
87 {
88 NAME_COLUMN,
89 N_COLUMNS
90 };
91
92 struct _StatisticViewerData{
93 Tab *tab;
94 LttvPluginTab *ptab;
95 //LttvTracesetStats * stats;
96 int size;
97
98 //gboolean shown; //indicate if the statistic is shown or not
99 //char * filter_key;
100
101 GtkWidget * hpaned_v;
102 GtkTreeStore * store_m;
103 GtkWidget * tree_v;
104
105 //scroll window containing Tree View
106 GtkWidget * scroll_win_tree;
107
108 GtkWidget * text_v;
109 //scroll window containing Text View
110 GtkWidget * scroll_win_text;
111
112 // Selection handler
113 GtkTreeSelection *select_c;
114
115 //hash
116 GHashTable *statistic_hash;
117
118 guint background_info_waiting;
119 guint live_trace_count;
120 };
121
122
123
124
125 /* Action to do when background computation completed.
126 *
127 * Eventually, will have to check that every requested traces are finished
128 * before doing the redraw. It will save unnecessary processor usage.
129 */
130
131 static gint background_ready(void *hook_data, void *call_data)
132 {
133 StatisticViewerData *svd = (StatisticViewerData *)hook_data;
134 Tab *tab = svd->tab;
135
136 svd->background_info_waiting--;
137
138 if(svd->background_info_waiting == 0) {
139 g_message("statistics viewer : background computation data ready.");
140
141 gtk_tree_store_clear (svd->store_m);
142
143 lttv_stats_sum_traceset(lttvwindow_get_traceset_stats(tab),
144 ltt_time_infinite);
145 show_traceset_stats(svd);
146 }
147
148 return 0;
149 }
150
151 /* Request background computation. Verify if it is in progress or ready first.
152 *
153 * Right now, for all loaded traces.
154 *
155 * Later : must be only for each trace in the tab's traceset.
156 */
157 static void request_background_data(StatisticViewerData *svd)
158 {
159 gint num_traces = lttvwindowtraces_get_number();
160 gint i;
161 LttvTrace *trace;
162 GtkTextBuffer* buf;
163
164 LttvHooks *background_ready_hook =
165 lttv_hooks_new();
166 lttv_hooks_add(background_ready_hook, background_ready, svd,
167 LTTV_PRIO_DEFAULT);
168 svd->background_info_waiting = num_traces;
169 buf = gtk_text_view_get_buffer((GtkTextView*)svd->text_v);
170 gtk_text_buffer_set_text(buf,"", -1);
171
172 for(i=0;i<num_traces;i++) {
173 trace = lttvwindowtraces_get_trace(i);
174
175 if(lttvwindowtraces_get_ready(g_quark_from_string("stats"),trace)==FALSE) {
176
177 if(lttvwindowtraces_get_in_progress(g_quark_from_string("stats"),
178 trace) == FALSE) {
179 /* We first remove requests that could have been done for the same
180 * information. Happens when two viewers ask for it before servicing
181 * starts.
182 */
183 if(!lttvwindowtraces_background_request_find(trace, "stats"))
184 lttvwindowtraces_background_request_queue(
185 main_window_get_widget(svd->tab), trace, "stats");
186 lttvwindowtraces_background_notify_queue(svd,
187 trace,
188 ltt_time_infinite,
189 NULL,
190 background_ready_hook);
191 } else { /* in progress */
192 lttvwindowtraces_background_notify_current(svd,
193 trace,
194 ltt_time_infinite,
195 NULL,
196 background_ready_hook);
197
198 }
199 } else {
200 /* ready */
201 lttv_hooks_call(background_ready_hook, NULL);
202 }
203 }
204
205 if(num_traces == 0) {
206 svd->background_info_waiting = 1;
207 lttv_hooks_call(background_ready_hook, NULL);
208 }
209 lttv_hooks_destroy(background_ready_hook);
210 }
211
212
213 GtkWidget *guistatistic_get_widget(StatisticViewerData *svd)
214 {
215 return svd->hpaned_v;
216 }
217
218
219 void
220 gui_statistic_destructor(StatisticViewerData *statistic_viewer_data)
221 {
222 Tab *tab = statistic_viewer_data->tab;
223
224 /* May already been done by GTK window closing */
225 if(GTK_IS_WIDGET(guistatistic_get_widget(statistic_viewer_data))){
226 g_info("widget still exists");
227 }
228 if(tab != NULL) {
229 lttvwindow_unregister_traceset_notify(statistic_viewer_data->tab,
230 statistic_traceset_changed,
231 statistic_viewer_data);
232 }
233 lttvwindowtraces_background_notify_remove(statistic_viewer_data);
234
235 g_hash_table_destroy(statistic_viewer_data->statistic_hash);
236 g_statistic_viewer_data_list =
237 g_slist_remove(g_statistic_viewer_data_list, statistic_viewer_data);
238 g_free(statistic_viewer_data);
239 }
240
241
242 /**
243 * Statistic Viewer's constructor hook
244 *
245 * This constructor is given as a parameter to the menuitem and toolbar button
246 * registration. It creates the list.
247 * @param parent_window A pointer to the parent window.
248 * @return The widget created.
249 */
250 GtkWidget *
251 h_gui_statistic(LttvPlugin *plugin)
252 {
253 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
254 StatisticViewerData* statistic_viewer_data = gui_statistic(ptab) ;
255
256 if(statistic_viewer_data)
257 return guistatistic_get_widget(statistic_viewer_data);
258 else return NULL;
259
260 }
261
262 #if 0
263 gboolean statistic_insert_traceset_stats(void * stats)
264 {
265 int i, len;
266 gpointer s;
267
268 len = statistic_traceset->len;
269 for(i=0;i<len;i++){
270 s = g_ptr_array_index(statistic_traceset, i);
271 if(s == stats) break;
272 }
273 if(i==len){
274 g_ptr_array_add(statistic_traceset, stats);
275 return TRUE;
276 }
277 return FALSE;
278 }
279 #endif //0
280
281 /**
282 * Statistic Viewer's constructor
283 *
284 * This constructor is used to create StatisticViewerData data structure.
285 * @return The Statistic viewer data created.
286 */
287 StatisticViewerData *
288 gui_statistic(LttvPluginTab *ptab)
289 {
290 GtkCellRenderer *renderer;
291 GtkTreeViewColumn *column;
292
293 StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1);
294 statistic_viewer_data->live_trace_count = 0;
295 Tab *tab = ptab->tab;
296 statistic_viewer_data->tab = tab;
297 statistic_viewer_data->ptab = ptab;
298 // statistic_viewer_data->stats =
299 // lttvwindow_get_traceset_stats(statistic_viewer_data->tab);
300 // statistic_viewer_data->calculate_stats =
301 // statistic_insert_traceset_stats((void *)statistic_viewer_data->stats);
302
303 lttvwindow_register_traceset_notify(statistic_viewer_data->tab,
304 statistic_traceset_changed,
305 statistic_viewer_data);
306 statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash,
307 g_str_equal,
308 statistic_destroy_hash_key,
309 NULL);
310
311 statistic_viewer_data->hpaned_v = gtk_hpaned_new();
312 statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING);
313 statistic_viewer_data->tree_v =
314 gtk_tree_view_new_with_model (
315 GTK_TREE_MODEL (statistic_viewer_data->store_m));
316 g_object_unref (G_OBJECT (statistic_viewer_data->store_m));
317
318 // Setup the selection handler
319 statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v));
320 gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE);
321 g_signal_connect (G_OBJECT (statistic_viewer_data->select_c), "changed",
322 G_CALLBACK (tree_selection_changed_cb),
323 statistic_viewer_data);
324
325 renderer = gtk_cell_renderer_text_new ();
326 column = gtk_tree_view_column_new_with_attributes ("Statistic Name",
327 renderer,
328 "text", NAME_COLUMN,
329 NULL);
330 gtk_tree_view_column_set_alignment (column, 0.0);
331 // gtk_tree_view_column_set_fixed_width (column, 45);
332 gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column);
333
334
335 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE);
336
337 statistic_viewer_data->scroll_win_tree = gtk_scrolled_window_new (NULL, NULL);
338 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_tree),
339 GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
340
341 gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_tree), statistic_viewer_data->tree_v);
342 gtk_paned_pack1(GTK_PANED(statistic_viewer_data->hpaned_v),statistic_viewer_data->scroll_win_tree, TRUE, FALSE);
343 gtk_paned_set_position(GTK_PANED(statistic_viewer_data->hpaned_v), 160);
344
345 statistic_viewer_data->scroll_win_text = gtk_scrolled_window_new (NULL, NULL);
346 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_text),
347 GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
348
349 statistic_viewer_data->text_v = gtk_text_view_new ();
350
351 gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
352 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
353 gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v);
354 gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE);
355
356 gtk_container_set_border_width(
357 GTK_CONTAINER(statistic_viewer_data->hpaned_v), 1);
358
359 gtk_widget_show(statistic_viewer_data->scroll_win_tree);
360 gtk_widget_show(statistic_viewer_data->scroll_win_text);
361 gtk_widget_show(statistic_viewer_data->tree_v);
362 gtk_widget_show(statistic_viewer_data->text_v);
363 gtk_widget_show(statistic_viewer_data->hpaned_v);
364
365 g_object_set_data_full(
366 G_OBJECT(guistatistic_get_widget(statistic_viewer_data)),
367 "statistic_viewer_data",
368 statistic_viewer_data,
369 (GDestroyNotify)gui_statistic_destructor);
370
371 /* Add the object's information to the module's array */
372 g_statistic_viewer_data_list = g_slist_append(
373 g_statistic_viewer_data_list,
374 statistic_viewer_data);
375
376 request_background_data(statistic_viewer_data);
377
378 return statistic_viewer_data;
379 }
380
381 static void
382 tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data)
383 {
384 StatisticViewerData *statistic_viewer_data = (StatisticViewerData*)data;
385 GtkTreeIter iter;
386 GtkTreeModel *model = GTK_TREE_MODEL(statistic_viewer_data->store_m);
387 gchar *event;
388 GtkTextBuffer* buf;
389 gchar * str;
390 GtkTreePath * path;
391 GtkTextIter text_iter;
392 LttvAttribute * stats;
393
394 if (gtk_tree_selection_get_selected (selection, &model, &iter))
395 {
396 gtk_tree_model_get (model, &iter, NAME_COLUMN, &event, -1);
397
398 path = gtk_tree_model_get_path(GTK_TREE_MODEL(model),&iter);
399 str = gtk_tree_path_to_string (path);
400 stats = (LttvAttribute*)g_hash_table_lookup (statistic_viewer_data->statistic_hash,str);
401 g_free(str);
402
403 buf = gtk_text_view_get_buffer((GtkTextView*)statistic_viewer_data->text_v);
404 gtk_text_buffer_set_text(buf,"Statistic for '", -1);
405 gtk_text_buffer_get_end_iter(buf, &text_iter);
406 gtk_text_buffer_insert(buf, &text_iter, event, strlen(event));
407 gtk_text_buffer_get_end_iter(buf, &text_iter);
408 gtk_text_buffer_insert(buf, &text_iter, "' :\n\n",5);
409
410 show_statistic(statistic_viewer_data, stats, buf);
411
412 g_free (event);
413 }
414 }
415
416 void statistic_destroy_hash_key(gpointer key)
417 {
418 g_free(key);
419 }
420
421 #ifdef DEBUG
422 #include <stdio.h>
423 extern FILE *stdin;
424 extern FILE *stdout;
425 extern FILE *stderr;
426 #endif //DEBUG
427
428 static const char *live_msg = "Statistics for traceset containing live traces are inaccurate";
429
430 void show_traceset_stats(StatisticViewerData * statistic_viewer_data)
431 {
432 Tab *tab = statistic_viewer_data->tab;
433 int i, nb;
434 LttvTraceset *ts;
435 LttvTraceStats *tcs;
436 LttvTracesetStats * tscs = lttvwindow_get_traceset_stats(tab);
437 gchar * str, trace_str[PATH_LENGTH];
438 GtkTreePath * path;
439 GtkTreeIter iter;
440 GtkTreeStore * store = statistic_viewer_data->store_m;
441
442 if(tscs->stats == NULL) return;
443 #ifdef DEBUG
444 lttv_attribute_write_xml(tscs->stats, stdout, 1, 4);
445 #endif //DEBUG
446
447 ts = tscs->parent.parent.ts;
448 nb = lttv_traceset_number(ts);
449 if(nb == 0) return;
450
451 gtk_tree_store_append (store, &iter, NULL);
452 gtk_tree_store_set (store, &iter,
453 NAME_COLUMN, "Traceset statistics",
454 -1);
455 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
456 str = gtk_tree_path_to_string (path);
457
458 for(i = 0 ; i < nb ; i++) {
459 if (LTTV_TRACESET_CONTEXT(tscs)->traces[i]->t->is_live) {
460 statistic_viewer_data->live_trace_count++;
461 }
462
463 }
464 if (statistic_viewer_data->live_trace_count) {
465 LttvAttributeValue value;
466 value = lttv_attribute_add(tscs->stats,
467 g_quark_from_static_string("WARNING: Live traceset"),
468 LTTV_STRING);
469 *(value.v_string) = live_msg;
470
471 }
472 g_hash_table_insert(statistic_viewer_data->statistic_hash,
473 (gpointer)str, tscs->stats);
474 show_tree(statistic_viewer_data, tscs->stats, &iter);
475
476 //show stats for all traces
477 for(i = 0 ; i < nb ; i++) {
478 tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]);
479 #if 0 //FIXME
480 desc = ltt_trace_system_description(tcs->parent.parent.t);
481 LttTime start_time = ltt_trace_system_description_trace_start_time(desc);
482 sprintf(trace_str, "Trace on system %s at time %lu.%09lu",
483 ltt_trace_system_description_node_name(desc),
484 start_time.tv_sec,
485 start_time.tv_nsec);
486 #endif //0
487 sprintf(trace_str, "%s", g_quark_to_string(ltt_trace_name(tcs->parent.parent.t)));
488 /* TODO ybrosseau 2011-01-12: Reenable stats for live trace */
489 if (LTTV_TRACE_CONTEXT(tcs)->t->is_live) {
490 strcat(trace_str, " [LIVE]");
491 gtk_tree_store_append (store, &iter, NULL);
492 gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1);
493
494 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
495 str = gtk_tree_path_to_string (path);
496 g_hash_table_insert(statistic_viewer_data->statistic_hash,
497 (gpointer)str,0);
498
499 } else {
500
501 gtk_tree_store_append (store, &iter, NULL);
502 gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1);
503 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
504 str = gtk_tree_path_to_string (path);
505 g_hash_table_insert(statistic_viewer_data->statistic_hash,
506 (gpointer)str,tcs->stats);
507 show_tree(statistic_viewer_data, tcs->stats, &iter);
508 #ifdef DEBUG
509 lttv_attribute_write_xml(tcs->stats, stdout, 3, 4);
510 #endif //DEBUG
511 }
512 }
513 }
514
515 void show_tree(StatisticViewerData * statistic_viewer_data,
516 LttvAttribute* stats, GtkTreeIter* parent)
517 {
518 int i, nb;
519 LttvAttribute *subtree;
520 LttvAttributeName name;
521 LttvAttributeValue value;
522 LttvAttributeType type;
523 gboolean is_named;
524 gchar * str, dir_str[PATH_LENGTH];
525 GtkTreePath * path;
526 GtkTreeIter iter;
527 GtkTreeStore * store = statistic_viewer_data->store_m;
528
529 nb = lttv_attribute_get_number(stats);
530 for(i = 0 ; i < nb ; i++) {
531 type = lttv_attribute_get(stats, i, &name, &value, &is_named);
532 switch(type) {
533 case LTTV_GOBJECT:
534 if(LTTV_IS_ATTRIBUTE(*(value.v_gobject))) {
535 subtree = (LttvAttribute *)*(value.v_gobject);
536 if(is_named)
537 sprintf(dir_str, "%s", g_quark_to_string(name));
538 else
539 sprintf(dir_str, "%u", name);
540 gtk_tree_store_append (store, &iter, parent);
541 gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1);
542 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
543 str = gtk_tree_path_to_string (path);
544 g_hash_table_insert(statistic_viewer_data->statistic_hash,
545 (gpointer)str, subtree);
546 show_tree(statistic_viewer_data, subtree, &iter);
547 }
548 break;
549 default:
550 break;
551 }
552 }
553 }
554
555 void show_statistic(StatisticViewerData * statistic_viewer_data,
556 LttvAttribute* stats, GtkTextBuffer* buf)
557 {
558 int i, nb = 0, flag;
559 LttvAttributeName name;
560 LttvAttributeValue value;
561 LttvAttributeType type;
562 gboolean is_named;
563 gchar type_name[PATH_LENGTH], type_value[PATH_LENGTH];
564 GtkTextIter text_iter;
565
566 flag = 0;
567 if(stats) {
568 nb = lttv_attribute_get_number(stats);
569 }
570 for(i = 0 ; i < nb ; i++) {
571 type = lttv_attribute_get(stats, i, &name, &value, &is_named);
572 if(is_named)
573 sprintf(type_name,"%s", g_quark_to_string(name));
574 else
575 sprintf(type_name,"%u", name);
576 type_value[0] = '\0';
577 switch(type) {
578 case LTTV_INT:
579 sprintf(type_value, " : %d\n", *value.v_int);
580 break;
581 case LTTV_UINT:
582 sprintf(type_value, " : %u\n", *value.v_uint);
583 break;
584 case LTTV_LONG:
585 sprintf(type_value, " : %ld\n", *value.v_long);
586 break;
587 case LTTV_ULONG:
588 sprintf(type_value, " : %lu\n", *value.v_ulong);
589 break;
590 case LTTV_FLOAT:
591 sprintf(type_value, " : %f\n", (double)*value.v_float);
592 break;
593 case LTTV_DOUBLE:
594 sprintf(type_value, " : %f\n", *value.v_double);
595 break;
596 case LTTV_TIME:
597 sprintf(type_value, " : %10lu.%09lu\n", value.v_time->tv_sec,
598 value.v_time->tv_nsec);
599 break;
600 case LTTV_POINTER:
601 sprintf(type_value, " : POINTER\n");
602 break;
603 case LTTV_STRING:
604 sprintf(type_value, " : %s\n", *value.v_string);
605 break;
606 default:
607 break;
608 }
609 if(strlen(type_value)){
610 flag = 1;
611 strcat(type_name,type_value);
612 gtk_text_buffer_get_end_iter(buf, &text_iter);
613 gtk_text_buffer_insert(buf, &text_iter, type_name, strlen(type_name));
614 }
615 }
616
617 if(flag == 0){
618 sprintf(type_value, "No statistic information in this directory.\nCheck in subdirectories please.\n");
619 gtk_text_buffer_get_end_iter(buf, &text_iter);
620 gtk_text_buffer_insert(buf, &text_iter, type_value, strlen(type_value));
621
622 }
623 }
624
625 gboolean statistic_traceset_changed(void * hook_data, void * call_data)
626 {
627 StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data;
628
629 request_background_data(statistic_viewer_data);
630
631 return FALSE;
632 }
633
634 #if 0
635 void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data,
636 LttvTracesetContext * tsc)
637 {
638 gint i, j, nbi, nb_tracefile;
639 LttTrace *trace;
640 LttvTraceContext *tc;
641 LttvTracefileContext *tfc;
642 LttvTracesetSelector * ts_s;
643 LttvTraceSelector * t_s;
644 LttvTracefileSelector * tf_s;
645 gboolean selected;
646
647 ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v),
648 statistic_viewer_data->filter_key);
649
650 //if there are hooks for traceset, add them here
651
652 nbi = lttv_traceset_number(tsc->ts);
653 for(i = 0 ; i < nbi ; i++) {
654 t_s = lttv_traceset_selector_trace_get(ts_s,i);
655 selected = lttv_trace_selector_get_selected(t_s);
656 if(!selected) continue;
657 tc = tsc->traces[i];
658 trace = tc->t;
659 //if there are hooks for trace, add them here
660
661 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
662 ltt_trace_per_cpu_tracefile_number(trace);
663
664 for(j = 0 ; j < nb_tracefile ; j++) {
665 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
666 selected = lttv_tracefile_selector_get_selected(tf_s);
667 if(!selected) continue;
668 tfc = tc->tracefiles[j];
669
670 //if there are hooks for tracefile, add them here
671 // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL,
672 // statistic_viewer_data->before_event_hooks,NULL);
673 }
674 }
675
676 lttv_stats_add_event_hooks(LTTV_TRACESET_STATS(tsc));
677
678 }
679
680 void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data,
681 LttvTracesetContext * tsc)
682 {
683 gint i, j, nbi, nb_tracefile;
684 LttTrace *trace;
685 LttvTraceContext *tc;
686 LttvTracefileContext *tfc;
687 LttvTracesetSelector * ts_s;
688 LttvTraceSelector * t_s;
689 LttvTracefileSelector * tf_s;
690 gboolean selected;
691
692 ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v),
693 statistic_viewer_data->filter_key);
694
695 //if there are hooks for traceset, remove them here
696
697 nbi = lttv_traceset_number(tsc->ts);
698 for(i = 0 ; i < nbi ; i++) {
699 t_s = lttv_traceset_selector_trace_get(ts_s,i);
700 selected = lttv_trace_selector_get_selected(t_s);
701 if(!selected) continue;
702 tc = tsc->traces[i];
703 trace = tc->t;
704 //if there are hooks for trace, remove them here
705
706 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
707 ltt_trace_per_cpu_tracefile_number(trace);
708
709 for(j = 0 ; j < nb_tracefile ; j++) {
710 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
711 selected = lttv_tracefile_selector_get_selected(tf_s);
712 if(!selected) continue;
713 tfc = tc->tracefiles[j];
714
715 //if there are hooks for tracefile, remove them here
716 // lttv_tracefile_context_remove_hooks(tfc, NULL,NULL,NULL,NULL,
717 // statistic_viewer_data->before_event_hooks,NULL);
718 }
719 }
720
721 lttv_stats_remove_event_hooks(LTTV_TRACESET_STATS(tsc));
722 }
723 #endif //0
724
725 /**
726 * plugin's init function
727 *
728 * This function initializes the Statistic Viewer functionnality through the
729 * gtkTraceSet API.
730 */
731 static void init() {
732
733 lttvwindow_register_constructor("guistatistics",
734 "/",
735 "Insert Statistic Viewer",
736 hGuiStatisticInsert_xpm,
737 "Insert Statistic Viewer",
738 h_gui_statistic);
739 }
740
741 void statistic_destroy_walk(gpointer data, gpointer user_data)
742 {
743 StatisticViewerData *svd = (StatisticViewerData*)data;
744
745 g_debug("CFV.c : statistic_destroy_walk, %p", svd);
746 /* May already have been done by GTK window closing */
747 if(GTK_IS_WIDGET(guistatistic_get_widget(svd)))
748 gtk_widget_destroy(guistatistic_get_widget(svd));
749 }
750
751 /**
752 * plugin's destroy function
753 *
754 * This function releases the memory reserved by the module and unregisters
755 * everything that has been registered in the gtkTraceSet API.
756 */
757 static void destroy() {
758
759 g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL );
760 g_slist_free(g_statistic_viewer_data_list);
761
762 lttvwindow_unregister_constructor(h_gui_statistic);
763
764 }
765
766
767 LTTV_MODULE("guistatistics", "Statistics viewer", \
768 "Graphical module to view statistics about processes, CPUs and systems", \
769 init, destroy, "lttvwindow")
770
This page took 0.051102 seconds and 3 git commands to generate.