Add state saving functions and update processTrace accordingly.
[lttv.git] / ltt / branches / poly / lttv / main.c
index 2ec66f74dd1e2ab059fb43ead5b0346a41bd7aed..7b6f7153c39a6545c6226079ea07f616e82d0d12 100644 (file)
@@ -1,53 +1,67 @@
 
-#include "lttv.h"
-#include "trace.h"
-#include "attribute.h"
-#include "hook.h"
-#include "option.h"
-#include "module.h"
+#include <lttv/hook.h>
+#include <lttv/module.h>
+#include <lttv/lttv.h>
+#include <lttv/iattribute.h>
+#include <lttv/attribute.h>
+#include <lttv/option.h>
+#include <lttv/traceset.h>
+#include <ltt/trace.h>
+#include <stdio.h>
+
+
+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 */
 
-/* Extensible array of popt command line options. Modules add options as
-   they are loaded and initialized. */
+static LttvIAttribute *attributes;
 
+static LttvHooks
+  *before_options,
+  *after_options,
+  *before_main,
+  *after_main;
 
-static lttv_attributes *attributes_global;
+static char 
+  *a_module,
+  *a_module_path;
 
-static lttv_hooks
-  *hooks_init_after,
-  *hooks_program_before,
-  *hooks_program_main,
-  *hooks_program_after;
+static gboolean
+  a_verbose,
+  a_debug;
 
-// trace sets has to be put one in each new window_traceset
-static lttv_trace_set *traces;
+static int a_argc;
 
-static char *aModule, *aPath, *aTrace;
-
-static int aArgc;
-
-static char **aArgv;
+static char **a_argv;
 
 static void lttv_module_option(void *hook_data);
 
 static void lttv_module_path_option(void *hook_data);
 
-static void lttv_trace_option(void *hook_data);
+static void lttv_verbose(void *hook_data);
 
-#ifdef MEMDEBUG
-extern struct GMemVTable *glib_mem_profiler_table;
-#endif
+static void lttv_debug(void *hook_data);
+
+static void lttv_help(void *hook_data);
 
 /* Since everything is done in modules, the main program only takes care
    of the infrastructure. */
 
 int main(int argc, char **argv) {
 
-  aArgc = argc;
-  aArgv = argv;
+  LttvAttributeValue value;
 
 #ifdef MEMDEBUG
   g_mem_set_vtable(glib_mem_profiler_table);
@@ -55,35 +69,38 @@ int main(int argc, char **argv) {
   g_mem_profile();
 #endif
 
-  attributes_global = lttv_attributes_new();
+  g_type_init();
+  //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS);
 
-//  traces = lttv_trace_set_new();
-//  lttv_attributes_set_pointer_pathname(attributes_global, "trace_set/default", traces);
+  attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
 
-  /* Initialize the hooks */
+  before_options = lttv_hooks_new();
+  after_options = lttv_hooks_new();
+  before_main = lttv_hooks_new();
+  after_main = lttv_hooks_new();
 
-  hooks_init_after = lttv_hooks_new();
-  lttv_attributes_set_pointer_pathname(attributes_global, "hooks/init/after", 
-      hooks_init_after);
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_options;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_options;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_main;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_main;
 
 
-  hooks_program_before = lttv_hooks_new();
-  lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/before", 
-      hooks_program_before);
-
-  hooks_program_main = lttv_hooks_new();
-  lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/main", 
-      hooks_program_main);
-
-  hooks_program_after = lttv_hooks_new();
-  lttv_attributes_set_pointer_pathname(attributes_global, "hooks/program/after", 
-      hooks_program_after);
-
   /* Initialize the command line options processing */
 
+  a_argc = argc;
+  a_argv = argv;
   lttv_option_init(argc,argv);
   lttv_module_init(argc,argv);
-  // FIXME lttv_analyse_init(argc,argv);
+  lttv_state_init(argc,argv);
+  lttv_stats_init(argc,argv);
 
   /* Initialize the module loading */
 
