1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers and XangXiu Yang
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;
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.
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,
20 * Initial main.c file generated by Glade. Edit as required.
21 * Glade will not overwrite this file.
31 #include <lttv/lttv.h>
32 #include <lttv/attribute.h>
33 #include <lttv/hook.h>
34 #include <lttv/option.h>
35 #include <lttv/module.h>
36 #include <lttv/tracecontext.h>
37 #include <lttv/state.h>
38 #include <lttv/stats.h>
39 #include <lttvwindow/menu.h>
40 #include <lttvwindow/toolbar.h>
41 #include <lttvwindow/lttvwindowtraces.h>
43 #include "interface.h"
45 #include <lttvwindow/mainwindow.h>
46 #include <lttvwindow/mainwindow-private.h>
47 #include "callbacks.h"
48 #include <ltt/trace.h>
51 LttvTraceInfo LTTV_TRACES
,
53 LTTV_VIEWER_CONSTRUCTORS
,
55 LTTV_REQUESTS_CURRENT
,
58 LTTV_COMPUTATION_TRACESET
,
59 LTTV_COMPUTATION_TRACESET_CONTEXT
,
60 LTTV_BEFORE_CHUNK_TRACESET
,
61 LTTV_BEFORE_CHUNK_TRACE
,
62 LTTV_BEFORE_CHUNK_TRACEFILE
,
63 LTTV_AFTER_CHUNK_TRACESET
,
64 LTTV_AFTER_CHUNK_TRACE
,
65 LTTV_AFTER_CHUNK_TRACEFILE
,
69 LTTV_EVENT_HOOK_BY_ID
,
77 /** Array containing instanced objects. */
78 GSList
* g_main_window_list
= NULL
;
83 /* Initial trace from command line */
84 LttvTrace
*g_init_trace
= NULL
;
89 void lttv_trace_option(void *hook_data
)
92 gchar abs_path
[PATH_MAX
];
94 get_absolute_pathname(a_trace
, abs_path
);
95 g_init_trace
= lttvwindowtraces_get_trace_by_name(abs_path
);
96 if(g_init_trace
== NULL
) {
97 trace
= ltt_trace_open(abs_path
);
99 g_warning("cannot open trace %s", abs_path
);
101 g_init_trace
= lttv_trace_new(trace
);
102 lttvwindowtraces_add_trace(g_init_trace
);
107 /*****************************************************************************
108 * Functions for module loading/unloading *
109 *****************************************************************************/
111 * plugin's init function
113 * This function initializes the GUI.
116 static gboolean
window_creation_hook(void *hook_data
, void *call_data
)
118 g_debug("GUI window_creation_hook()");
120 bindtextdomain (GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
121 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
122 textdomain (GETTEXT_PACKAGE
);
126 gtk_init (<tv_argc
, <tv_argv
);
128 add_pixmap_directory (PACKAGE_DATA_DIR
"/" PACKAGE
"/pixmaps");
129 add_pixmap_directory ("pixmaps");
130 add_pixmap_directory ("../modules/gui/main/pixmaps");
132 construct_main_window(NULL
);
141 LttvAttributeValue value
;
143 // Global attributes only used for interaction with main() here.
144 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
146 LTTV_TRACES
= g_quark_from_string("traces");
147 LTTV_COMPUTATION
= g_quark_from_string("computation");
148 LTTV_VIEWER_CONSTRUCTORS
= g_quark_from_string("viewer_constructors");
149 LTTV_REQUESTS_QUEUE
= g_quark_from_string("requests_queue");
150 LTTV_REQUESTS_CURRENT
= g_quark_from_string("requests_current");
151 LTTV_NOTIFY_QUEUE
= g_quark_from_string("notify_queue");
152 LTTV_NOTIFY_CURRENT
= g_quark_from_string("notify_current");
153 LTTV_COMPUTATION_TRACESET
= g_quark_from_string("computation_traceset");
154 LTTV_COMPUTATION_TRACESET_CONTEXT
=
155 g_quark_from_string("computation_traceset_context");
156 LTTV_BEFORE_CHUNK_TRACESET
= g_quark_from_string("before_chunk_traceset");
157 LTTV_BEFORE_CHUNK_TRACE
= g_quark_from_string("before_chunk_trace");
158 LTTV_BEFORE_CHUNK_TRACEFILE
= g_quark_from_string("before_chunk_tracefile");
159 LTTV_AFTER_CHUNK_TRACESET
= g_quark_from_string("after_chunk_traceset");
160 LTTV_AFTER_CHUNK_TRACE
= g_quark_from_string("after_chunk_trace");
161 LTTV_AFTER_CHUNK_TRACEFILE
= g_quark_from_string("after_chunk_tracefile");
162 LTTV_BEFORE_REQUEST
= g_quark_from_string("before_request");
163 LTTV_AFTER_REQUEST
= g_quark_from_string("after_request");
164 LTTV_EVENT_HOOK
= g_quark_from_string("event_hook");
165 LTTV_EVENT_HOOK_BY_ID
= g_quark_from_string("event_hook_by_id");
166 LTTV_HOOK_ADDER
= g_quark_from_string("hook_adder");
167 LTTV_HOOK_REMOVER
= g_quark_from_string("hook_remover");
168 LTTV_IN_PROGRESS
= g_quark_from_string("in_progress");
169 LTTV_READY
= g_quark_from_string("ready");
170 LTTV_LOCK
= g_quark_from_string("lock");
172 g_debug("GUI init()");
174 lttv_option_add("trace", 't',
175 "add a trace to the trace set to analyse",
176 "pathname of the directory containing the trace",
177 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
179 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
180 LTTV_POINTER
, &value
));
181 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
183 lttv_hooks_add(main_hooks
, window_creation_hook
, NULL
, LTTV_PRIO_DEFAULT
);
186 /* Register state calculator */
187 LttvHooks
*hook_adder
= lttv_hooks_new();
188 lttv_hooks_add(hook_adder
, lttv_state_save_hook_add_event_hooks
, NULL
,
190 lttv_hooks_add(hook_adder
, lttv_state_hook_add_event_hooks
, NULL
,
192 LttvHooks
*hook_remover
= lttv_hooks_new();
193 lttv_hooks_add(hook_remover
, lttv_state_save_hook_remove_event_hooks
,
194 NULL
, LTTV_PRIO_DEFAULT
);
195 lttv_hooks_add(hook_remover
, lttv_state_hook_remove_event_hooks
,
196 NULL
, LTTV_PRIO_DEFAULT
);
197 /* Add state computation background hook adder to attributes */
198 lttvwindowtraces_register_computation_hooks(g_quark_from_string("state"),
199 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
200 hook_adder
, hook_remover
);
204 /* Register statistics calculator */
205 LttvHooks
*hook_adder
= lttv_hooks_new();
206 lttv_hooks_add(hook_adder
, lttv_stats_hook_add_event_hooks
, NULL
,
208 lttv_hooks_add(hook_adder
, lttv_state_hook_add_event_hooks
, NULL
,
210 LttvHooks
*hook_remover
= lttv_hooks_new();
211 lttv_hooks_add(hook_remover
, lttv_stats_hook_remove_event_hooks
,
212 NULL
, LTTV_PRIO_DEFAULT
);
213 lttv_hooks_add(hook_remover
, lttv_state_hook_remove_event_hooks
,
214 NULL
, LTTV_PRIO_DEFAULT
);
215 LttvHooks
*after_request
= lttv_hooks_new();
216 lttv_hooks_add(after_request
, lttv_stats_sum_traceset_hook
, NULL
,
218 /* Add state computation background hook adder to attributes */
219 lttvwindowtraces_register_computation_hooks(g_quark_from_string("stats"),
220 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
221 after_request
, NULL
, NULL
,
222 hook_adder
, hook_remover
);
227 main_window_destructor(MainWindow
* mw
)
229 g_assert(GTK_IS_WIDGET(mw
->mwindow
));
230 gtk_widget_destroy(mw
->mwindow
);
235 * plugin's destroy function
237 * This function releases the memory reserved by the module and unregisters
238 * everything that has been registered in the gtkTraceSet API.
240 static void destroy() {
242 LttvAttributeValue value
;
246 lttvwindowtraces_unregister_requests(g_quark_from_string("stats"));
247 lttvwindowtraces_unregister_requests(g_quark_from_string("state"));
248 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("stats"));
249 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("state"));
251 lttv_option_remove("trace");
253 lttv_hooks_remove_data(main_hooks
, window_creation_hook
, NULL
);
255 g_debug("GUI destroy()");
257 if(g_main_window_list
){
258 for(iter
=g_main_window_list
;iter
!=NULL
;iter
=g_slist_next(iter
)) {
259 main_window_destructor((MainWindow
*)iter
->data
);
261 g_slist_free(g_main_window_list
);
267 LTTV_MODULE("lttvwindow", "Viewer main window", \
268 "Viewer with multiple windows, tabs and panes for graphical modules", \
269 init
, destroy
, "stats", "option")