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