X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmain%2Fmain.c;h=a27519e8fe2c1791a912bc43742fe7bad34a8630;hb=338d4282832c1e0002ccdeeb36555271959dd57b;hp=6578c24d6b66aaeebfa19221a87c4a699711890e;hpb=9c3123113f395e7ea634c522e340604331359e7e;p=lttv.git diff --git a/ltt/branches/poly/lttv/main/main.c b/ltt/branches/poly/lttv/main/main.c index 6578c24d..a27519e8 100644 --- a/ltt/branches/poly/lttv/main/main.c +++ b/ltt/branches/poly/lttv/main/main.c @@ -28,18 +28,6 @@ #include -void lttv_option_init(int argc, char **argv); -void lttv_option_destroy(); - -void lttv_module_init(int argc, char **argv); -void lttv_module_destroy(); - -void lttv_state_init(int argc, char **argv); -void lttv_state_destroy(); - -void lttv_stats_init(int argc, char **argv); -void lttv_stats_destroy(); - /* The main program maintains a few central data structures and relies on modules for the rest. These data structures may be accessed by modules through an exported API */ @@ -60,9 +48,11 @@ static gboolean a_verbose, a_debug; -static int a_argc; +gboolean lttv_profile_memory; + +int lttv_argc; -static char **a_argv; +char **lttv_argv; static void lttv_module_option(void *hook_data); @@ -74,21 +64,56 @@ static void lttv_debug(void *hook_data); static void lttv_help(void *hook_data); +/* This is the handler to specify when we dont need all the debugging + messages. It receives the message and does nothing. */ + +void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer user_data) { +} + + /* Since everything is done in modules, the main program only takes care of the infrastructure. */ int main(int argc, char **argv) { + int i; + + char + *profile_memory_short_option = "-M", + *profile_memory_long_option = "--memory"; + + gboolean profile_memory = FALSE; + LttvAttributeValue value; -#ifdef MEMDEBUG - g_mem_set_vtable(glib_mem_profiler_table); - g_message("Memory summary before main"); - g_mem_profile(); -#endif + lttv_argc = argc; + lttv_argv = argv; + + /* Before anything else, check if memory profiling is requested */ + + for(i = 1 ; i < argc ; i++) { + if(*(argv[i]) != '-') break; + if(strcmp(argv[i], profile_memory_short_option) == 0 || + strcmp(argv[i], profile_memory_long_option) == 0) { + g_mem_set_vtable(glib_mem_profiler_table); + g_message("Memory summary before main"); + g_mem_profile(); + profile_memory = TRUE; + break; + } + } + + + /* Initialize glib and by default ignore info and debug messages */ g_type_init(); //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); + g_log_set_handler(NULL, G_LOG_LEVEL_INFO, ignore_and_drop_message, NULL); + g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_and_drop_message, NULL); + + + /* Have an attributes subtree to store hooks to be registered by modules. */ attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); @@ -97,6 +122,9 @@ int main(int argc, char **argv) { before_main = lttv_hooks_new(); after_main = lttv_hooks_new(); + + /* Create a number of hooks lists */ + g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before", LTTV_POINTER, &value)); *(value.v_pointer) = before_options; @@ -113,16 +141,17 @@ int main(int argc, char **argv) { /* Initialize the command line options processing */ - a_argc = argc; - a_argv = argv; - lttv_option_init(argc,argv); - lttv_module_init(argc,argv); - lttv_state_init(argc,argv); - lttv_stats_init(argc,argv); + GError *error = NULL; + + LttvModule *module_module = lttv_module_require("module", &error); + if(error != NULL) g_error(error->message); + LttvModule *module_option = lttv_module_require("option", &error); + if(error != NULL) g_error(error->message); /* Initialize the module loading */ - lttv_module_path_add("/usr/lib/lttv/plugins"); + lttv_library_path_add(PACKAGE_PLUGIN_DIR); + /* Add some built-in options */ @@ -145,18 +174,35 @@ int main(int argc, char **argv) { lttv_option_add("debug",'d', "print debugging messages", "none", LTTV_OPT_NONE, NULL, lttv_debug, NULL); + lttv_profile_memory = FALSE; + lttv_option_add(profile_memory_long_option + 2, + profile_memory_short_option[1], "print memory information", "none", + LTTV_OPT_NONE, <tv_profile_memory, NULL, NULL); + + + /* Process the options */ lttv_hooks_call(before_options, NULL); lttv_option_parse(argc, argv); lttv_hooks_call(after_options, NULL); + + /* Memory profiling to be useful must be activated as early as possible */ + + if(profile_memory != lttv_profile_memory) + g_error("Memory profiling options must appear before other options"); + + + /* Do the main work */ + lttv_hooks_call(before_main, NULL); lttv_hooks_call(after_main, NULL); - lttv_stats_destroy(); - lttv_state_destroy(); - lttv_module_destroy(); - lttv_option_destroy(); + + /* Clean up everything */ + + lttv_module_release(module_option); + lttv_module_release(module_module); lttv_hooks_destroy(before_options); lttv_hooks_destroy(after_options); @@ -164,10 +210,11 @@ int main(int argc, char **argv) { lttv_hooks_destroy(after_main); g_object_unref(attributes); -#ifdef MEMDEBUG + if(profile_memory) { g_message("Memory summary after main"); g_mem_profile(); -#endif + } + return 0; } @@ -179,15 +226,19 @@ LttvAttribute *lttv_global_attributes() void lttv_module_option(void *hook_data) { - lttv_module_load(a_module,a_argc,a_argv); + GError *error = NULL; + + lttv_module_require(a_module, &error); + if(error != NULL) g_error(error->message); } void lttv_module_path_option(void *hook_data) { - lttv_module_path_add(a_module_path); + lttv_library_path_add(a_module_path); } + void lttv_verbose(void *hook_data) { g_log_set_handler(NULL, G_LOG_LEVEL_INFO, g_log_default_handler, NULL); @@ -210,13 +261,6 @@ void lttv_help(void *hook_data) /* -- Make it easier to change modules from builtin to externally loaded. - - have: MODULE_INFO(name, init, destroy, { require} ) in each module. - Maintain the list of builtin modules and search these first (or - optionally last). Add the lib prefix if needed to avoid having to - specify libbatchAnalysis instead of batchAnalysis. - - Define formally traceset/trace in the GUI for the user and decide how trace/traceset sharing goes in the application.