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