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