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