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