@@ -92,56 +109,113 @@ int main(int argc, char **argv) {
   /* Add some built-in options */
 
   lttv_option_add("module",'m', "load a module", "name of module to load", 
-      LTTV_OPT_STRING, &aModule, lttv_module_option, NULL);
+      LTTV_OPT_STRING, &a_module, lttv_module_option, NULL);
  
   lttv_option_add("modules-path", 'L', 
       "add a directory to the module search path", 
-      "directory to add to the path", LTTV_OPT_STRING, &aPath, 
+      "directory to add to the path", LTTV_OPT_STRING, &a_module_path, 
       lttv_module_path_option, NULL);
+       
+  lttv_option_add("help",'h', "basic help", "none", 
+      LTTV_OPT_NONE, NULL, lttv_help, NULL);
 
-  lttv_option_add("trace", 't', 
-      "add a trace to the trace set to analyse", 
-      "pathname of the directory containing the trace", 
-      LTTV_OPT_STRING, &aTrace, lttv_trace_option, NULL);
-
-  lttv_hooks_call(hooks_init_after, NULL);
+  a_verbose = FALSE; 
+  lttv_option_add("verbose",'v', "print information messages", "none", 
+      LTTV_OPT_NONE, NULL, lttv_verbose, NULL);
+  a_debug = FALSE;
+  lttv_option_add("debug",'d', "print debugging messages", "none", 
+      LTTV_OPT_NONE, NULL, lttv_debug, NULL);
+  lttv_hooks_call(before_options, NULL);
+  lttv_option_parse(argc, argv);
+  lttv_hooks_call(after_options, NULL);
 
-  lttv_hooks_call(hooks_program_before, NULL);
-  lttv_hooks_call(hooks_program_main, NULL);
-  lttv_hooks_call(hooks_program_after, NULL);
+  lttv_hooks_call(before_main, NULL);
+  lttv_hooks_call(after_main, NULL);
 
-  /* Finalize the command line options processing */
+  lttv_stats_destroy();
+  lttv_state_destroy();
   lttv_module_destroy();
   lttv_option_destroy();
-  // FIXME lttv_analyse_destroy();
-  lttv_attributes_destroy(attributes_global);
+
+  lttv_hooks_destroy(before_options);
+  lttv_hooks_destroy(after_options);
+  lttv_hooks_destroy(before_main);
+  lttv_hooks_destroy(after_main);
+  g_object_unref(attributes);
 
 #ifdef MEMDEBUG
     g_message("Memory summary after main");
     g_mem_profile();
 #endif
+}
+
 
-  
+LttvAttribute *lttv_global_attributes()
+{
+  return (LttvAttribute*)attributes;
 }
 
+
 void lttv_module_option(void *hook_data)
 { 
-  lttv_module_load(aModule,aArgc,aArgv,STANDALONE);
+  lttv_module_load(a_module,a_argc,a_argv);
 }
 
 
 void lttv_module_path_option(void *hook_data)
 {
-  lttv_module_path_add(aPath);
+  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);
+  g_info("Logging set to include INFO level messages");
+}
 
-void lttv_trace_option(void *hook_data)
-{ 
-//  lttv_trace *trace;
+void lttv_debug(void *hook_data)
+{
+  g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, g_log_default_handler, NULL);
+  g_info("Logging set to include DEBUG level messages");
+}
 
-//  trace = lttv_trace_open(aTrace);
-//  if(trace == NULL) g_critical("cannot open trace %s", aTrace);
-//  lttv_trace_set_add(traces, trace);
+void lttv_help(void *hook_data)
+{
+       printf("Linux Trace Toolkit Visualizer\n");
+       printf("\n");
+       lttv_option_show_help();
+       printf("\n");
 }
 
+/* 
+
+- 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.
+
+- Use appropriately the new functions in time.h
+
+- remove the separate tracefiles (control/per cpu) arrays/loops in context.
+
+- split processTrace into context.c and processTrace.c
+
+- check spelling conventions.
+
+- get all the copyright notices.
+
+- remove all the warnings.
+
+- get all the .h files properly doxygen commented to produce useful documents.
+
+- have an intro/architecture document.
+
+- write a tutorial */
This page took 0.024995 seconds and 4 git commands to generate.