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 |
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(); |
fcdf0ec2 |
18 | |
ffd54a90 |
19 | void lttv_state_init(int argc, char **argv); |
20 | void lttv_state_destroy(); |
21 | |
eccb5352 |
22 | /* The main program maintains a few central data structures and relies |
23 | on modules for the rest. These data structures may be accessed by modules |
24 | through an exported API */ |
25 | |
ffd54a90 |
26 | static LttvIAttribute *attributes; |
eccb5352 |
27 | |
dc877563 |
28 | static LttvHooks |
29 | *before_options, |
30 | *after_options, |
31 | *before_main, |
32 | *after_main; |
eccb5352 |
33 | |
dc877563 |
34 | static char |
35 | *a_module, |
36 | *a_module_path; |
eccb5352 |
37 | |
dc877563 |
38 | static int a_argc; |
eccb5352 |
39 | |
dc877563 |
40 | static char **a_argv; |
eccb5352 |
41 | |
42 | static void lttv_module_option(void *hook_data); |
43 | |
44 | static void lttv_module_path_option(void *hook_data); |
45 | |
d888c9c8 |
46 | static void lttv_help(void); |
dc877563 |
47 | |
eccb5352 |
48 | /* Since everything is done in modules, the main program only takes care |
49 | of the infrastructure. */ |
50 | |
51 | int main(int argc, char **argv) { |
52 | |
ffd54a90 |
53 | LttvAttributeValue value; |
eccb5352 |
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 | |
41f18f3e |
61 | g_type_init(); |
62 | //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); |
d83f6739 |
63 | |
ffd54a90 |
64 | attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); |
eccb5352 |
65 | |
dc877563 |
66 | before_options = lttv_hooks_new(); |
67 | after_options = lttv_hooks_new(); |
68 | before_main = lttv_hooks_new(); |
69 | after_main = lttv_hooks_new(); |
eccb5352 |
70 | |
dc877563 |
71 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before", |
72 | LTTV_POINTER, &value)); |
ffd54a90 |
73 | *(value.v_pointer) = before_options; |
dc877563 |
74 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after", |
75 | LTTV_POINTER, &value)); |
ffd54a90 |
76 | *(value.v_pointer) = after_options; |
dc877563 |
77 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
78 | LTTV_POINTER, &value)); |
ffd54a90 |
79 | *(value.v_pointer) = before_main; |
dc877563 |
80 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after", |
81 | LTTV_POINTER, &value)); |
ffd54a90 |
82 | *(value.v_pointer) = after_main; |
eccb5352 |
83 | |
eccb5352 |
84 | |
85 | /* Initialize the command line options processing */ |
86 | |
87 | lttv_option_init(argc,argv); |
88 | lttv_module_init(argc,argv); |
ffd54a90 |
89 | lttv_state_init(argc,argv); |
eccb5352 |
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", |
ffd54a90 |
98 | LTTV_OPT_STRING, &a_module, lttv_module_option, NULL); |
eccb5352 |
99 | |
100 | lttv_option_add("modules-path", 'L', |
101 | "add a directory to the module search path", |
ffd54a90 |
102 | "directory to add to the path", LTTV_OPT_STRING, &a_module_path, |
eccb5352 |
103 | lttv_module_path_option, NULL); |
d888c9c8 |
104 | |
105 | lttv_option_add("help",'h', "basic help", "none", |
106 | LTTV_OPT_NONE, NULL, lttv_help, NULL); |
107 | |
108 | |
dc877563 |
109 | lttv_hooks_call(before_options, NULL); |
c432246e |
110 | lttv_option_parse(argc, argv); |
dc877563 |
111 | lttv_hooks_call(after_options, NULL); |
c432246e |
112 | |
dc877563 |
113 | lttv_hooks_call(before_main, NULL); |
114 | lttv_hooks_call(after_main, NULL); |
eccb5352 |
115 | |
ffd54a90 |
116 | lttv_state_destroy(); |
eccb5352 |
117 | lttv_module_destroy(); |
118 | lttv_option_destroy(); |
dc877563 |
119 | |
120 | lttv_hooks_destroy(before_options); |
121 | lttv_hooks_destroy(after_options); |
122 | lttv_hooks_destroy(before_main); |
123 | lttv_hooks_destroy(after_main); |
124 | g_object_unref(attributes); |
eccb5352 |
125 | |
126 | #ifdef MEMDEBUG |
127 | g_message("Memory summary after main"); |
128 | g_mem_profile(); |
129 | #endif |
eccb5352 |
130 | } |
131 | |
dc877563 |
132 | |
ffd54a90 |
133 | LttvAttribute *lttv_global_attributes() |
1cab0928 |
134 | { |
cbe7c836 |
135 | return (LttvAttribute*)attributes; |
1cab0928 |
136 | } |
137 | |
138 | |
eccb5352 |
139 | void lttv_module_option(void *hook_data) |
140 | { |
dc877563 |
141 | lttv_module_load(a_module,a_argc,a_argv); |
eccb5352 |
142 | } |
143 | |
144 | |
145 | void lttv_module_path_option(void *hook_data) |
146 | { |
ffd54a90 |
147 | lttv_module_path_add(a_module_path); |
eccb5352 |
148 | } |
d888c9c8 |
149 | |
150 | void lttv_help() |
151 | { |
152 | printf("Linux Trace Toolkit Visualizer\n"); |
153 | printf("\n"); |
154 | lttv_option_show_help(); |
155 | printf("\n"); |
156 | } |