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