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