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