e076699e |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Mathieu Desnoyers and 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 | |
fb87279e |
19 | /* |
20 | * Initial main.c file generated by Glade. Edit as required. |
21 | * Glade will not overwrite this file. |
22 | */ |
23 | |
24 | #ifdef HAVE_CONFIG_H |
25 | # include <config.h> |
26 | #endif |
27 | |
28 | #include <gtk/gtk.h> |
a1a2b649 |
29 | #include <glib.h> |
fb87279e |
30 | |
fb87279e |
31 | #include <lttv/lttv.h> |
0a6808c0 |
32 | #include <lttv/attribute.h> |
33 | #include <lttv/hook.h> |
34 | #include <lttv/option.h> |
35 | #include <lttv/module.h> |
d8f124de |
36 | #include <lttv/tracecontext.h> |
ec25ff5e |
37 | #include <lttv/state.h> |
6b1d3120 |
38 | #include <lttv/stats.h> |
13f86ce2 |
39 | #include <lttvwindow/menu.h> |
40 | #include <lttvwindow/toolbar.h> |
a1a2b649 |
41 | #include <lttvwindow/lttvwindowtraces.h> |
fb87279e |
42 | |
43 | #include "interface.h" |
44 | #include "support.h" |
13f86ce2 |
45 | #include <lttvwindow/mainwindow.h> |
2d262115 |
46 | #include <lttvwindow/mainwindow-private.h> |
fb87279e |
47 | #include "callbacks.h" |
a5dcde2f |
48 | #include <ltt/trace.h> |
49 | |
fb87279e |
50 | |
a1a2b649 |
51 | LttvTraceInfo LTTV_TRACES, |
52 | LTTV_COMPUTATION, |
e025a729 |
53 | LTTV_VIEWER_CONSTRUCTORS, |
a1a2b649 |
54 | LTTV_REQUESTS_QUEUE, |
55 | LTTV_REQUESTS_CURRENT, |
56 | LTTV_NOTIFY_QUEUE, |
8bc02ec8 |
57 | LTTV_NOTIFY_CURRENT, |
58 | LTTV_COMPUTATION_TRACESET, |
59 | LTTV_COMPUTATION_TRACESET_CONTEXT, |
79257ba5 |
60 | LTTV_COMPUTATION_SYNC_POSITION, |
8bc02ec8 |
61 | LTTV_BEFORE_CHUNK_TRACESET, |
62 | LTTV_BEFORE_CHUNK_TRACE, |
63 | LTTV_BEFORE_CHUNK_TRACEFILE, |
64 | LTTV_AFTER_CHUNK_TRACESET, |
65 | LTTV_AFTER_CHUNK_TRACE, |
66 | LTTV_AFTER_CHUNK_TRACEFILE, |
67 | LTTV_BEFORE_REQUEST, |
68 | LTTV_AFTER_REQUEST, |
69 | LTTV_EVENT_HOOK, |
70 | LTTV_EVENT_HOOK_BY_ID, |
313bd6fc |
71 | LTTV_HOOK_ADDER, |
72 | LTTV_HOOK_REMOVER, |
8bc02ec8 |
73 | LTTV_IN_PROGRESS, |
b052368a |
74 | LTTV_READY, |
75 | LTTV_LOCK; |
8bc02ec8 |
76 | |
6ced96ef |
77 | |
ec25ff5e |
78 | /** Array containing instanced objects. */ |
68b48a45 |
79 | GSList * g_main_window_list = NULL ; |
ec25ff5e |
80 | |
f7afe191 |
81 | LttvHooks |
ec25ff5e |
82 | *main_hooks; |
83 | |
f7afe191 |
84 | /* Initial trace from command line */ |
6cec4cd2 |
85 | //LttvTrace *g_init_trace = NULL; |
f7afe191 |
86 | |
ec25ff5e |
87 | static char *a_trace; |
6cec4cd2 |
88 | static char g_init_trace[PATH_MAX] = ""; |
ec25ff5e |
89 | |
6ced96ef |
90 | |
ec25ff5e |
91 | void lttv_trace_option(void *hook_data) |
92 | { |
308711e5 |
93 | LttTrace *trace; |
6cec4cd2 |
94 | |
95 | get_absolute_pathname(a_trace, g_init_trace); |
ec25ff5e |
96 | } |
fb87279e |
97 | |
98 | /***************************************************************************** |
99 | * Functions for module loading/unloading * |
100 | *****************************************************************************/ |
101 | /** |
102 | * plugin's init function |
103 | * |
104 | * This function initializes the GUI. |
105 | */ |
106 | |
68b48a45 |
107 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e |
108 | { |
2a2fa4f0 |
109 | g_debug("GUI window_creation_hook()"); |
fb87279e |
110 | #ifdef ENABLE_NLS |
111 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
112 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
113 | textdomain (GETTEXT_PACKAGE); |
114 | #endif |
115 | |
116 | gtk_set_locale (); |
08b1c66e |
117 | gtk_init (<tv_argc, <tv_argv); |
fb87279e |
118 | |
119 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
120 | add_pixmap_directory ("pixmaps"); |
077ba5c0 |
121 | add_pixmap_directory ("../modules/gui/main/pixmaps"); |
fb87279e |
122 | |
6cec4cd2 |
123 | /* First window, use command line trace */ |
124 | if(strcmp(g_init_trace, "") != 0){ |
125 | create_main_window_with_trace(g_init_trace); |
126 | } else { |
127 | construct_main_window(NULL); |
128 | } |
fb87279e |
129 | |
130 | gtk_main (); |
0a6808c0 |
131 | |
ec25ff5e |
132 | return FALSE; |
0a6808c0 |
133 | } |
134 | |
08b1c66e |
135 | static void init() { |
0a6808c0 |
136 | |
ec25ff5e |
137 | LttvAttributeValue value; |
f7afe191 |
138 | |
139 | // Global attributes only used for interaction with main() here. |
ec25ff5e |
140 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
141 | |
a1a2b649 |
142 | LTTV_TRACES = g_quark_from_string("traces"); |
143 | LTTV_COMPUTATION = g_quark_from_string("computation"); |
e025a729 |
144 | LTTV_VIEWER_CONSTRUCTORS = g_quark_from_string("viewer_constructors"); |
a1a2b649 |
145 | LTTV_REQUESTS_QUEUE = g_quark_from_string("requests_queue"); |
146 | LTTV_REQUESTS_CURRENT = g_quark_from_string("requests_current"); |
147 | LTTV_NOTIFY_QUEUE = g_quark_from_string("notify_queue"); |
148 | LTTV_NOTIFY_CURRENT = g_quark_from_string("notify_current"); |
8bc02ec8 |
149 | LTTV_COMPUTATION_TRACESET = g_quark_from_string("computation_traceset"); |
150 | LTTV_COMPUTATION_TRACESET_CONTEXT = |
151 | g_quark_from_string("computation_traceset_context"); |
79257ba5 |
152 | LTTV_COMPUTATION_SYNC_POSITION = |
153 | g_quark_from_string("computation_sync_position"); |
8bc02ec8 |
154 | LTTV_BEFORE_CHUNK_TRACESET = g_quark_from_string("before_chunk_traceset"); |
155 | LTTV_BEFORE_CHUNK_TRACE = g_quark_from_string("before_chunk_trace"); |
156 | LTTV_BEFORE_CHUNK_TRACEFILE = g_quark_from_string("before_chunk_tracefile"); |
157 | LTTV_AFTER_CHUNK_TRACESET = g_quark_from_string("after_chunk_traceset"); |
158 | LTTV_AFTER_CHUNK_TRACE = g_quark_from_string("after_chunk_trace"); |
159 | LTTV_AFTER_CHUNK_TRACEFILE = g_quark_from_string("after_chunk_tracefile"); |
160 | LTTV_BEFORE_REQUEST = g_quark_from_string("before_request"); |
161 | LTTV_AFTER_REQUEST = g_quark_from_string("after_request"); |
162 | LTTV_EVENT_HOOK = g_quark_from_string("event_hook"); |
163 | LTTV_EVENT_HOOK_BY_ID = g_quark_from_string("event_hook_by_id"); |
313bd6fc |
164 | LTTV_HOOK_ADDER = g_quark_from_string("hook_adder"); |
165 | LTTV_HOOK_REMOVER = g_quark_from_string("hook_remover"); |
8bc02ec8 |
166 | LTTV_IN_PROGRESS = g_quark_from_string("in_progress"); |
167 | LTTV_READY = g_quark_from_string("ready"); |
b052368a |
168 | LTTV_LOCK = g_quark_from_string("lock"); |
8bc02ec8 |
169 | |
6ced96ef |
170 | g_debug("GUI init()"); |
171 | |
ec25ff5e |
172 | lttv_option_add("trace", 't', |
173 | "add a trace to the trace set to analyse", |
174 | "pathname of the directory containing the trace", |
175 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
176 | |
ec25ff5e |
177 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
178 | LTTV_POINTER, &value)); |
179 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
180 | |
2d262115 |
181 | lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT); |
0a6808c0 |
182 | |
91fd6881 |
183 | { |
184 | /* Register state calculator */ |
185 | LttvHooks *hook_adder = lttv_hooks_new(); |
186 | lttv_hooks_add(hook_adder, lttv_state_save_hook_add_event_hooks, NULL, |
187 | LTTV_PRIO_DEFAULT); |
1ce324c6 |
188 | lttv_hooks_add(hook_adder, lttv_state_hook_add_event_hooks, NULL, |
189 | LTTV_PRIO_DEFAULT); |
91fd6881 |
190 | LttvHooks *hook_remover = lttv_hooks_new(); |
191 | lttv_hooks_add(hook_remover, lttv_state_save_hook_remove_event_hooks, |
192 | NULL, LTTV_PRIO_DEFAULT); |
1ce324c6 |
193 | lttv_hooks_add(hook_remover, lttv_state_hook_remove_event_hooks, |
194 | NULL, LTTV_PRIO_DEFAULT); |
91fd6881 |
195 | /* Add state computation background hook adder to attributes */ |
196 | lttvwindowtraces_register_computation_hooks(g_quark_from_string("state"), |
197 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
198 | hook_adder, hook_remover); |
199 | } |
200 | |
201 | { |
202 | /* Register statistics calculator */ |
203 | LttvHooks *hook_adder = lttv_hooks_new(); |
204 | lttv_hooks_add(hook_adder, lttv_stats_hook_add_event_hooks, NULL, |
205 | LTTV_PRIO_DEFAULT); |
1ce324c6 |
206 | lttv_hooks_add(hook_adder, lttv_state_hook_add_event_hooks, NULL, |
207 | LTTV_PRIO_DEFAULT); |
91fd6881 |
208 | LttvHooks *hook_remover = lttv_hooks_new(); |
209 | lttv_hooks_add(hook_remover, lttv_stats_hook_remove_event_hooks, |
210 | NULL, LTTV_PRIO_DEFAULT); |
1ce324c6 |
211 | lttv_hooks_add(hook_remover, lttv_state_hook_remove_event_hooks, |
212 | NULL, LTTV_PRIO_DEFAULT); |
91fd6881 |
213 | LttvHooks *after_request = lttv_hooks_new(); |
214 | lttv_hooks_add(after_request, lttv_stats_sum_traceset_hook, NULL, |
215 | LTTV_PRIO_DEFAULT); |
216 | /* Add state computation background hook adder to attributes */ |
217 | lttvwindowtraces_register_computation_hooks(g_quark_from_string("stats"), |
218 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
219 | after_request, NULL, NULL, |
220 | hook_adder, hook_remover); |
221 | } |
fb87279e |
222 | } |
223 | |
7a859036 |
224 | void |
bca3b81f |
225 | main_window_destructor(MainWindow * mw) |
7a859036 |
226 | { |
2d262115 |
227 | g_assert(GTK_IS_WIDGET(mw->mwindow)); |
228 | gtk_widget_destroy(mw->mwindow); |
fb87279e |
229 | } |
230 | |
d0724d16 |
231 | static void destroy_walk(gpointer data, gpointer user_data) |
232 | { |
233 | main_window_destructor((MainWindow*)data); |
234 | } |
fb87279e |
235 | |
fb87279e |
236 | /** |
237 | * plugin's destroy function |
238 | * |
239 | * This function releases the memory reserved by the module and unregisters |
240 | * everything that has been registered in the gtkTraceSet API. |
241 | */ |
08b1c66e |
242 | static void destroy() { |
fb87279e |
243 | |
7a859036 |
244 | LttvAttributeValue value; |
308711e5 |
245 | LttvTrace *trace; |
2d262115 |
246 | GSList *iter = NULL; |
247 | |
ec25ff5e |
248 | lttv_option_remove("trace"); |
249 | |
08b1c66e |
250 | lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL); |
ec25ff5e |
251 | |
2a2fa4f0 |
252 | g_debug("GUI destroy()"); |
fb87279e |
253 | |
d0724d16 |
254 | g_slist_foreach(g_main_window_list, destroy_walk, NULL); |
255 | |
256 | g_slist_free(g_main_window_list); |
ec25ff5e |
257 | |
fb87279e |
258 | } |
259 | |
260 | |
db2c9c14 |
261 | LTTV_MODULE("lttvwindow", "Viewer main window", \ |
08b1c66e |
262 | "Viewer with multiple windows, tabs and panes for graphical modules", \ |
2d262115 |
263 | init, destroy, "stats", "option") |