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