eccb5352 |
1 | |
4accaa97 |
2 | #include "lttv.h" |
3 | #include "trace.h" |
eccb5352 |
4 | |
5 | |
6 | /* The main program maintains a few central data structures and relies |
7 | on modules for the rest. These data structures may be accessed by modules |
8 | through an exported API */ |
9 | |
10 | /* Extensible array of popt command line options. Modules add options as |
11 | they are loaded and initialized. */ |
12 | |
13 | |
4accaa97 |
14 | static lttv_attributes *attributes_global; |
eccb5352 |
15 | |
16 | static lttv_hooks |
17 | *hooks_init_after, |
18 | *hooks_program_before, |
19 | *hooks_program_main, |
20 | *hooks_program_after; |
21 | |
22 | // trace sets has to be put one in each new window_traceset |
23 | static lttv_trace_set *traces; |
24 | |
25 | static char *aModule, *aPath, *aTrace; |
26 | |
27 | static int aArgc; |
28 | |
29 | static char **aArgv; |
30 | |
31 | static void lttv_module_option(void *hook_data); |
32 | |
33 | static void lttv_module_path_option(void *hook_data); |
34 | |
35 | static void lttv_trace_option(void *hook_data); |
36 | |
37 | #ifdef MEMDEBUG |
38 | extern struct GMemVTable *glib_mem_profiler_table; |
39 | #endif |
40 | |
41 | /* Since everything is done in modules, the main program only takes care |
42 | of the infrastructure. */ |
43 | |
44 | int main(int argc, char **argv) { |
45 | |
46 | aArgc = argc; |
47 | aArgv = argv; |
48 | |
49 | #ifdef MEMDEBUG |
50 | g_mem_set_vtable(glib_mem_profiler_table); |
51 | g_message("Memory summary before main"); |
52 | g_mem_profile(); |
53 | #endif |
54 | |
55 | attributes_global = lttv_attributes_new(); |
56 | |
57 | // traces = lttv_trace_set_new(); |
58 | // lttv_attributes_set_pointer_pathname(attributes_global, "trace_set/default", traces); |
59 | |
60 | /* Initialize the hooks */ |
61 | |
62 | hooks_init_after = lttv_hooks_new(); |
63 | lttv_attributes_set_pointer_pathname(attributes_global, "hooks/init/after", |
64 | hooks_init_after); |
65 | |
66 | |
67 | hooks_program_before = lttv_hooks_new(); |
68 | lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/before", |
69 | hooks_program_before); |
70 | |
71 | hooks_program_main = lttv_hooks_new(); |
72 | lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/main", |
73 | hooks_program_main); |
74 | |
75 | hooks_program_after = lttv_hooks_new(); |
76 | lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/after", |
77 | hooks_program_after); |
78 | |
79 | /* Initialize the command line options processing */ |
80 | |
81 | lttv_option_init(argc,argv); |
82 | lttv_module_init(argc,argv); |
83 | // FIXME lttv_analyse_init(argc,argv); |
84 | |
85 | /* Initialize the module loading */ |
86 | |
87 | lttv_module_path_add("/usr/lib/lttv/plugins"); |
88 | |
89 | /* Add some built-in options */ |
90 | |
91 | lttv_option_add("module",'m', "load a module", "name of module to load", |
92 | LTTV_OPT_STRING, &aModule, lttv_module_option, NULL); |
93 | |
94 | lttv_option_add("modules-path", 'L', |
95 | "add a directory to the module search path", |
96 | "directory to add to the path", LTTV_OPT_STRING, &aPath, |
97 | lttv_module_path_option, NULL); |
98 | |
99 | lttv_option_add("trace", 't', |
100 | "add a trace to the trace set to analyse", |
101 | "pathname of the directory containing the trace", |
102 | LTTV_OPT_STRING, &aTrace, lttv_trace_option, NULL); |
103 | |
104 | lttv_hooks_call(hooks_init_after, NULL); |
105 | |
106 | lttv_hooks_call(hooks_program_before, NULL); |
107 | lttv_hooks_call(hooks_program_main, NULL); |
108 | lttv_hooks_call(hooks_program_after, NULL); |
109 | |
110 | /* Finalize the command line options processing */ |
111 | lttv_module_destroy(); |
112 | lttv_option_destroy(); |
113 | // FIXME lttv_analyse_destroy(); |
114 | lttv_attributes_destroy(attributes_global); |
115 | |
116 | #ifdef MEMDEBUG |
117 | g_message("Memory summary after main"); |
118 | g_mem_profile(); |
119 | #endif |
120 | |
121 | |
122 | } |
123 | |
124 | void lttv_module_option(void *hook_data) |
125 | { |
126 | lttv_module_load(aModule,aArgc,aArgv,STANDALONE); |
127 | } |
128 | |
129 | |
130 | void lttv_module_path_option(void *hook_data) |
131 | { |
132 | lttv_module_path_add(aPath); |
133 | } |
134 | |
135 | |
136 | void lttv_trace_option(void *hook_data) |
137 | { |
138 | // lttv_trace *trace; |
139 | |
140 | // trace = lttv_trace_open(aTrace); |
141 | // if(trace == NULL) g_critical("cannot open trace %s", aTrace); |
142 | // lttv_trace_set_add(traces, trace); |
143 | } |
144 | |