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