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