Added options to run different tests in module batchtest
[lttv.git] / ltt / branches / poly / lttv / main / main.c
index 7b6f7153c39a6545c6226079ea07f616e82d0d12..fb9c7164e8578bceab33ab47b3925b49a414d7ab 100644 (file)
@@ -1,3 +1,21 @@
+/* This file is part of the Linux Trace Toolkit viewer
+ * Copyright (C) 2003-2004 Michel Dagenais
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
+ * MA 02111-1307, USA.
+ */
+
 
 #include <lttv/hook.h>
 #include <lttv/module.h>
@@ -8,6 +26,7 @@
 #include <lttv/traceset.h>
 #include <ltt/trace.h>
 #include <stdio.h>
+#include <mcheck.h>
 
 
 void lttv_option_init(int argc, char **argv);
@@ -42,6 +61,8 @@ static gboolean
   a_verbose,
   a_debug;
 
+gboolean lttv_profile_memory;
+
 static int a_argc;
 
 static char **a_argv;
@@ -56,21 +77,55 @@ 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
+
+  /* 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) {
+      mcheck(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));
 
@@ -79,6 +134,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;
@@ -102,9 +160,11 @@ int main(int argc, char **argv) {
   lttv_state_init(argc,argv);
   lttv_stats_init(argc,argv);
 
+
   /* Initialize the module loading */
 
-  lttv_module_path_add("/usr/lib/lttv/plugins");
+  lttv_module_path_add(PACKAGE_PLUGIN_DIR);
+
 
   /* Add some built-in options */
 
@@ -127,14 +187,33 @@ 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, &lttv_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);
 
+
+  /* Clean up everything */
+
   lttv_stats_destroy();
   lttv_state_destroy();
   lttv_module_destroy();
@@ -146,10 +225,10 @@ 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
+  }
 }
 
 
@@ -170,6 +249,7 @@ void lttv_module_path_option(void *hook_data)
   lttv_module_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);
This page took 0.025306 seconds and 4 git commands to generate.