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