unfinished conversion of gui modules
[lttv.git] / ltt / branches / poly / 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;
134 LttvTrace *trace = (LttvTrace*)call_data;
135
55046569 136 svd->background_info_waiting--;
137
138 if(svd->background_info_waiting == 0) {
139 g_message("statistics viewer : background computation data ready.");
0af2d5b1 140
55046569 141 gtk_tree_store_clear (svd->store_m);
0af2d5b1 142
b91e751b 143 lttv_stats_sum_traceset(lttvwindow_get_traceset_stats(tab),
144 ltt_time_infinite);
55046569 145 show_traceset_stats(svd);
146 }
0af2d5b1 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 */
157static void request_background_data(StatisticViewerData *svd)
158{
159 gint num_traces = lttvwindowtraces_get_number();
160 gint i;
161 LttvTrace *trace;
55046569 162 GtkTextBuffer* buf;
0af2d5b1 163
164 LttvHooks *background_ready_hook =
165 lttv_hooks_new();
166 lttv_hooks_add(background_ready_hook, background_ready, svd,
167 LTTV_PRIO_DEFAULT);
55046569 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);
0af2d5b1 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 */
93ac601b 183 if(!lttvwindowtraces_background_request_find(trace, "stats"))
b5e17af5 184 lttvwindowtraces_background_request_queue(
185 main_window_get_widget(svd->tab), trace, "stats");
0af2d5b1 186 lttvwindowtraces_background_notify_queue(svd,
187 trace,
188 ltt_time_infinite,
189 NULL,
190 background_ready_hook);
191 } else { /* in progress */
0af2d5b1 192 lttvwindowtraces_background_notify_current(svd,
193 trace,
194 ltt_time_infinite,
195 NULL,
196 background_ready_hook);
197
198 }
c6053dc7 199 } else {
200 /* ready */
201 lttv_hooks_call(background_ready_hook, NULL);
0af2d5b1 202 }
7a859036 203 }
55046569 204
205 if(num_traces == 0) {
206 svd->background_info_waiting = 1;
207 lttv_hooks_call(background_ready_hook, NULL);
208 }
0af2d5b1 209 lttv_hooks_destroy(background_ready_hook);
210}
211
212
213GtkWidget *guistatistic_get_widget(StatisticViewerData *svd)
214{
215 return svd->hpaned_v;
6b1d3120 216}
217
0af2d5b1 218
6b1d3120 219void
10f2da95 220gui_statistic_destructor(StatisticViewerData *statistic_viewer_data)
6b1d3120 221{
0af2d5b1 222 Tab *tab = statistic_viewer_data->tab;
223
6b1d3120 224 /* May already been done by GTK window closing */
0af2d5b1 225 if(GTK_IS_WIDGET(guistatistic_get_widget(statistic_viewer_data))){
226 g_info("widget still exists");
7a859036 227 }
0af2d5b1 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);
6b1d3120 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.
10f2da95 247 * @param parent_window A pointer to the parent window.
6b1d3120 248 * @return The widget created.
249 */
250GtkWidget *
e433e6d6 251h_gui_statistic(LttvPlugin *plugin)
6b1d3120 252{
e433e6d6 253 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
254 StatisticViewerData* statistic_viewer_data = gui_statistic(ptab) ;
6b1d3120 255
10f2da95 256 if(statistic_viewer_data)
0af2d5b1 257 return guistatistic_get_widget(statistic_viewer_data);
6b1d3120 258 else return NULL;
8d70e03b 259
6b1d3120 260}
261
0af2d5b1 262#if 0
5b2cdf0e 263gboolean 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}
0af2d5b1 279#endif //0
5b2cdf0e 280
6b1d3120 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 */
287StatisticViewerData *
e433e6d6 288gui_statistic(LttvPluginTab *ptab)
6b1d3120 289{
290 GtkCellRenderer *renderer;
291 GtkTreeViewColumn *column;
292
10f2da95 293 StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1);
e433e6d6 294 Tab *tab = ptab->tab;
0af2d5b1 295 statistic_viewer_data->tab = tab;
e433e6d6 296 statistic_viewer_data->ptab = ptab;
0af2d5b1 297 // statistic_viewer_data->stats =
298 // lttvwindow_get_traceset_stats(statistic_viewer_data->tab);
299 // statistic_viewer_data->calculate_stats =
300 // statistic_insert_traceset_stats((void *)statistic_viewer_data->stats);
a8c0f09d 301
0af2d5b1 302 lttvwindow_register_traceset_notify(statistic_viewer_data->tab,
303 statistic_traceset_changed,
304 statistic_viewer_data);
fef5cbca 305
224446ce 306 statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash,
307 g_str_equal,
308 statistic_destroy_hash_key,
e025a729 309 NULL);
6b1d3120 310
10f2da95 311 statistic_viewer_data->hpaned_v = gtk_hpaned_new();
312 statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING);
224446ce 313 statistic_viewer_data->tree_v =
314 gtk_tree_view_new_with_model (
315 GTK_TREE_MODEL (statistic_viewer_data->store_m));
10f2da95 316 g_object_unref (G_OBJECT (statistic_viewer_data->store_m));
6b1d3120 317
6b1d3120 318 // Setup the selection handler
10f2da95 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",
8d70e03b 322 G_CALLBACK (tree_selection_changed_cb),
323 statistic_viewer_data);
6b1d3120 324
325 renderer = gtk_cell_renderer_text_new ();
326 column = gtk_tree_view_column_new_with_attributes ("Statistic Name",
8d70e03b 327 renderer,
328 "text", NAME_COLUMN,
329 NULL);
6b1d3120 330 gtk_tree_view_column_set_alignment (column, 0.0);
331 // gtk_tree_view_column_set_fixed_width (column, 45);
10f2da95 332 gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column);
6b1d3120 333
334
10f2da95 335 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE);
6b1d3120 336
10f2da95 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),
8d70e03b 339 GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
6b1d3120 340
10f2da95 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);
6b1d3120 344
10f2da95 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),
8d70e03b 347 GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
6b1d3120 348
10f2da95 349 statistic_viewer_data->text_v = gtk_text_view_new ();
6b1d3120 350
10f2da95 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);
6b1d3120 355
203eb6f7 356 gtk_container_set_border_width(
357 GTK_CONTAINER(statistic_viewer_data->hpaned_v), 1);
358
10f2da95 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);
6b1d3120 364
365 g_object_set_data_full(
0af2d5b1 366 G_OBJECT(guistatistic_get_widget(statistic_viewer_data)),
8d70e03b 367 "statistic_viewer_data",
368 statistic_viewer_data,
0af2d5b1 369 (GDestroyNotify)gui_statistic_destructor);
6b1d3120 370
371 /* Add the object's information to the module's array */
10f2da95 372 g_statistic_viewer_data_list = g_slist_append(
8d70e03b 373 g_statistic_viewer_data_list,
374 statistic_viewer_data);
6b1d3120 375
fef5cbca 376 request_background_data(statistic_viewer_data);
377
10f2da95 378 return statistic_viewer_data;
6b1d3120 379}
380
6b1d3120 381static void
382tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data)
383{
10f2da95 384 StatisticViewerData *statistic_viewer_data = (StatisticViewerData*)data;
6b1d3120 385 GtkTreeIter iter;
10f2da95 386 GtkTreeModel *model = GTK_TREE_MODEL(statistic_viewer_data->store_m);
387 gchar *event;
6b1d3120 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 {
10f2da95 396 gtk_tree_model_get (model, &iter, NAME_COLUMN, &event, -1);
6b1d3120 397
398 path = gtk_tree_model_get_path(GTK_TREE_MODEL(model),&iter);
399 str = gtk_tree_path_to_string (path);
10f2da95 400 stats = (LttvAttribute*)g_hash_table_lookup (statistic_viewer_data->statistic_hash,str);
6b1d3120 401 g_free(str);
402
10f2da95 403 buf = gtk_text_view_get_buffer((GtkTextView*)statistic_viewer_data->text_v);
6b1d3120 404 gtk_text_buffer_set_text(buf,"Statistic for '", -1);
405 gtk_text_buffer_get_end_iter(buf, &text_iter);
10f2da95 406 gtk_text_buffer_insert(buf, &text_iter, event, strlen(event));
6b1d3120 407 gtk_text_buffer_get_end_iter(buf, &text_iter);
408 gtk_text_buffer_insert(buf, &text_iter, "' :\n\n",5);
409
10f2da95 410 show_statistic(statistic_viewer_data, stats, buf);
6b1d3120 411
10f2da95 412 g_free (event);
6b1d3120 413 }
414}
415
2176f952 416void statistic_destroy_hash_key(gpointer key)
6b1d3120 417{
418 g_free(key);
419}
420
e025a729 421#ifdef DEBUG
0af2d5b1 422#include <stdio.h>
423extern FILE *stdin;
424extern FILE *stdout;
425extern FILE *stderr;
e025a729 426#endif //DEBUG
0af2d5b1 427
10f2da95 428void show_traceset_stats(StatisticViewerData * statistic_viewer_data)
6b1d3120 429{
0af2d5b1 430 Tab *tab = statistic_viewer_data->tab;
6b1d3120 431 int i, nb;
432 LttvTraceset *ts;
433 LttvTraceStats *tcs;
434 LttSystemDescription *desc;
0af2d5b1 435 LttvTracesetStats * tscs = lttvwindow_get_traceset_stats(tab);
6b1d3120 436 gchar * str, trace_str[PATH_LENGTH];
437 GtkTreePath * path;
438 GtkTreeIter iter;
10f2da95 439 GtkTreeStore * store = statistic_viewer_data->store_m;
6b1d3120 440
441 if(tscs->stats == NULL) return;
0af2d5b1 442#ifdef DEBUG
443 lttv_attribute_write_xml(tscs->stats, stdout, 1, 4);
444#endif //DEBUG
445
912be9a5 446 ts = tscs->parent.parent.ts;
447 nb = lttv_traceset_number(ts);
55046569 448 if(nb == 0) return;
912be9a5 449
6b1d3120 450 gtk_tree_store_append (store, &iter, NULL);
451 gtk_tree_store_set (store, &iter,
8d70e03b 452 NAME_COLUMN, "Traceset statistics",
453 -1);
454 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
6b1d3120 455 str = gtk_tree_path_to_string (path);
10f2da95 456 g_hash_table_insert(statistic_viewer_data->statistic_hash,
8d70e03b 457 (gpointer)str, tscs->stats);
10f2da95 458 show_tree(statistic_viewer_data, tscs->stats, &iter);
6b1d3120 459
460 //show stats for all traces
6b1d3120 461 for(i = 0 ; i < nb ; i++) {
462 tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]);
d730b5c8 463#if 0 //FIXME
6b1d3120 464 desc = ltt_trace_system_description(tcs->parent.parent.t);
e025a729 465 LttTime start_time = ltt_trace_system_description_trace_start_time(desc);
466 sprintf(trace_str, "Trace on system %s at time %lu.%09lu",
8d70e03b 467 ltt_trace_system_description_node_name(desc),
e025a729 468 start_time.tv_sec,
469 start_time.tv_nsec);
d730b5c8 470#endif //0
13f45ba4 471 sprintf(trace_str, g_quark_to_string(ltt_trace_name(tcs->parent.parent.t)));
6b1d3120 472 gtk_tree_store_append (store, &iter, NULL);
473 gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1);
474 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
475 str = gtk_tree_path_to_string (path);
10f2da95 476 g_hash_table_insert(statistic_viewer_data->statistic_hash,
8d70e03b 477 (gpointer)str,tcs->stats);
10f2da95 478 show_tree(statistic_viewer_data, tcs->stats, &iter);
0af2d5b1 479#ifdef DEBUG
480 lttv_attribute_write_xml(tcs->stats, stdout, 3, 4);
481#endif //DEBUG
6b1d3120 482 }
483}
484
10f2da95 485void show_tree(StatisticViewerData * statistic_viewer_data,
8d70e03b 486 LttvAttribute* stats, GtkTreeIter* parent)
6b1d3120 487{
488 int i, nb;
489 LttvAttribute *subtree;
490 LttvAttributeName name;
491 LttvAttributeValue value;
492 LttvAttributeType type;
c0cb4d12 493 gboolean is_named;
6b1d3120 494 gchar * str, dir_str[PATH_LENGTH];
495 GtkTreePath * path;
496 GtkTreeIter iter;
10f2da95 497 GtkTreeStore * store = statistic_viewer_data->store_m;
6b1d3120 498
499 nb = lttv_attribute_get_number(stats);
500 for(i = 0 ; i < nb ; i++) {
c0cb4d12 501 type = lttv_attribute_get(stats, i, &name, &value, &is_named);
6b1d3120 502 switch(type) {
503 case LTTV_GOBJECT:
504 if(LTTV_IS_ATTRIBUTE(*(value.v_gobject))) {
6b1d3120 505 subtree = (LttvAttribute *)*(value.v_gobject);
5e96e7e3 506 if(is_named)
507 sprintf(dir_str, "%s", g_quark_to_string(name));
508 else
509 sprintf(dir_str, "%u", name);
510 gtk_tree_store_append (store, &iter, parent);
511 gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1);
512 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
513 str = gtk_tree_path_to_string (path);
514 g_hash_table_insert(statistic_viewer_data->statistic_hash,
8d70e03b 515 (gpointer)str, subtree);
10f2da95 516 show_tree(statistic_viewer_data, subtree, &iter);
6b1d3120 517 }
518 break;
519 default:
8d70e03b 520 break;
6b1d3120 521 }
522 }
523}
524
10f2da95 525void show_statistic(StatisticViewerData * statistic_viewer_data,
8d70e03b 526 LttvAttribute* stats, GtkTextBuffer* buf)
6b1d3120 527{
528 int i, nb , flag;
6b1d3120 529 LttvAttributeName name;
530 LttvAttributeValue value;
531 LttvAttributeType type;
c0cb4d12 532 gboolean is_named;
6b1d3120 533 gchar type_name[PATH_LENGTH], type_value[PATH_LENGTH];
534 GtkTextIter text_iter;
535
536 flag = 0;
537 nb = lttv_attribute_get_number(stats);
538 for(i = 0 ; i < nb ; i++) {
c0cb4d12 539 type = lttv_attribute_get(stats, i, &name, &value, &is_named);
540 if(is_named)
541 sprintf(type_name,"%s", g_quark_to_string(name));
542 else
5e96e7e3 543 sprintf(type_name,"%u", name);
6b1d3120 544 type_value[0] = '\0';
545 switch(type) {
546 case LTTV_INT:
547 sprintf(type_value, " : %d\n", *value.v_int);
548 break;
549 case LTTV_UINT:
550 sprintf(type_value, " : %u\n", *value.v_uint);
551 break;
552 case LTTV_LONG:
553 sprintf(type_value, " : %ld\n", *value.v_long);
554 break;
555 case LTTV_ULONG:
556 sprintf(type_value, " : %lu\n", *value.v_ulong);
557 break;
558 case LTTV_FLOAT:
559 sprintf(type_value, " : %f\n", (double)*value.v_float);
560 break;
561 case LTTV_DOUBLE:
562 sprintf(type_value, " : %f\n", *value.v_double);
563 break;
564 case LTTV_TIME:
e025a729 565 sprintf(type_value, " : %10lu.%09lu\n", value.v_time->tv_sec,
6b1d3120 566 value.v_time->tv_nsec);
567 break;
568 case LTTV_POINTER:
569 sprintf(type_value, " : POINTER\n");
570 break;
571 case LTTV_STRING:
572 sprintf(type_value, " : %s\n", *value.v_string);
573 break;
574 default:
575 break;
576 }
577 if(strlen(type_value)){
578 flag = 1;
579 strcat(type_name,type_value);
580 gtk_text_buffer_get_end_iter(buf, &text_iter);
581 gtk_text_buffer_insert(buf, &text_iter, type_name, strlen(type_name));
582 }
583 }
584
585 if(flag == 0){
586 sprintf(type_value, "No statistic information in this directory.\nCheck in subdirectories please.\n");
587 gtk_text_buffer_get_end_iter(buf, &text_iter);
588 gtk_text_buffer_insert(buf, &text_iter, type_value, strlen(type_value));
589
590 }
591}
592
a8c0f09d 593gboolean statistic_traceset_changed(void * hook_data, void * call_data)
594{
595 StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data;
596
0af2d5b1 597 request_background_data(statistic_viewer_data);
a8c0f09d 598
599 return FALSE;
600}
601
0af2d5b1 602#if 0
a8c0f09d 603void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data,
8d70e03b 604 LttvTracesetContext * tsc)
a8c0f09d 605{
dbb7bb09 606 gint i, j, nbi, nb_tracefile;
a8c0f09d 607 LttTrace *trace;
608 LttvTraceContext *tc;
609 LttvTracefileContext *tfc;
610 LttvTracesetSelector * ts_s;
611 LttvTraceSelector * t_s;
612 LttvTracefileSelector * tf_s;
613 gboolean selected;
614
615 ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v),
8d70e03b 616 statistic_viewer_data->filter_key);
a8c0f09d 617
618 //if there are hooks for traceset, add them here
619
620 nbi = lttv_traceset_number(tsc->ts);
621 for(i = 0 ; i < nbi ; i++) {
ed3b99b6 622 t_s = lttv_traceset_selector_trace_get(ts_s,i);
a8c0f09d 623 selected = lttv_trace_selector_get_selected(t_s);
624 if(!selected) continue;
625 tc = tsc->traces[i];
626 trace = tc->t;
627 //if there are hooks for trace, add them here
628
dbb7bb09 629 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
630 ltt_trace_per_cpu_tracefile_number(trace);
a8c0f09d 631
632 for(j = 0 ; j < nb_tracefile ; j++) {
ed3b99b6 633 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
a8c0f09d 634 selected = lttv_tracefile_selector_get_selected(tf_s);
635 if(!selected) continue;
dbb7bb09 636 tfc = tc->tracefiles[j];
a8c0f09d 637
638 //if there are hooks for tracefile, add them here
639 // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL,
8d70e03b 640 // statistic_viewer_data->before_event_hooks,NULL);
a8c0f09d 641 }
642 }
643
224446ce 644 lttv_stats_add_event_hooks(LTTV_TRACESET_STATS(tsc));
a8c0f09d 645
646}
647
648void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data,
8d70e03b 649 LttvTracesetContext * tsc)
a8c0f09d 650{
dbb7bb09 651 gint i, j, nbi, nb_tracefile;
a8c0f09d 652 LttTrace *trace;
653 LttvTraceContext *tc;
654 LttvTracefileContext *tfc;
655 LttvTracesetSelector * ts_s;
656 LttvTraceSelector * t_s;
657 LttvTracefileSelector * tf_s;
658 gboolean selected;
659
660 ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v),
8d70e03b 661 statistic_viewer_data->filter_key);
a8c0f09d 662
663 //if there are hooks for traceset, remove them here
664
665 nbi = lttv_traceset_number(tsc->ts);
666 for(i = 0 ; i < nbi ; i++) {
ed3b99b6 667 t_s = lttv_traceset_selector_trace_get(ts_s,i);
a8c0f09d 668 selected = lttv_trace_selector_get_selected(t_s);
669 if(!selected) continue;
670 tc = tsc->traces[i];
671 trace = tc->t;
672 //if there are hooks for trace, remove them here
673
dbb7bb09 674 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
675 ltt_trace_per_cpu_tracefile_number(trace);
a8c0f09d 676
677 for(j = 0 ; j < nb_tracefile ; j++) {
ed3b99b6 678 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
a8c0f09d 679 selected = lttv_tracefile_selector_get_selected(tf_s);
680 if(!selected) continue;
dbb7bb09 681 tfc = tc->tracefiles[j];
a8c0f09d 682
683 //if there are hooks for tracefile, remove them here
684 // lttv_tracefile_context_remove_hooks(tfc, NULL,NULL,NULL,NULL,
8d70e03b 685 // statistic_viewer_data->before_event_hooks,NULL);
a8c0f09d 686 }
687 }
688
224446ce 689 lttv_stats_remove_event_hooks(LTTV_TRACESET_STATS(tsc));
a8c0f09d 690}
0af2d5b1 691#endif //0
6b1d3120 692
08b1c66e 693/**
694 * plugin's init function
695 *
696 * This function initializes the Statistic Viewer functionnality through the
697 * gtkTraceSet API.
698 */
699static void init() {
700
e025a729 701 lttvwindow_register_constructor("guistatistics",
702 "/",
0af2d5b1 703 "Insert Statistic Viewer",
704 hGuiStatisticInsert_xpm,
705 "Insert Statistic Viewer",
706 h_gui_statistic);
08b1c66e 707}
708
709void statistic_destroy_walk(gpointer data, gpointer user_data)
710{
0af2d5b1 711 StatisticViewerData *svd = (StatisticViewerData*)data;
712
713 g_debug("CFV.c : statistic_destroy_walk, %p", svd);
714 /* May already have been done by GTK window closing */
715 if(GTK_IS_WIDGET(guistatistic_get_widget(svd)))
716 gtk_widget_destroy(guistatistic_get_widget(svd));
08b1c66e 717}
718
719/**
720 * plugin's destroy function
721 *
722 * This function releases the memory reserved by the module and unregisters
723 * everything that has been registered in the gtkTraceSet API.
724 */
725static void destroy() {
08b1c66e 726
0af2d5b1 727 g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL );
728 g_slist_free(g_statistic_viewer_data_list);
08b1c66e 729
0af2d5b1 730 lttvwindow_unregister_constructor(h_gui_statistic);
08b1c66e 731
08b1c66e 732}
733
734
735LTTV_MODULE("guistatistics", "Statistics viewer", \
736 "Graphical module to view statistics about processes, CPUs and systems", \
db2c9c14 737 init, destroy, "lttvwindow")
08b1c66e 738
This page took 0.084094 seconds and 4 git commands to generate.