6 #include <lttv/module.h>
7 #include <lttv/gtkTraceSet.h>
8 #include <lttv/processTrace.h>
10 #include <lttv/common.h>
11 #include <lttv/state.h>
12 #include <lttv/stats.h>
15 #include <ltt/event.h>
17 #include <ltt/trace.h>
21 #include "../icons/hGuiStatisticInsert.xpm"
23 #define PATH_LENGTH 256
25 static LttvModule
*Main_Win_Module
;
27 /** Array containing instanced objects. Used when module is unloaded */
28 GSList
*gStatistic_Viewer_Data_List
= NULL
;
30 typedef struct _StatisticViewerData StatisticViewerData
;
32 //! Statistic Viewer's constructor hook
33 GtkWidget
*hGuiStatistic(mainWindow
*pmParentWindow
);
34 //! Statistic Viewer's constructor
35 StatisticViewerData
*GuiStatistic(mainWindow
*pmParentWindow
);
36 //! Statistic Viewer's destructor
37 void GuiStatistic_Destructor(StatisticViewerData
*Statistic_Viewer_Data
);
38 void GuiStatistic_free(StatisticViewerData
*Statistic_Viewer_Data
);
40 void grab_focus(GtkWidget
*widget
, gpointer data
);
41 static void tree_selection_changed_cb (GtkTreeSelection
*selection
, gpointer data
);
43 void Destroy_hash_key(gpointer key
);
44 void Destroy_hash_data(gpointer data
);
46 void get_traceset_stats(StatisticViewerData
* Statistic_Viewer_Data
);
47 void show_traceset_stats(StatisticViewerData
* Statistic_Viewer_Data
);
48 void show_tree(StatisticViewerData
* Statistic_Viewer_Data
,
49 LttvAttribute
* stats
, GtkTreeIter
* parent
);
50 void show_statistic(StatisticViewerData
* Statistic_Viewer_Data
,
51 LttvAttribute
* stats
, GtkTextBuffer
* buf
);
60 struct _StatisticViewerData
{
62 LttvTracesetStats
* stats
;
65 GtkTreeStore
* Store_M
;
68 //scroll window containing Tree View
69 GtkWidget
* Scroll_Win_Tree
;
72 //scroll window containing Text View
73 GtkWidget
* Scroll_Win_Text
;
76 GtkTreeSelection
*Select_C
;
79 GHashTable
*Statistic_Hash
;
84 * plugin's init function
86 * This function initializes the Statistic Viewer functionnality through the
89 G_MODULE_EXPORT
void init(LttvModule
*self
, int argc
, char *argv
[]) {
91 Main_Win_Module
= lttv_module_require(self
, "mainwin", argc
, argv
);
93 if(Main_Win_Module
== NULL
){
94 g_critical("Can't load Statistic Viewer : missing mainwin\n");
98 g_critical("GUI Statistic Viewer init()");
100 /* Register the toolbar insert button */
101 ToolbarItemReg(hGuiStatisticInsert_xpm
, "Insert Statistic Viewer", hGuiStatistic
);
103 /* Register the menu item insert entry */
104 MenuItemReg("/", "Insert Statistic Viewer", hGuiStatistic
);
108 void destroy_walk(gpointer data
, gpointer user_data
)
110 GuiStatistic_Destructor((StatisticViewerData
*)data
);
114 * plugin's destroy function
116 * This function releases the memory reserved by the module and unregisters
117 * everything that has been registered in the gtkTraceSet API.
119 G_MODULE_EXPORT
void destroy() {
122 StatisticViewerData
*Statistic_Viewer_Data
;
124 g_critical("GUI Statistic Viewer destroy()");
126 g_slist_foreach(gStatistic_Viewer_Data_List
, destroy_walk
, NULL
);
128 g_slist_free(gStatistic_Viewer_Data_List
);
130 /* Unregister the toolbar insert button */
131 ToolbarItemUnreg(hGuiStatistic
);
133 /* Unregister the menu item insert entry */
134 MenuItemUnreg(hGuiStatistic
);
139 GuiStatistic_free(StatisticViewerData
*Statistic_Viewer_Data
)
141 if(Statistic_Viewer_Data
){
142 g_hash_table_destroy(Statistic_Viewer_Data
->Statistic_Hash
);
143 gStatistic_Viewer_Data_List
= g_slist_remove(gStatistic_Viewer_Data_List
, Statistic_Viewer_Data
);
144 g_warning("Delete Statistic data\n");
145 g_free(Statistic_Viewer_Data
);
150 GuiStatistic_Destructor(StatisticViewerData
*Statistic_Viewer_Data
)
152 /* May already been done by GTK window closing */
153 if(GTK_IS_WIDGET(Statistic_Viewer_Data
->HPaned_V
)){
154 gtk_widget_destroy(Statistic_Viewer_Data
->HPaned_V
);
155 Statistic_Viewer_Data
= NULL
;
158 GuiStatistic_free(Statistic_Viewer_Data
);
163 * Statistic Viewer's constructor hook
165 * This constructor is given as a parameter to the menuitem and toolbar button
166 * registration. It creates the list.
167 * @param pmParentWindow A pointer to the parent window.
168 * @return The widget created.
171 hGuiStatistic(mainWindow
* pmParentWindow
)
173 StatisticViewerData
* Statistic_Viewer_Data
= GuiStatistic(pmParentWindow
) ;
175 if(Statistic_Viewer_Data
)
176 return Statistic_Viewer_Data
->HPaned_V
;
182 * Statistic Viewer's constructor
184 * This constructor is used to create StatisticViewerData data structure.
185 * @return The Statistic viewer data created.
187 StatisticViewerData
*
188 GuiStatistic(mainWindow
*pmParentWindow
)
190 GtkCellRenderer
*renderer
;
191 GtkTreeViewColumn
*column
;
193 StatisticViewerData
* Statistic_Viewer_Data
= g_new(StatisticViewerData
,1);
195 Statistic_Viewer_Data
->mw
= pmParentWindow
;
196 Statistic_Viewer_Data
->stats
= getTracesetStats(Statistic_Viewer_Data
->mw
);
198 Statistic_Viewer_Data
->Statistic_Hash
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
199 Destroy_hash_key
, Destroy_hash_data
);
201 Statistic_Viewer_Data
->HPaned_V
= gtk_hpaned_new();
202 Statistic_Viewer_Data
->Store_M
= gtk_tree_store_new (N_COLUMNS
, G_TYPE_STRING
);
203 Statistic_Viewer_Data
->Tree_V
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (Statistic_Viewer_Data
->Store_M
));
204 g_object_unref (G_OBJECT (Statistic_Viewer_Data
->Store_M
));
206 g_signal_connect (G_OBJECT (Statistic_Viewer_Data
->Tree_V
), "grab-focus",
207 G_CALLBACK (grab_focus
),
208 Statistic_Viewer_Data
);
210 // Setup the selection handler
211 Statistic_Viewer_Data
->Select_C
= gtk_tree_view_get_selection (GTK_TREE_VIEW (Statistic_Viewer_Data
->Tree_V
));
212 gtk_tree_selection_set_mode (Statistic_Viewer_Data
->Select_C
, GTK_SELECTION_SINGLE
);
213 g_signal_connect (G_OBJECT (Statistic_Viewer_Data
->Select_C
), "changed",
214 G_CALLBACK (tree_selection_changed_cb
),
215 Statistic_Viewer_Data
);
217 renderer
= gtk_cell_renderer_text_new ();
218 column
= gtk_tree_view_column_new_with_attributes ("Statistic Name",
222 gtk_tree_view_column_set_alignment (column
, 0.0);
223 // gtk_tree_view_column_set_fixed_width (column, 45);
224 gtk_tree_view_append_column (GTK_TREE_VIEW (Statistic_Viewer_Data
->Tree_V
), column
);
227 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (Statistic_Viewer_Data
->Tree_V
), FALSE
);
229 Statistic_Viewer_Data
->Scroll_Win_Tree
= gtk_scrolled_window_new (NULL
, NULL
);
230 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Statistic_Viewer_Data
->Scroll_Win_Tree
),
231 GTK_POLICY_AUTOMATIC
,GTK_POLICY_AUTOMATIC
);
233 gtk_container_add (GTK_CONTAINER (Statistic_Viewer_Data
->Scroll_Win_Tree
), Statistic_Viewer_Data
->Tree_V
);
234 gtk_paned_pack1(GTK_PANED(Statistic_Viewer_Data
->HPaned_V
),Statistic_Viewer_Data
->Scroll_Win_Tree
, TRUE
, FALSE
);
235 gtk_paned_set_position(GTK_PANED(Statistic_Viewer_Data
->HPaned_V
), 160);
237 Statistic_Viewer_Data
->Scroll_Win_Text
= gtk_scrolled_window_new (NULL
, NULL
);
238 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Statistic_Viewer_Data
->Scroll_Win_Text
),
239 GTK_POLICY_AUTOMATIC
,GTK_POLICY_AUTOMATIC
);
241 Statistic_Viewer_Data
->Text_V
= gtk_text_view_new ();
242 g_signal_connect (G_OBJECT (Statistic_Viewer_Data
->Text_V
), "grab-focus",
243 G_CALLBACK (grab_focus
),
244 Statistic_Viewer_Data
);
246 gtk_text_view_set_editable(GTK_TEXT_VIEW(Statistic_Viewer_Data
->Text_V
),FALSE
);
247 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(Statistic_Viewer_Data
->Text_V
),FALSE
);
248 gtk_container_add (GTK_CONTAINER (Statistic_Viewer_Data
->Scroll_Win_Text
), Statistic_Viewer_Data
->Text_V
);
249 gtk_paned_pack2(GTK_PANED(Statistic_Viewer_Data
->HPaned_V
), Statistic_Viewer_Data
->Scroll_Win_Text
, TRUE
, FALSE
);
251 gtk_widget_show(Statistic_Viewer_Data
->Scroll_Win_Tree
);
252 gtk_widget_show(Statistic_Viewer_Data
->Scroll_Win_Text
);
253 gtk_widget_show(Statistic_Viewer_Data
->Tree_V
);
254 gtk_widget_show(Statistic_Viewer_Data
->Text_V
);
255 gtk_widget_show(Statistic_Viewer_Data
->HPaned_V
);
257 g_object_set_data_full(
258 G_OBJECT(Statistic_Viewer_Data
->HPaned_V
),
259 "Statistic_Viewer_Data",
260 Statistic_Viewer_Data
,
261 (GDestroyNotify
)GuiStatistic_free
);
263 /* Add the object's information to the module's array */
264 gStatistic_Viewer_Data_List
= g_slist_append(gStatistic_Viewer_Data_List
, Statistic_Viewer_Data
);
266 get_traceset_stats(Statistic_Viewer_Data
);
268 return Statistic_Viewer_Data
;
271 void grab_focus(GtkWidget
*widget
, gpointer data
)
273 StatisticViewerData
*Statistic_Viewer_Data
= (StatisticViewerData
*)data
;
274 mainWindow
* mw
= Statistic_Viewer_Data
->mw
;
275 SetFocusedPane(mw
, gtk_widget_get_parent(Statistic_Viewer_Data
->HPaned_V
));
279 tree_selection_changed_cb (GtkTreeSelection
*selection
, gpointer data
)
281 StatisticViewerData
*Statistic_Viewer_Data
= (StatisticViewerData
*)data
;
283 GtkTreeModel
*model
= GTK_TREE_MODEL(Statistic_Viewer_Data
->Store_M
);
288 GtkTextIter text_iter
;
289 LttvAttribute
* stats
;
291 if (gtk_tree_selection_get_selected (selection
, &model
, &iter
))
293 gtk_tree_model_get (model
, &iter
, NAME_COLUMN
, &Event
, -1);
295 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(model
),&iter
);
296 str
= gtk_tree_path_to_string (path
);
297 stats
= (LttvAttribute
*)g_hash_table_lookup (Statistic_Viewer_Data
->Statistic_Hash
,str
);
300 buf
= gtk_text_view_get_buffer((GtkTextView
*)Statistic_Viewer_Data
->Text_V
);
301 gtk_text_buffer_set_text(buf
,"Statistic for '", -1);
302 gtk_text_buffer_get_end_iter(buf
, &text_iter
);
303 gtk_text_buffer_insert(buf
, &text_iter
, Event
, strlen(Event
));
304 gtk_text_buffer_get_end_iter(buf
, &text_iter
);
305 gtk_text_buffer_insert(buf
, &text_iter
, "' :\n\n",5);
307 show_statistic(Statistic_Viewer_Data
, stats
, buf
);
313 void Destroy_hash_key(gpointer key
)
318 void Destroy_hash_data(gpointer data
)
323 void get_traceset_stats(StatisticViewerData
* Statistic_Viewer_Data
)
329 end
.tv_sec
= G_MAXULONG
;
330 end
.tv_nsec
= G_MAXULONG
;
332 stateAddEventHooks(Statistic_Viewer_Data
->mw
);
333 statsAddEventHooks(Statistic_Viewer_Data
->mw
);
335 processTraceset(Statistic_Viewer_Data
->mw
, start
, end
, G_MAXULONG
);
337 stateRemoveEventHooks(Statistic_Viewer_Data
->mw
);
338 statsRemoveEventHooks(Statistic_Viewer_Data
->mw
);
340 //establish tree view for stats
341 show_traceset_stats(Statistic_Viewer_Data
);
344 void show_traceset_stats(StatisticViewerData
* Statistic_Viewer_Data
)
349 LttSystemDescription
*desc
;
350 LttvTracesetStats
* tscs
= Statistic_Viewer_Data
->stats
;
351 gchar
* str
, trace_str
[PATH_LENGTH
];
354 GtkTreeStore
* store
= Statistic_Viewer_Data
->Store_M
;
356 if(tscs
->stats
== NULL
) return;
358 gtk_tree_store_append (store
, &iter
, NULL
);
359 gtk_tree_store_set (store
, &iter
,
360 NAME_COLUMN
, "Traceset statistics",
362 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &iter
);
363 str
= gtk_tree_path_to_string (path
);
364 g_hash_table_insert(Statistic_Viewer_Data
->Statistic_Hash
,
365 (gpointer
)str
, tscs
->stats
);
366 show_tree(Statistic_Viewer_Data
, tscs
->stats
, &iter
);
368 //show stats for all traces
369 ts
= tscs
->parent
.parent
.ts
;
370 nb
= lttv_traceset_number(ts
);
372 for(i
= 0 ; i
< nb
; i
++) {
373 tcs
= (LttvTraceStats
*)(LTTV_TRACESET_CONTEXT(tscs
)->traces
[i
]);
374 desc
= ltt_trace_system_description(tcs
->parent
.parent
.t
);
375 sprintf(trace_str
, "Trace on system %s at time %d secs",
376 desc
->node_name
,desc
->trace_start
.tv_sec
);
378 gtk_tree_store_append (store
, &iter
, NULL
);
379 gtk_tree_store_set (store
, &iter
,NAME_COLUMN
,trace_str
,-1);
380 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &iter
);
381 str
= gtk_tree_path_to_string (path
);
382 g_hash_table_insert(Statistic_Viewer_Data
->Statistic_Hash
,
383 (gpointer
)str
,tcs
->stats
);
384 show_tree(Statistic_Viewer_Data
, tcs
->stats
, &iter
);
388 void show_tree(StatisticViewerData
* Statistic_Viewer_Data
,
389 LttvAttribute
* stats
, GtkTreeIter
* parent
)
392 LttvAttribute
*subtree
;
393 LttvAttributeName name
;
394 LttvAttributeValue value
;
395 LttvAttributeType type
;
396 gchar
* str
, dir_str
[PATH_LENGTH
];
399 GtkTreeStore
* store
= Statistic_Viewer_Data
->Store_M
;
401 nb
= lttv_attribute_get_number(stats
);
402 for(i
= 0 ; i
< nb
; i
++) {
403 type
= lttv_attribute_get(stats
, i
, &name
, &value
);
406 if(LTTV_IS_ATTRIBUTE(*(value
.v_gobject
))) {
407 sprintf(dir_str
, "%s", g_quark_to_string(name
));
408 subtree
= (LttvAttribute
*)*(value
.v_gobject
);
409 gtk_tree_store_append (store
, &iter
, parent
);
410 gtk_tree_store_set (store
, &iter
,NAME_COLUMN
,dir_str
,-1);
411 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &iter
);
412 str
= gtk_tree_path_to_string (path
);
413 g_hash_table_insert(Statistic_Viewer_Data
->Statistic_Hash
,
414 (gpointer
)str
, subtree
);
415 show_tree(Statistic_Viewer_Data
, subtree
, &iter
);
424 void show_statistic(StatisticViewerData
* Statistic_Viewer_Data
,
425 LttvAttribute
* stats
, GtkTextBuffer
* buf
)
428 LttvAttribute
*subtree
;
429 LttvAttributeName name
;
430 LttvAttributeValue value
;
431 LttvAttributeType type
;
432 gchar type_name
[PATH_LENGTH
], type_value
[PATH_LENGTH
];
433 GtkTextIter text_iter
;
436 nb
= lttv_attribute_get_number(stats
);
437 for(i
= 0 ; i
< nb
; i
++) {
438 type
= lttv_attribute_get(stats
, i
, &name
, &value
);
439 sprintf(type_name
,"%s", g_quark_to_string(name
));
440 type_value
[0] = '\0';
443 sprintf(type_value
, " : %d\n", *value
.v_int
);
446 sprintf(type_value
, " : %u\n", *value
.v_uint
);
449 sprintf(type_value
, " : %ld\n", *value
.v_long
);
452 sprintf(type_value
, " : %lu\n", *value
.v_ulong
);
455 sprintf(type_value
, " : %f\n", (double)*value
.v_float
);
458 sprintf(type_value
, " : %f\n", *value
.v_double
);
461 sprintf(type_value
, " : %10u.%09u\n", value
.v_time
->tv_sec
,
462 value
.v_time
->tv_nsec
);
465 sprintf(type_value
, " : POINTER\n");
468 sprintf(type_value
, " : %s\n", *value
.v_string
);
473 if(strlen(type_value
)){
475 strcat(type_name
,type_value
);
476 gtk_text_buffer_get_end_iter(buf
, &text_iter
);
477 gtk_text_buffer_insert(buf
, &text_iter
, type_name
, strlen(type_name
));
482 sprintf(type_value
, "No statistic information in this directory.\nCheck in subdirectories please.\n");
483 gtk_text_buffer_get_end_iter(buf
, &text_iter
);
484 gtk_text_buffer_insert(buf
, &text_iter
, type_value
, strlen(type_value
));