Commit | Line | Data |
---|---|---|
9c312311 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais | |
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 | ||
4e4d11b3 | 19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> | |
21 | #endif | |
eccb5352 | 22 | |
3d218f2a | 23 | #include <lttv/hook.h> |
24 | #include <lttv/module.h> | |
fcdf0ec2 | 25 | #include <lttv/lttv.h> |
ffd54a90 | 26 | #include <lttv/iattribute.h> |
fcdf0ec2 | 27 | #include <lttv/attribute.h> |
28 | #include <lttv/option.h> | |
dc877563 | 29 | #include <lttv/traceset.h> |
30 | #include <ltt/trace.h> | |
d888c9c8 | 31 | #include <stdio.h> |
00e74b69 | 32 | #include <string.h> |
d888c9c8 | 33 | |
eccb5352 | 34 | |
35 | /* The main program maintains a few central data structures and relies | |
36 | on modules for the rest. These data structures may be accessed by modules | |
37 | through an exported API */ | |
38 | ||
ffd54a90 | 39 | static LttvIAttribute *attributes; |
eccb5352 | 40 | |
dc877563 | 41 | static LttvHooks |
90e19f82 AM |
42 | *before_options, |
43 | *after_options, | |
44 | *before_main, | |
45 | *after_main; | |
eccb5352 | 46 | |
dc877563 | 47 | static char |
90e19f82 AM |
48 | *a_module, |
49 | *a_module_path; | |
eccb5352 | 50 | |
b445142a | 51 | static gboolean |
90e19f82 AM |
52 | a_verbose, |
53 | a_debug, | |
54 | a_fatal; | |
b445142a | 55 | |
dbb7bb09 | 56 | gboolean lttv_profile_memory; |
57 | ||
08b1c66e | 58 | int lttv_argc; |
eccb5352 | 59 | |
08b1c66e | 60 | char **lttv_argv; |
eccb5352 | 61 | |
62 | static void lttv_module_option(void *hook_data); | |
63 | ||
64 | static void lttv_module_path_option(void *hook_data); | |
65 | ||
b445142a | 66 | static void lttv_verbose(void *hook_data); |
67 | ||
68 | static void lttv_debug(void *hook_data); | |
69 | ||
91f8d488 | 70 | static void lttv_event_debug(void *hook_data); |
71 | ||
3754677c | 72 | static void lttv_fatal(void *hook_data); |
73 | ||
308711e5 | 74 | static void lttv_help(void *hook_data); |
dc877563 | 75 | |
2a2fa4f0 | 76 | /* This is the handler to specify when we dont need all the debugging |
77 | messages. It receives the message and does nothing. */ | |
78 | ||
79 | void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, | |
90e19f82 | 80 | const gchar *message, gpointer user_data) |
00100e0e | 81 | { |
2a2fa4f0 | 82 | } |
83 | ||
84 | ||
eccb5352 | 85 | /* Since everything is done in modules, the main program only takes care |
86 | of the infrastructure. */ | |
87 | ||
00100e0e | 88 | int main(int argc, char **argv) |
89 | { | |
eccb5352 | 90 | |
90e19f82 | 91 | int i; |
dbb7bb09 | 92 | |
90e19f82 AM |
93 | char |
94 | *profile_memory_short_option = "-M", | |
95 | *profile_memory_long_option = "--memory"; | |
dbb7bb09 | 96 | |
90e19f82 AM |
97 | gboolean profile_memory = FALSE; |
98 | gboolean retval; | |
dbb7bb09 | 99 | |
90e19f82 | 100 | LttvAttributeValue value; |
eccb5352 | 101 | |
90e19f82 AM |
102 | lttv_argc = argc; |
103 | lttv_argv = argv; | |
eccb5352 | 104 | |
90e19f82 | 105 | /* Before anything else, check if memory profiling is requested */ |
dbb7bb09 | 106 | |
90e19f82 AM |
107 | for(i = 1 ; i < argc ; i++) { |
108 | if(*(argv[i]) != '-') break; | |
109 | if(strcmp(argv[i], profile_memory_short_option) == 0 || | |
110 | strcmp(argv[i], profile_memory_long_option) == 0) { | |
111 | g_mem_set_vtable(glib_mem_profiler_table); | |
112 | g_message("Memory summary before main"); | |
113 | g_mem_profile(); | |
114 | profile_memory = TRUE; | |
115 | break; | |
116 | } | |
117 | } | |
dbb7bb09 | 118 | |
119 | ||
90e19f82 | 120 | /* Initialize glib and by default ignore info and debug messages */ |
2a2fa4f0 | 121 | |
90e19f82 AM |
122 | g_type_init(); |
123 | //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); | |
124 | g_log_set_handler(NULL, G_LOG_LEVEL_INFO, ignore_and_drop_message, NULL); | |
125 | g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_and_drop_message, NULL); | |
dbb7bb09 | 126 | |
127 | ||
90e19f82 | 128 | /* Have an attributes subtree to store hooks to be registered by modules. */ |
d83f6739 | 129 | |
90e19f82 | 130 | attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); |
eccb5352 | 131 | |
90e19f82 AM |
132 | before_options = lttv_hooks_new(); |
133 | after_options = lttv_hooks_new(); | |
134 | before_main = lttv_hooks_new(); | |
135 | after_main = lttv_hooks_new(); | |
eccb5352 | 136 | |
dbb7bb09 | 137 | |
90e19f82 | 138 | /* Create a number of hooks lists */ |
dbb7bb09 | 139 | |
90e19f82 AM |
140 | retval= lttv_iattribute_find_by_path(attributes, "hooks/options/before", |
141 | LTTV_POINTER, &value); | |
142 | g_assert(retval); | |
143 | *(value.v_pointer) = before_options; | |
144 | retval= lttv_iattribute_find_by_path(attributes, "hooks/options/after", | |
145 | LTTV_POINTER, &value); | |
146 | g_assert(retval); | |
147 | *(value.v_pointer) = after_options; | |
148 | retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", | |
149 | LTTV_POINTER, &value); | |
150 | g_assert(retval); | |
151 | *(value.v_pointer) = before_main; | |
152 | retval= lttv_iattribute_find_by_path(attributes, "hooks/main/after", | |
153 | LTTV_POINTER, &value); | |
154 | g_assert(retval); | |
155 | *(value.v_pointer) = after_main; | |
eccb5352 | 156 | |
eccb5352 | 157 | |
90e19f82 | 158 | /* Initialize the command line options processing */ |
eccb5352 | 159 | |
90e19f82 | 160 | GError *error = NULL; |
eccb5352 | 161 | |
90e19f82 AM |
162 | LttvModule *module_module = lttv_module_require("module", &error); |
163 | if(error != NULL) g_error("%s", error->message); | |
164 | LttvModule *module_option = lttv_module_require("option", &error); | |
165 | if(error != NULL) g_error("%s", error->message); | |
dbb7bb09 | 166 | |
90e19f82 | 167 | /* Initialize the module loading */ |
eccb5352 | 168 | |
90e19f82 | 169 | lttv_library_path_add(PACKAGE_PLUGIN_DIR); |
eccb5352 | 170 | |
dbb7bb09 | 171 | |
90e19f82 | 172 | /* Add some built-in options */ |
eccb5352 | 173 | |
90e19f82 AM |
174 | lttv_option_add("module",'m', "load a module", "name of module to load", |
175 | LTTV_OPT_STRING, &a_module, lttv_module_option, NULL); | |
eccb5352 | 176 | |
90e19f82 AM |
177 | lttv_option_add("modules-path", 'L', |
178 | "add a directory to the module search path", | |
179 | "directory to add to the path", LTTV_OPT_STRING, &a_module_path, | |
180 | lttv_module_path_option, NULL); | |
d888c9c8 | 181 | |
90e19f82 AM |
182 | lttv_option_add("help",'h', "basic help", "none", |
183 | LTTV_OPT_NONE, NULL, lttv_help, NULL); | |
b445142a | 184 | |
90e19f82 AM |
185 | a_verbose = FALSE; |
186 | lttv_option_add("verbose",'v', "print information messages", "none", | |
187 | LTTV_OPT_NONE, NULL, lttv_verbose, NULL); | |
b445142a | 188 | |
90e19f82 AM |
189 | a_debug = FALSE; |
190 | lttv_option_add("debug",'d', "print debugging messages", "none", | |
191 | LTTV_OPT_NONE, NULL, lttv_debug, NULL); | |
192 | ||
193 | /* use --edebug, -e conflicts with filter. Problem with option parsing when we | |
194 | * reparse the options with different number of arguments. */ | |
195 | lttv_option_add("edebug",'e', "print event debugging", "none", | |
196 | LTTV_OPT_NONE, NULL, lttv_event_debug, NULL); | |
197 | ||
198 | a_fatal = FALSE; | |
199 | lttv_option_add("fatal",'f', "make critical messages fatal", "none", | |
200 | LTTV_OPT_NONE, NULL, lttv_fatal, NULL); | |
d888c9c8 | 201 | |
90e19f82 AM |
202 | lttv_profile_memory = FALSE; |
203 | lttv_option_add(profile_memory_long_option + 2, | |
204 | profile_memory_short_option[1], "print memory information", "none", | |
205 | LTTV_OPT_NONE, <tv_profile_memory, NULL, NULL); | |
dbb7bb09 | 206 | |
207 | ||
90e19f82 | 208 | /* Process the options */ |
d888c9c8 | 209 | |
90e19f82 AM |
210 | lttv_hooks_call(before_options, NULL); |
211 | lttv_option_parse(argc, argv); | |
212 | lttv_hooks_call(after_options, NULL); | |
c432246e | 213 | |
dbb7bb09 | 214 | |
90e19f82 | 215 | /* Memory profiling to be useful must be activated as early as possible */ |
dbb7bb09 | 216 | |
90e19f82 AM |
217 | if(profile_memory != lttv_profile_memory) |
218 | g_error("Memory profiling options must appear before other options"); | |
dbb7bb09 | 219 | |
220 | ||
90e19f82 | 221 | /* Do the main work */ |
dbb7bb09 | 222 | |
90e19f82 AM |
223 | lttv_hooks_call(before_main, NULL); |
224 | lttv_hooks_call(after_main, NULL); | |
eccb5352 | 225 | |
dbb7bb09 | 226 | |
90e19f82 | 227 | /* Clean up everything */ |
dbb7bb09 | 228 | |
90e19f82 AM |
229 | lttv_module_release(module_option); |
230 | lttv_module_release(module_module); | |
dc877563 | 231 | |
90e19f82 AM |
232 | lttv_hooks_destroy(before_options); |
233 | lttv_hooks_destroy(after_options); | |
234 | lttv_hooks_destroy(before_main); | |
235 | lttv_hooks_destroy(after_main); | |
236 | g_object_unref(attributes); | |
eccb5352 | 237 | |
90e19f82 AM |
238 | if(profile_memory) { |
239 | g_message("Memory summary after main"); | |
240 | g_mem_profile(); | |
241 | } | |
242 | return 0; | |
eccb5352 | 243 | } |
244 | ||
dc877563 | 245 | |
ffd54a90 | 246 | LttvAttribute *lttv_global_attributes() |
1cab0928 | 247 | { |
90e19f82 | 248 | return (LttvAttribute*)attributes; |
1cab0928 | 249 | } |
250 | ||
251 | ||
eccb5352 | 252 | void lttv_module_option(void *hook_data) |
00100e0e | 253 | { |
90e19f82 | 254 | GError *error = NULL; |
08b1c66e | 255 | |
90e19f82 AM |
256 | lttv_module_require(a_module, &error); |
257 | if(error != NULL) g_error("%s", error->message); | |
eccb5352 | 258 | } |
259 | ||
260 | ||
261 | void lttv_module_path_option(void *hook_data) | |
262 | { | |
90e19f82 | 263 | lttv_library_path_add(a_module_path); |
eccb5352 | 264 | } |
d888c9c8 | 265 | |
2a2fa4f0 | 266 | |
b445142a | 267 | void lttv_verbose(void *hook_data) |
268 | { | |
90e19f82 AM |
269 | g_log_set_handler(NULL, G_LOG_LEVEL_INFO, g_log_default_handler, NULL); |
270 | g_info("Logging set to include INFO level messages"); | |
b445142a | 271 | } |
272 | ||
273 | void lttv_debug(void *hook_data) | |
274 | { | |
90e19f82 AM |
275 | g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, g_log_default_handler, NULL); |
276 | g_info("Logging set to include DEBUG level messages"); | |
b445142a | 277 | } |
278 | ||
91f8d488 | 279 | void lttv_event_debug(void *hook_data) |
280 | { | |
90e19f82 AM |
281 | ltt_event_debug(1); |
282 | g_info("Output event detailed debug"); | |
91f8d488 | 283 | } |
284 | ||
3754677c | 285 | void lttv_fatal(void *hook_data) |
286 | { | |
90e19f82 AM |
287 | g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); |
288 | //g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); | |
289 | g_info("Critical log from glib will abort execution"); | |
3754677c | 290 | } |
291 | ||
308711e5 | 292 | void lttv_help(void *hook_data) |
d888c9c8 | 293 | { |
90e19f82 AM |
294 | printf("Linux Trace Toolkit Visualizer " VERSION "\n"); |
295 | printf("\n"); | |
296 | lttv_option_show_help(); | |
297 | printf("\n"); | |
d888c9c8 | 298 | } |
b445142a | 299 | |
308711e5 | 300 | /* |
301 | ||
308711e5 | 302 | - Define formally traceset/trace in the GUI for the user and decide how |
90e19f82 | 303 | trace/traceset sharing goes in the application. |
308711e5 | 304 | |
305 | - Use appropriately the new functions in time.h | |
306 | ||
307 | - remove the separate tracefiles (control/per cpu) arrays/loops in context. | |
308 | ||
309 | - split processTrace into context.c and processTrace.c | |
310 | ||
311 | - check spelling conventions. | |
312 | ||
313 | - get all the copyright notices. | |
314 | ||
315 | - remove all the warnings. | |
316 | ||
317 | - get all the .h files properly doxygen commented to produce useful documents. | |
318 | ||
319 | - have an intro/architecture document. | |
320 | ||
321 | - write a tutorial */ |