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