Add state saving functions and update processTrace accordingly.
[lttv.git] / ltt / branches / poly / lttv / main.c
1
2 #include <lttv/hook.h>
3 #include <lttv/module.h>
4 #include <lttv/lttv.h>
5 #include <lttv/iattribute.h>
6 #include <lttv/attribute.h>
7 #include <lttv/option.h>
8 #include <lttv/traceset.h>
9 #include <ltt/trace.h>
10 #include <stdio.h>
11
12
13 void lttv_option_init(int argc, char **argv);
14 void lttv_option_destroy();
15
16 void lttv_module_init(int argc, char **argv);
17 void lttv_module_destroy();
18
19 void lttv_state_init(int argc, char **argv);
20 void lttv_state_destroy();
21
22 void lttv_stats_init(int argc, char **argv);
23 void lttv_stats_destroy();
24
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
29 static LttvIAttribute *attributes;
30
31 static LttvHooks
32 *before_options,
33 *after_options,
34 *before_main,
35 *after_main;
36
37 static char
38 *a_module,
39 *a_module_path;
40
41 static gboolean
42 a_verbose,
43 a_debug;
44
45 static int a_argc;
46
47 static char **a_argv;
48
49 static void lttv_module_option(void *hook_data);
50
51 static void lttv_module_path_option(void *hook_data);
52
53 static void lttv_verbose(void *hook_data);
54
55 static void lttv_debug(void *hook_data);
56
57 static void lttv_help(void *hook_data);
58
59 /* Since everything is done in modules, the main program only takes care
60 of the infrastructure. */
61
62 int main(int argc, char **argv) {
63
64 LttvAttributeValue value;
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
72 g_type_init();
73 //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS);
74
75 attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
76
77 before_options = lttv_hooks_new();
78 after_options = lttv_hooks_new();
79 before_main = lttv_hooks_new();
80 after_main = lttv_hooks_new();
81
82 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
83 LTTV_POINTER, &value));
84 *(value.v_pointer) = before_options;
85 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
86 LTTV_POINTER, &value));
87 *(value.v_pointer) = after_options;
88 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
89 LTTV_POINTER, &value));
90 *(value.v_pointer) = before_main;
91 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
92 LTTV_POINTER, &value));
93 *(value.v_pointer) = after_main;
94
95
96 /* Initialize the command line options processing */
97
98 a_argc = argc;
99 a_argv = argv;
100 lttv_option_init(argc,argv);
101 lttv_module_init(argc,argv);
102 lttv_state_init(argc,argv);
103 lttv_stats_init(argc,argv);
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",
112 LTTV_OPT_STRING, &a_module, lttv_module_option, NULL);
113
114 lttv_option_add("modules-path", 'L',
115 "add a directory to the module search path",
116 "directory to add to the path", LTTV_OPT_STRING, &a_module_path,
117 lttv_module_path_option, NULL);
118
119 lttv_option_add("help",'h', "basic help", "none",
120 LTTV_OPT_NONE, NULL, lttv_help, NULL);
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);
129
130
131 lttv_hooks_call(before_options, NULL);
132 lttv_option_parse(argc, argv);
133 lttv_hooks_call(after_options, NULL);
134
135 lttv_hooks_call(before_main, NULL);
136 lttv_hooks_call(after_main, NULL);
137
138 lttv_stats_destroy();
139 lttv_state_destroy();
140 lttv_module_destroy();
141 lttv_option_destroy();
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);
148
149 #ifdef MEMDEBUG
150 g_message("Memory summary after main");
151 g_mem_profile();
152 #endif
153 }
154
155
156 LttvAttribute *lttv_global_attributes()
157 {
158 return (LttvAttribute*)attributes;
159 }
160
161
162 void lttv_module_option(void *hook_data)
163 {
164 lttv_module_load(a_module,a_argc,a_argv);
165 }
166
167
168 void lttv_module_path_option(void *hook_data)
169 {
170 lttv_module_path_add(a_module_path);
171 }
172
173 void 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
179 void 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
185 void lttv_help(void *hook_data)
186 {
187 printf("Linux Trace Toolkit Visualizer\n");
188 printf("\n");
189 lttv_option_show_help();
190 printf("\n");
191 }
192
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.033522 seconds and 4 git commands to generate.