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> |
20 | #include <gmodule.h> |
21 | #include <gtk/gtk.h> |
22 | #include <gdk/gdk.h> |
23 | |
2a2fa4f0 |
24 | #include <lttv/lttv.h> |
6b1d3120 |
25 | #include <lttv/module.h> |
cef97e7c |
26 | #include <lttv/gtktraceset.h> |
6b1d3120 |
27 | #include <lttv/processTrace.h> |
28 | #include <lttv/hook.h> |
29 | #include <lttv/common.h> |
30 | #include <lttv/state.h> |
31 | #include <lttv/stats.h> |
32 | |
33 | #include <ltt/ltt.h> |
34 | #include <ltt/event.h> |
35 | #include <ltt/type.h> |
36 | #include <ltt/trace.h> |
37 | |
38 | #include <string.h> |
39 | |
40 | #include "../icons/hGuiStatisticInsert.xpm" |
41 | |
dbb7bb09 |
42 | #define PATH_LENGTH 256 /* CHECK */ |
6b1d3120 |
43 | |
10f2da95 |
44 | static LttvModule *statistic_main_win_module; |
5b2cdf0e |
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 | |
52 | //! Statistic Viewer's constructor hook |
49bf71b5 |
53 | GtkWidget *h_gui_statistic(MainWindow *parent_window, LttvTracesetSelector * s, char* key); |
6b1d3120 |
54 | //! Statistic Viewer's constructor |
49bf71b5 |
55 | StatisticViewerData *gui_statistic(MainWindow *parent_window,LttvTracesetSelector * s, char* key); |
6b1d3120 |
56 | //! Statistic Viewer's destructor |
10f2da95 |
57 | void gui_statistic_destructor(StatisticViewerData *statistic_viewer_data); |
58 | void gui_statistic_free(StatisticViewerData *statistic_viewer_data); |
6b1d3120 |
59 | |
60 | void grab_focus(GtkWidget *widget, gpointer data); |
61 | static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data); |
62 | |
2176f952 |
63 | void statistic_destroy_hash_key(gpointer key); |
64 | void statistic_destroy_hash_data(gpointer data); |
6b1d3120 |
65 | |
10f2da95 |
66 | void show_traceset_stats(StatisticViewerData * statistic_viewer_data); |
67 | void show_tree(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
68 | LttvAttribute* stats, GtkTreeIter* parent); |
10f2da95 |
69 | void show_statistic(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
70 | LttvAttribute* stats, GtkTextBuffer* buf); |
6b1d3120 |
71 | |
72 | |
a8c0f09d |
73 | /** hook functions for update time interval, current time ... */ |
74 | gboolean statistic_update_time_window(void * hook_data, void * call_data); |
75 | gboolean statistic_show_viewer(void * hook_data, void * call_data); |
76 | gboolean statistic_traceset_changed(void * hook_data, void * call_data); |
77 | void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
78 | LttvTracesetContext * tsc); |
a8c0f09d |
79 | void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
80 | LttvTracesetContext * tsc); |
a8c0f09d |
81 | |
5b2cdf0e |
82 | gboolean statistic_insert_traceset_stats(void * stats); |
83 | |
6b1d3120 |
84 | enum |
85 | { |
86 | NAME_COLUMN, |
87 | N_COLUMNS |
88 | }; |
89 | |
90 | struct _StatisticViewerData{ |
bca3b81f |
91 | MainWindow * mw; |
6b1d3120 |
92 | LttvTracesetStats * stats; |
5b2cdf0e |
93 | gboolean calculate_stats; |
94 | int size; |
6b1d3120 |
95 | |
a8c0f09d |
96 | TimeInterval time_span; |
97 | gboolean shown; //indicate if the statistic is shown or not |
98 | char * filter_key; |
99 | |
10f2da95 |
100 | GtkWidget * hpaned_v; |
101 | GtkTreeStore * store_m; |
102 | GtkWidget * tree_v; |
6b1d3120 |
103 | |
104 | //scroll window containing Tree View |
10f2da95 |
105 | GtkWidget * scroll_win_tree; |
6b1d3120 |
106 | |
10f2da95 |
107 | GtkWidget * text_v; |
6b1d3120 |
108 | //scroll window containing Text View |
10f2da95 |
109 | GtkWidget * scroll_win_text; |
6b1d3120 |
110 | |
111 | // Selection handler |
10f2da95 |
112 | GtkTreeSelection *select_c; |
6b1d3120 |
113 | |
114 | //hash |
10f2da95 |
115 | GHashTable *statistic_hash; |
6b1d3120 |
116 | }; |
117 | |
118 | |
119 | /** |
120 | * plugin's init function |
121 | * |
122 | * This function initializes the Statistic Viewer functionnality through the |
123 | * gtkTraceSet API. |
124 | */ |
125 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
126 | |
10f2da95 |
127 | statistic_main_win_module = lttv_module_require(self, "mainwin", argc, argv); |
6b1d3120 |
128 | |
10f2da95 |
129 | if(statistic_main_win_module == NULL){ |
6b1d3120 |
130 | g_critical("Can't load Statistic Viewer : missing mainwin\n"); |
131 | return; |
132 | } |
5b2cdf0e |
133 | |
134 | statistic_traceset = g_ptr_array_new (); |
135 | |
6b1d3120 |
136 | /* Register the toolbar insert button */ |
41a76985 |
137 | toolbar_item_reg(hGuiStatisticInsert_xpm, "Insert Statistic Viewer", h_gui_statistic); |
6b1d3120 |
138 | |
139 | /* Register the menu item insert entry */ |
41a76985 |
140 | menu_item_reg("/", "Insert Statistic Viewer", h_gui_statistic); |
6b1d3120 |
141 | |
142 | } |
143 | |
2176f952 |
144 | void statistic_destroy_walk(gpointer data, gpointer user_data) |
6b1d3120 |
145 | { |
10f2da95 |
146 | gui_statistic_destructor((StatisticViewerData*)data); |
6b1d3120 |
147 | } |
148 | |
149 | /** |
150 | * plugin's destroy function |
151 | * |
152 | * This function releases the memory reserved by the module and unregisters |
153 | * everything that has been registered in the gtkTraceSet API. |
154 | */ |
155 | G_MODULE_EXPORT void destroy() { |
156 | int i; |
157 | |
10f2da95 |
158 | if(g_statistic_viewer_data_list){ |
159 | g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL ); |
160 | g_slist_free(g_statistic_viewer_data_list); |
2176f952 |
161 | } |
5b2cdf0e |
162 | g_ptr_array_free (statistic_traceset, TRUE); |
6b1d3120 |
163 | |
164 | /* Unregister the toolbar insert button */ |
41a76985 |
165 | toolbar_item_unreg(h_gui_statistic); |
8d70e03b |
166 | |
6b1d3120 |
167 | /* Unregister the menu item insert entry */ |
41a76985 |
168 | menu_item_unreg(h_gui_statistic); |
6b1d3120 |
169 | } |
170 | |
171 | |
172 | void |
10f2da95 |
173 | gui_statistic_free(StatisticViewerData *statistic_viewer_data) |
6b1d3120 |
174 | { |
10f2da95 |
175 | if(statistic_viewer_data){ |
a8c0f09d |
176 | unreg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); |
177 | unreg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); |
178 | unreg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); |
179 | |
10f2da95 |
180 | g_hash_table_destroy(statistic_viewer_data->statistic_hash); |
a8c0f09d |
181 | g_free(statistic_viewer_data->filter_key); |
10f2da95 |
182 | g_statistic_viewer_data_list = g_slist_remove(g_statistic_viewer_data_list, statistic_viewer_data); |
183 | g_free(statistic_viewer_data); |
7a859036 |
184 | } |
6b1d3120 |
185 | } |
186 | |
187 | void |
10f2da95 |
188 | gui_statistic_destructor(StatisticViewerData *statistic_viewer_data) |
6b1d3120 |
189 | { |
190 | /* May already been done by GTK window closing */ |
10f2da95 |
191 | if(GTK_IS_WIDGET(statistic_viewer_data->hpaned_v)){ |
e4d09234 |
192 | gui_statistic_free(statistic_viewer_data); |
10f2da95 |
193 | gtk_widget_destroy(statistic_viewer_data->hpaned_v); |
194 | statistic_viewer_data = NULL; |
7a859036 |
195 | } |
10f2da95 |
196 | //gui_statistic_free(statistic_viewer_data); |
6b1d3120 |
197 | } |
198 | |
199 | |
200 | /** |
201 | * Statistic Viewer's constructor hook |
202 | * |
203 | * This constructor is given as a parameter to the menuitem and toolbar button |
204 | * registration. It creates the list. |
10f2da95 |
205 | * @param parent_window A pointer to the parent window. |
6b1d3120 |
206 | * @return The widget created. |
207 | */ |
208 | GtkWidget * |
49bf71b5 |
209 | h_gui_statistic(MainWindow * parent_window, LttvTracesetSelector * s, char* key) |
6b1d3120 |
210 | { |
49bf71b5 |
211 | StatisticViewerData* statistic_viewer_data = gui_statistic(parent_window, s, key) ; |
6b1d3120 |
212 | |
10f2da95 |
213 | if(statistic_viewer_data) |
214 | return statistic_viewer_data->hpaned_v; |
6b1d3120 |
215 | else return NULL; |
8d70e03b |
216 | |
6b1d3120 |
217 | } |
218 | |
5b2cdf0e |
219 | gboolean statistic_insert_traceset_stats(void * stats) |
220 | { |
221 | int i, len; |
222 | gpointer s; |
223 | |
224 | len = statistic_traceset->len; |
225 | for(i=0;i<len;i++){ |
226 | s = g_ptr_array_index(statistic_traceset, i); |
227 | if(s == stats) break; |
228 | } |
229 | if(i==len){ |
230 | g_ptr_array_add(statistic_traceset, stats); |
231 | return TRUE; |
232 | } |
233 | return FALSE; |
234 | } |
235 | |
6b1d3120 |
236 | /** |
237 | * Statistic Viewer's constructor |
238 | * |
239 | * This constructor is used to create StatisticViewerData data structure. |
240 | * @return The Statistic viewer data created. |
241 | */ |
242 | StatisticViewerData * |
49bf71b5 |
243 | gui_statistic(MainWindow *parent_window, LttvTracesetSelector * s, char* key) |
6b1d3120 |
244 | { |
245 | GtkCellRenderer *renderer; |
246 | GtkTreeViewColumn *column; |
247 | |
10f2da95 |
248 | StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1); |
6b1d3120 |
249 | |
10f2da95 |
250 | statistic_viewer_data->mw = parent_window; |
41a76985 |
251 | statistic_viewer_data->stats = get_traceset_stats_api(statistic_viewer_data->mw); |
5b2cdf0e |
252 | statistic_viewer_data->calculate_stats = statistic_insert_traceset_stats((void *)statistic_viewer_data->stats); |
6b1d3120 |
253 | |
a8c0f09d |
254 | reg_update_time_window(statistic_update_time_window,statistic_viewer_data, statistic_viewer_data->mw); |
255 | reg_show_viewer(statistic_show_viewer,statistic_viewer_data, statistic_viewer_data->mw); |
256 | reg_update_traceset(statistic_traceset_changed,statistic_viewer_data, statistic_viewer_data->mw); |
257 | |
10f2da95 |
258 | statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash, g_str_equal, |
8d70e03b |
259 | statistic_destroy_hash_key, |
260 | statistic_destroy_hash_data); |
6b1d3120 |
261 | |
10f2da95 |
262 | statistic_viewer_data->hpaned_v = gtk_hpaned_new(); |
263 | statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING); |
264 | statistic_viewer_data->tree_v = gtk_tree_view_new_with_model (GTK_TREE_MODEL (statistic_viewer_data->store_m)); |
265 | g_object_unref (G_OBJECT (statistic_viewer_data->store_m)); |
6b1d3120 |
266 | |
10f2da95 |
267 | g_signal_connect (G_OBJECT (statistic_viewer_data->tree_v), "grab-focus", |
8d70e03b |
268 | G_CALLBACK (grab_focus), |
269 | statistic_viewer_data); |
6b1d3120 |
270 | |
271 | // Setup the selection handler |
10f2da95 |
272 | statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v)); |
273 | gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE); |
274 | g_signal_connect (G_OBJECT (statistic_viewer_data->select_c), "changed", |
8d70e03b |
275 | G_CALLBACK (tree_selection_changed_cb), |
276 | statistic_viewer_data); |
6b1d3120 |
277 | |
278 | renderer = gtk_cell_renderer_text_new (); |
279 | column = gtk_tree_view_column_new_with_attributes ("Statistic Name", |
8d70e03b |
280 | renderer, |
281 | "text", NAME_COLUMN, |
282 | NULL); |
6b1d3120 |
283 | gtk_tree_view_column_set_alignment (column, 0.0); |
284 | // gtk_tree_view_column_set_fixed_width (column, 45); |
10f2da95 |
285 | gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column); |
6b1d3120 |
286 | |
287 | |
10f2da95 |
288 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE); |
6b1d3120 |
289 | |
10f2da95 |
290 | statistic_viewer_data->scroll_win_tree = gtk_scrolled_window_new (NULL, NULL); |
291 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_tree), |
8d70e03b |
292 | GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); |
6b1d3120 |
293 | |
10f2da95 |
294 | gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_tree), statistic_viewer_data->tree_v); |
295 | gtk_paned_pack1(GTK_PANED(statistic_viewer_data->hpaned_v),statistic_viewer_data->scroll_win_tree, TRUE, FALSE); |
296 | gtk_paned_set_position(GTK_PANED(statistic_viewer_data->hpaned_v), 160); |
6b1d3120 |
297 | |
10f2da95 |
298 | statistic_viewer_data->scroll_win_text = gtk_scrolled_window_new (NULL, NULL); |
299 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_text), |
8d70e03b |
300 | GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); |
6b1d3120 |
301 | |
10f2da95 |
302 | statistic_viewer_data->text_v = gtk_text_view_new (); |
303 | g_signal_connect (G_OBJECT (statistic_viewer_data->text_v), "grab-focus", |
8d70e03b |
304 | G_CALLBACK (grab_focus), |
305 | statistic_viewer_data); |
6b1d3120 |
306 | |
10f2da95 |
307 | gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); |
308 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); |
309 | gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v); |
310 | gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE); |
6b1d3120 |
311 | |
10f2da95 |
312 | gtk_widget_show(statistic_viewer_data->scroll_win_tree); |
313 | gtk_widget_show(statistic_viewer_data->scroll_win_text); |
314 | gtk_widget_show(statistic_viewer_data->tree_v); |
315 | gtk_widget_show(statistic_viewer_data->text_v); |
316 | gtk_widget_show(statistic_viewer_data->hpaned_v); |
6b1d3120 |
317 | |
a8c0f09d |
318 | //get the life span of the traceset and set the upper of the scroll bar |
319 | get_traceset_time_span(statistic_viewer_data->mw, &statistic_viewer_data->time_span); |
320 | |
321 | statistic_viewer_data->shown = FALSE; |
322 | statistic_viewer_data->filter_key = g_strdup(key); |
49bf71b5 |
323 | g_object_set_data( |
8d70e03b |
324 | G_OBJECT(statistic_viewer_data->hpaned_v), |
325 | statistic_viewer_data->filter_key, |
326 | s); |
49bf71b5 |
327 | |
a8c0f09d |
328 | g_object_set_data( |
8d70e03b |
329 | G_OBJECT(statistic_viewer_data->hpaned_v), |
330 | TRACESET_TIME_SPAN, |
331 | &statistic_viewer_data->time_span); |
9f797243 |
332 | |
333 | if(statistic_viewer_data->calculate_stats){ |
334 | if(lttv_stats_load_statistics(statistic_viewer_data->stats)) |
335 | statistic_viewer_data->calculate_stats = FALSE; |
336 | } |
a8c0f09d |
337 | |
5b2cdf0e |
338 | if(statistic_viewer_data->calculate_stats == FALSE){ |
339 | statistic_viewer_data->size = 1; |
340 | g_object_set_data( |
8d70e03b |
341 | G_OBJECT(statistic_viewer_data->hpaned_v), |
342 | MAX_NUMBER_EVENT, |
343 | &statistic_viewer_data->size); |
5b2cdf0e |
344 | } |
345 | |
6b1d3120 |
346 | g_object_set_data_full( |
8d70e03b |
347 | G_OBJECT(statistic_viewer_data->hpaned_v), |
348 | "statistic_viewer_data", |
349 | statistic_viewer_data, |
350 | (GDestroyNotify)gui_statistic_free); |
6b1d3120 |
351 | |
352 | /* Add the object's information to the module's array */ |
10f2da95 |
353 | g_statistic_viewer_data_list = g_slist_append( |
8d70e03b |
354 | g_statistic_viewer_data_list, |
355 | statistic_viewer_data); |
6b1d3120 |
356 | |
10f2da95 |
357 | return statistic_viewer_data; |
6b1d3120 |
358 | } |
359 | |
360 | void grab_focus(GtkWidget *widget, gpointer data) |
361 | { |
10f2da95 |
362 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData *)data; |
bca3b81f |
363 | MainWindow * mw = statistic_viewer_data->mw; |
41a76985 |
364 | set_focused_pane(mw, gtk_widget_get_parent(statistic_viewer_data->hpaned_v)); |
6b1d3120 |
365 | } |
366 | |
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 | |
2176f952 |
407 | void statistic_destroy_hash_data(gpointer data) |
6b1d3120 |
408 | { |
409 | // g_free(data); |
410 | } |
411 | |
10f2da95 |
412 | void show_traceset_stats(StatisticViewerData * statistic_viewer_data) |
6b1d3120 |
413 | { |
414 | int i, nb; |
415 | LttvTraceset *ts; |
416 | LttvTraceStats *tcs; |
417 | LttSystemDescription *desc; |
10f2da95 |
418 | LttvTracesetStats * tscs = statistic_viewer_data->stats; |
6b1d3120 |
419 | gchar * str, trace_str[PATH_LENGTH]; |
420 | GtkTreePath * path; |
421 | GtkTreeIter iter; |
10f2da95 |
422 | GtkTreeStore * store = statistic_viewer_data->store_m; |
6b1d3120 |
423 | |
424 | if(tscs->stats == NULL) return; |
425 | |
912be9a5 |
426 | ts = tscs->parent.parent.ts; |
427 | nb = lttv_traceset_number(ts); |
428 | if(nb == 0)return; |
429 | |
6b1d3120 |
430 | gtk_tree_store_append (store, &iter, NULL); |
431 | gtk_tree_store_set (store, &iter, |
8d70e03b |
432 | NAME_COLUMN, "Traceset statistics", |
433 | -1); |
434 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
6b1d3120 |
435 | str = gtk_tree_path_to_string (path); |
10f2da95 |
436 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
8d70e03b |
437 | (gpointer)str, tscs->stats); |
10f2da95 |
438 | show_tree(statistic_viewer_data, tscs->stats, &iter); |
6b1d3120 |
439 | |
440 | //show stats for all traces |
6b1d3120 |
441 | for(i = 0 ; i < nb ; i++) { |
442 | tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]); |
443 | desc = ltt_trace_system_description(tcs->parent.parent.t); |
444 | sprintf(trace_str, "Trace on system %s at time %d secs", |
8d70e03b |
445 | ltt_trace_system_description_node_name(desc), |
446 | (ltt_trace_system_description_trace_start_time(desc)).tv_sec); |
6b1d3120 |
447 | |
448 | gtk_tree_store_append (store, &iter, NULL); |
449 | gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1); |
450 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
451 | str = gtk_tree_path_to_string (path); |
10f2da95 |
452 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
8d70e03b |
453 | (gpointer)str,tcs->stats); |
10f2da95 |
454 | show_tree(statistic_viewer_data, tcs->stats, &iter); |
6b1d3120 |
455 | } |
456 | } |
457 | |
10f2da95 |
458 | void show_tree(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
459 | LttvAttribute* stats, GtkTreeIter* parent) |
6b1d3120 |
460 | { |
461 | int i, nb; |
462 | LttvAttribute *subtree; |
463 | LttvAttributeName name; |
464 | LttvAttributeValue value; |
465 | LttvAttributeType type; |
466 | gchar * str, dir_str[PATH_LENGTH]; |
467 | GtkTreePath * path; |
468 | GtkTreeIter iter; |
10f2da95 |
469 | GtkTreeStore * store = statistic_viewer_data->store_m; |
6b1d3120 |
470 | |
471 | nb = lttv_attribute_get_number(stats); |
472 | for(i = 0 ; i < nb ; i++) { |
473 | type = lttv_attribute_get(stats, i, &name, &value); |
474 | switch(type) { |
475 | case LTTV_GOBJECT: |
476 | if(LTTV_IS_ATTRIBUTE(*(value.v_gobject))) { |
8d70e03b |
477 | sprintf(dir_str, "%s", g_quark_to_string(name)); |
6b1d3120 |
478 | subtree = (LttvAttribute *)*(value.v_gobject); |
8d70e03b |
479 | gtk_tree_store_append (store, &iter, parent); |
480 | gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1); |
481 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
482 | str = gtk_tree_path_to_string (path); |
483 | g_hash_table_insert(statistic_viewer_data->statistic_hash, |
484 | (gpointer)str, subtree); |
10f2da95 |
485 | show_tree(statistic_viewer_data, subtree, &iter); |
6b1d3120 |
486 | } |
487 | break; |
488 | default: |
8d70e03b |
489 | break; |
6b1d3120 |
490 | } |
491 | } |
492 | } |
493 | |
10f2da95 |
494 | void show_statistic(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
495 | LttvAttribute* stats, GtkTextBuffer* buf) |
6b1d3120 |
496 | { |
497 | int i, nb , flag; |
498 | LttvAttribute *subtree; |
499 | LttvAttributeName name; |
500 | LttvAttributeValue value; |
501 | LttvAttributeType type; |
502 | gchar type_name[PATH_LENGTH], type_value[PATH_LENGTH]; |
503 | GtkTextIter text_iter; |
504 | |
505 | flag = 0; |
506 | nb = lttv_attribute_get_number(stats); |
507 | for(i = 0 ; i < nb ; i++) { |
508 | type = lttv_attribute_get(stats, i, &name, &value); |
509 | sprintf(type_name,"%s", g_quark_to_string(name)); |
510 | type_value[0] = '\0'; |
511 | switch(type) { |
512 | case LTTV_INT: |
513 | sprintf(type_value, " : %d\n", *value.v_int); |
514 | break; |
515 | case LTTV_UINT: |
516 | sprintf(type_value, " : %u\n", *value.v_uint); |
517 | break; |
518 | case LTTV_LONG: |
519 | sprintf(type_value, " : %ld\n", *value.v_long); |
520 | break; |
521 | case LTTV_ULONG: |
522 | sprintf(type_value, " : %lu\n", *value.v_ulong); |
523 | break; |
524 | case LTTV_FLOAT: |
525 | sprintf(type_value, " : %f\n", (double)*value.v_float); |
526 | break; |
527 | case LTTV_DOUBLE: |
528 | sprintf(type_value, " : %f\n", *value.v_double); |
529 | break; |
530 | case LTTV_TIME: |
531 | sprintf(type_value, " : %10u.%09u\n", value.v_time->tv_sec, |
532 | value.v_time->tv_nsec); |
533 | break; |
534 | case LTTV_POINTER: |
535 | sprintf(type_value, " : POINTER\n"); |
536 | break; |
537 | case LTTV_STRING: |
538 | sprintf(type_value, " : %s\n", *value.v_string); |
539 | break; |
540 | default: |
541 | break; |
542 | } |
543 | if(strlen(type_value)){ |
544 | flag = 1; |
545 | strcat(type_name,type_value); |
546 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
547 | gtk_text_buffer_insert(buf, &text_iter, type_name, strlen(type_name)); |
548 | } |
549 | } |
550 | |
551 | if(flag == 0){ |
552 | sprintf(type_value, "No statistic information in this directory.\nCheck in subdirectories please.\n"); |
553 | gtk_text_buffer_get_end_iter(buf, &text_iter); |
554 | gtk_text_buffer_insert(buf, &text_iter, type_value, strlen(type_value)); |
555 | |
556 | } |
557 | } |
558 | |
a8c0f09d |
559 | gboolean statistic_update_time_window(void * hook_data, void * call_data) |
560 | { |
561 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
562 | LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); |
563 | |
5b2cdf0e |
564 | //if statistic is already calculated, do nothing |
565 | if(!statistic_viewer_data->calculate_stats){ |
566 | return FALSE; |
567 | } |
568 | |
a8c0f09d |
569 | if(statistic_viewer_data->shown == FALSE){ |
570 | statistic_add_context_hooks(statistic_viewer_data, tsc); |
571 | } |
572 | return FALSE; |
573 | } |
574 | |
575 | gboolean statistic_show_viewer(void * hook_data, void * call_data) |
576 | { |
577 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
578 | LttvTracesetContext * tsc = get_traceset_context(statistic_viewer_data->mw); |
579 | |
580 | if(statistic_viewer_data->shown == FALSE){ |
581 | statistic_viewer_data->shown = TRUE; |
582 | show_traceset_stats(statistic_viewer_data); |
5b2cdf0e |
583 | if(statistic_viewer_data->calculate_stats){ |
584 | statistic_remove_context_hooks(statistic_viewer_data,tsc); |
9f797243 |
585 | lttv_stats_save_statistics((LttvTracesetStats*)tsc); |
5b2cdf0e |
586 | } |
a8c0f09d |
587 | } |
588 | |
589 | return FALSE; |
590 | } |
591 | |
592 | gboolean statistic_traceset_changed(void * hook_data, void * call_data) |
593 | { |
594 | StatisticViewerData *statistic_viewer_data = (StatisticViewerData*) hook_data; |
595 | |
21e8c385 |
596 | gtk_tree_store_clear (statistic_viewer_data->store_m); |
597 | statistic_viewer_data->shown = FALSE; |
a8c0f09d |
598 | |
599 | return FALSE; |
600 | } |
601 | |
602 | void statistic_add_context_hooks(StatisticViewerData * statistic_viewer_data, |
8d70e03b |
603 | LttvTracesetContext * tsc) |
a8c0f09d |
604 | { |
dbb7bb09 |
605 | gint i, j, nbi, nb_tracefile; |
a8c0f09d |
606 | LttTrace *trace; |
607 | LttvTraceContext *tc; |
608 | LttvTracefileContext *tfc; |
609 | LttvTracesetSelector * ts_s; |
610 | LttvTraceSelector * t_s; |
611 | LttvTracefileSelector * tf_s; |
612 | gboolean selected; |
613 | |
614 | ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(statistic_viewer_data->hpaned_v), |
8d70e03b |
615 | statistic_viewer_data->filter_key); |
a8c0f09d |
616 | |
617 | //if there are hooks for traceset, add them here |
618 | |
619 | nbi = lttv_traceset_number(tsc->ts); |
620 | for(i = 0 ; i < nbi ; i++) { |
ed3b99b6 |
621 | t_s = lttv_traceset_selector_trace_get(ts_s,i); |
a8c0f09d |
622 | selected = lttv_trace_selector_get_selected(t_s); |
623 | if(!selected) continue; |
624 | tc = tsc->traces[i]; |
625 | trace = tc->t; |
626 | //if there are hooks for trace, add them here |
627 | |
dbb7bb09 |
628 | nb_tracefile = ltt_trace_control_tracefile_number(trace) + |
629 | ltt_trace_per_cpu_tracefile_number(trace); |
a8c0f09d |
630 | |
631 | for(j = 0 ; j < nb_tracefile ; j++) { |
ed3b99b6 |
632 | tf_s = lttv_trace_selector_tracefile_get(t_s,j); |
a8c0f09d |
633 | selected = lttv_tracefile_selector_get_selected(tf_s); |
634 | if(!selected) continue; |
dbb7bb09 |
635 | tfc = tc->tracefiles[j]; |
a8c0f09d |
636 | |
637 | //if there are hooks for tracefile, add them here |
638 | // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL, |
8d70e03b |
639 | // statistic_viewer_data->before_event_hooks,NULL); |
a8c0f09d |
640 | } |
641 | } |
642 | |
643 | //add state and stats hooks |
540edb40 |
644 | //state_add_event_hooks_api(statistic_viewer_data->mw); //it will be added in the main window |
a8c0f09d |
645 | stats_add_event_hooks_api(statistic_viewer_data->mw); |
646 | |
647 | } |
648 | |
649 | void 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 | |
690 | //remove state and stats hooks |
540edb40 |
691 | //state_remove_event_hooks_api(statistic_viewer_data->mw); //it will be done in the main window |
a8c0f09d |
692 | stats_remove_event_hooks_api(statistic_viewer_data->mw); |
693 | } |
694 | |
6b1d3120 |
695 | |