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