| 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 | |
| 11 | void lttv_option_init(int argc, char **argv); |
| 12 | void lttv_option_destroy(); |
| 13 | |
| 14 | void lttv_module_init(int argc, char **argv); |
| 15 | void lttv_module_destroy(); |
| 16 | |
| 17 | void lttv_state_init(int argc, char **argv); |
| 18 | void lttv_state_destroy(); |
| 19 | |
| 20 | /* The main program maintains a few central data structures and relies |
| 21 | on modules for the rest. These data structures may be accessed by modules |
| 22 | through an exported API */ |
| 23 | |
| 24 | static LttvIAttribute *attributes; |
| 25 | |
| 26 | static LttvHooks |
| 27 | *before_options, |
| 28 | *after_options, |
| 29 | *before_main, |
| 30 | *after_main; |
| 31 | |
| 32 | static char |
| 33 | *a_module, |
| 34 | *a_module_path; |
| 35 | |
| 36 | static int a_argc; |
| 37 | |
| 38 | static char **a_argv; |
| 39 | |
| 40 | static void lttv_module_option(void *hook_data); |
| 41 | |
| 42 | static void lttv_module_path_option(void *hook_data); |
| 43 | |
| 44 | #ifdef MEMDEBUG |
| 45 | extern struct GMemVTable *glib_mem_profiler_table; |
| 46 | #endif |
| 47 | |
| 48 | |
| 49 | /* Since everything is done in modules, the main program only takes care |
| 50 | of the infrastructure. */ |
| 51 | |
| 52 | int main(int argc, char **argv) { |
| 53 | |
| 54 | LttvAttributeValue value; |
| 55 | |
| 56 | #ifdef MEMDEBUG |
| 57 | g_mem_set_vtable(glib_mem_profiler_table); |
| 58 | g_message("Memory summary before main"); |
| 59 | g_mem_profile(); |
| 60 | #endif |
| 61 | |
| 62 | //g_type_init(); |
| 63 | g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); |
| 64 | |
| 65 | attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); |
| 66 | |
| 67 | before_options = lttv_hooks_new(); |
| 68 | after_options = lttv_hooks_new(); |
| 69 | before_main = lttv_hooks_new(); |
| 70 | after_main = lttv_hooks_new(); |
| 71 | |
| 72 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before", |
| 73 | LTTV_POINTER, &value)); |
| 74 | *(value.v_pointer) = before_options; |
| 75 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after", |
| 76 | LTTV_POINTER, &value)); |
| 77 | *(value.v_pointer) = after_options; |
| 78 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
| 79 | LTTV_POINTER, &value)); |
| 80 | *(value.v_pointer) = before_main; |
| 81 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after", |
| 82 | LTTV_POINTER, &value)); |
| 83 | *(value.v_pointer) = after_main; |
| 84 | |
| 85 | |
| 86 | /* Initialize the command line options processing */ |
| 87 | |
| 88 | lttv_option_init(argc,argv); |
| 89 | lttv_module_init(argc,argv); |
| 90 | lttv_state_init(argc,argv); |
| 91 | |
| 92 | /* Initialize the module loading */ |
| 93 | |
| 94 | lttv_module_path_add("/usr/lib/lttv/plugins"); |
| 95 | |
| 96 | /* Add some built-in options */ |
| 97 | |
| 98 | lttv_option_add("module",'m', "load a module", "name of module to load", |
| 99 | LTTV_OPT_STRING, &a_module, lttv_module_option, NULL); |
| 100 | |
| 101 | lttv_option_add("modules-path", 'L', |
| 102 | "add a directory to the module search path", |
| 103 | "directory to add to the path", LTTV_OPT_STRING, &a_module_path, |
| 104 | lttv_module_path_option, NULL); |
| 105 | |
| 106 | lttv_hooks_call(before_options, NULL); |
| 107 | lttv_option_parse(argc, argv); |
| 108 | lttv_hooks_call(after_options, NULL); |
| 109 | |
| 110 | lttv_hooks_call(before_main, NULL); |
| 111 | lttv_hooks_call(after_main, NULL); |
| 112 | |
| 113 | lttv_state_destroy(); |
| 114 | lttv_module_destroy(); |
| 115 | lttv_option_destroy(); |
| 116 | |
| 117 | lttv_hooks_destroy(before_options); |
| 118 | lttv_hooks_destroy(after_options); |
| 119 | lttv_hooks_destroy(before_main); |
| 120 | lttv_hooks_destroy(after_main); |
| 121 | g_object_unref(attributes); |
| 122 | |
| 123 | #ifdef MEMDEBUG |
| 124 | g_message("Memory summary after main"); |
| 125 | g_mem_profile(); |
| 126 | #endif |
| 127 | } |
| 128 | |
| 129 | |
| 130 | LttvAttribute *lttv_global_attributes() |
| 131 | { |
| 132 | return (LttvAttribute*)attributes; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | void lttv_module_option(void *hook_data) |
| 137 | { |
| 138 | lttv_module_load(a_module,a_argc,a_argv); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void lttv_module_path_option(void *hook_data) |
| 143 | { |
| 144 | lttv_module_path_add(a_module_path); |
| 145 | } |