Add copyright notices and some comments about status and TODO
[lttv.git] / ltt / branches / poly / lttv / main / main.c
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
19
20 #include <lttv/hook.h>
21 #include <lttv/module.h>
22 #include <lttv/lttv.h>
23 #include <lttv/iattribute.h>
24 #include <lttv/attribute.h>
25 #include <lttv/option.h>
26 #include <lttv/traceset.h>
27 #include <ltt/trace.h>
28 #include <stdio.h>
29
30
31 void lttv_option_init(int argc, char **argv);
32 void lttv_option_destroy();
33
34 void lttv_module_init(int argc, char **argv);
35 void lttv_module_destroy();
36
37 void lttv_state_init(int argc, char **argv);
38 void lttv_state_destroy();
39
40 void lttv_stats_init(int argc, char **argv);
41 void lttv_stats_destroy();
42
43 /* The main program maintains a few central data structures and relies
44 on modules for the rest. These data structures may be accessed by modules
45 through an exported API */
46
47 static LttvIAttribute *attributes;
48
49 static LttvHooks
50 *before_options,
51 *after_options,
52 *before_main,
53 *after_main;
54
55 static char
56 *a_module,
57 *a_module_path;
58
59 static gboolean
60 a_verbose,
61 a_debug;
62
63 static int a_argc;
64
65 static char **a_argv;
66
67 static void lttv_module_option(void *hook_data);
68
69 static void lttv_module_path_option(void *hook_data);
70
71 static void lttv_verbose(void *hook_data);
72
73 static void lttv_debug(void *hook_data);
74
75 static void lttv_help(void *hook_data);
76
77 /* Since everything is done in modules, the main program only takes care
78 of the infrastructure. */
79
80 int main(int argc, char **argv) {
81
82 LttvAttributeValue value;
83
84 #ifdef MEMDEBUG
85 g_mem_set_vtable(glib_mem_profiler_table);
86 g_message("Memory summary before main");
87 g_mem_profile();
88 #endif
89
90 g_type_init();
91 //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS);
92
93 attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
94
95 before_options = lttv_hooks_new();
96 after_options = lttv_hooks_new();
97 before_main = lttv_hooks_new();
98 after_main = lttv_hooks_new();
99
100 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
101 LTTV_POINTER, &value));
102 *(value.v_pointer) = before_options;
103 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
104 LTTV_POINTER, &value));
105 *(value.v_pointer) = after_options;
106 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
107 LTTV_POINTER, &value));
108 *(value.v_pointer) = before_main;
109 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
110 LTTV_POINTER, &value));
111 *(value.v_pointer) = after_main;
112
113
114 /* Initialize the command line options processing */
115
116 a_argc = argc;
117 a_argv = argv;
118 lttv_option_init(argc,argv);
119 lttv_module_init(argc,argv);
120 lttv_state_init(argc,argv);
121 lttv_stats_init(argc,argv);
122
123 /* Initialize the module loading */
124
125 lttv_module_path_add("/usr/lib/lttv/plugins");
126
127 /* Add some built-in options */
128
129 lttv_option_add("module",'m', "load a module", "name of module to load",
130 LTTV_OPT_STRING, &a_module, lttv_module_option, NULL);
131
132 lttv_option_add("modules-path", 'L',
133 "add a directory to the module search path",
134 "directory to add to the path", LTTV_OPT_STRING, &a_module_path,
135 lttv_module_path_option, NULL);
136
137 lttv_option_add("help",'h', "basic help", "none",
138 LTTV_OPT_NONE, NULL, lttv_help, NULL);
139
140 a_verbose = FALSE;
141 lttv_option_add("verbose",'v', "print information messages", "none",
142 LTTV_OPT_NONE, NULL, lttv_verbose, NULL);
143
144 a_debug = FALSE;
145 lttv_option_add("debug",'d', "print debugging messages", "none",
146 LTTV_OPT_NONE, NULL, lttv_debug, NULL);
147
148
149 lttv_hooks_call(before_options, NULL);
150 lttv_option_parse(argc, argv);
151 lttv_hooks_call(after_options, NULL);
152
153 lttv_hooks_call(before_main, NULL);
154 lttv_hooks_call(after_main, NULL);
155
156 lttv_stats_destroy();
157 lttv_state_destroy();
158 lttv_module_destroy();
159 lttv_option_destroy();
160
161 lttv_hooks_destroy(before_options);
162 lttv_hooks_destroy(after_options);
163 lttv_hooks_destroy(before_main);
164 lttv_hooks_destroy(after_main);
165 g_object_unref(attributes);
166
167 #ifdef MEMDEBUG
168 g_message("Memory summary after main");
169 g_mem_profile();
170 #endif
171 }
172
173
174 LttvAttribute *lttv_global_attributes()
175 {
176 return (LttvAttribute*)attributes;
177 }
178
179
180 void lttv_module_option(void *hook_data)
181 {
182 lttv_module_load(a_module,a_argc,a_argv);
183 }
184
185
186 void lttv_module_path_option(void *hook_data)
187 {
188 lttv_module_path_add(a_module_path);
189 }
190
191 void lttv_verbose(void *hook_data)
192 {
193 g_log_set_handler(NULL, G_LOG_LEVEL_INFO, g_log_default_handler, NULL);
194 g_info("Logging set to include INFO level messages");
195 }
196
197 void lttv_debug(void *hook_data)
198 {
199 g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, g_log_default_handler, NULL);
200 g_info("Logging set to include DEBUG level messages");
201 }
202
203 void lttv_help(void *hook_data)
204 {
205 printf("Linux Trace Toolkit Visualizer\n");
206 printf("\n");
207 lttv_option_show_help();
208 printf("\n");
209 }
210
211 /*
212
213 - Make it easier to change modules from builtin to externally loaded.
214
215 have: MODULE_INFO(name, init, destroy, { require} ) in each module.
216 Maintain the list of builtin modules and search these first (or
217 optionally last). Add the lib prefix if needed to avoid having to
218 specify libbatchAnalysis instead of batchAnalysis.
219
220 - Define formally traceset/trace in the GUI for the user and decide how
221 trace/traceset sharing goes in the application.
222
223 - Use appropriately the new functions in time.h
224
225 - remove the separate tracefiles (control/per cpu) arrays/loops in context.
226
227 - split processTrace into context.c and processTrace.c
228
229 - check spelling conventions.
230
231 - get all the copyright notices.
232
233 - remove all the warnings.
234
235 - get all the .h files properly doxygen commented to produce useful documents.
236
237 - have an intro/architecture document.
238
239 - write a tutorial */
This page took 0.035983 seconds and 4 git commands to generate.