Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to exit in a more valgrind friendly manner when help is requested.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 1 Oct 2013 13:15:24 +0000 (15:15 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 1 Oct 2013 14:24:27 +0000 (16:24 +0200)
src/include/simgrid/sg_config.h
src/instr/instr_config.c
src/simdag/sd_global.c
src/simgrid/sg_config.c
src/simix/smx_global.c

index d0e93c4..e4142a9 100644 (file)
@@ -11,6 +11,7 @@
 /*******************************************/
 XBT_PUBLIC_DATA(xbt_cfg_t) _sg_cfg_set;
 XBT_PUBLIC_DATA(int) _sg_cfg_init_status;
+XBT_PUBLIC_DATA(int) _sg_cfg_exit_asap;
 XBT_PUBLIC(int) sg_cfg_get_int(const char* name);
 XBT_PUBLIC(double) sg_cfg_get_double(const char* name);
 XBT_PUBLIC(char*) sg_cfg_get_string(const char* name);
index 3339f1a..3ef4c71 100644 (file)
@@ -181,6 +181,7 @@ int TRACE_end()
     XBT_DEBUG("Tracing is off");
     XBT_DEBUG("Tracing system is shutdown");
   }
+  xbt_dynar_free(&TRACE_start_functions); /* useful when exiting early */
   xbt_dynar_free(&TRACE_end_functions);
   return retval;
 }
index 21b640d..54feb2d 100644 (file)
@@ -96,6 +96,11 @@ void SD_init(int *argc, char **argv)
   SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy);
   SD_LINK_LEVEL = xbt_lib_add_level(link_lib,__SD_link_destroy);
   SD_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,__SD_storage_destroy);
+
+  if (_sg_cfg_exit_asap) {
+    SD_exit();
+    exit(0);
+  }
 }
 
 /** \brief set a configuration variable
index 34e5b43..5365b64 100644 (file)
@@ -35,6 +35,12 @@ xbt_cfg_t _sg_cfg_set = NULL;
  */
 int _sg_cfg_init_status = 0;
 
+/* instruct the upper layer (simix or simdag) to exit as soon as possible
+ */
+int _sg_cfg_exit_asap = 0;
+
+#define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0)
+
 /* Parse the command line, looking for options */
 static void sg_config_cmd_line(int *argc, char **argv)
 {
@@ -96,10 +102,8 @@ static void sg_config_cmd_line(int *argc, char **argv)
     argv[j] = NULL;
     *argc = j;
   }
-  if (shall_exit) {
-    _sg_cfg_init_status = 1;        // get everything cleanly cleaned on exit
-    exit(0);
-  }
+  if (shall_exit)
+    sg_cfg_exit_early();
 }
 
 /* callback of the workstation/model variable */
@@ -114,7 +118,7 @@ static void _sg_cfg_cb__workstation_model(const char *name, int pos)
 
   if (!strcmp(val, "help")) {
     model_help("workstation", surf_workstation_model_description);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* Make sure that the model exists */
@@ -133,7 +137,7 @@ static void _sg_cfg_cb__cpu_model(const char *name, int pos)
 
   if (!strcmp(val, "help")) {
     model_help("CPU", surf_cpu_model_description);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* New Module missing */
@@ -152,7 +156,7 @@ static void _sg_cfg_cb__optimization_mode(const char *name, int pos)
 
   if (!strcmp(val, "help")) {
     model_help("optimization", surf_optimization_mode_description);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* New Module missing */
@@ -171,7 +175,7 @@ static void _sg_cfg_cb__storage_mode(const char *name, int pos)
 
   if (!strcmp(val, "help")) {
     model_help("storage", surf_storage_model_description);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* New Module missing */
@@ -190,7 +194,7 @@ static void _sg_cfg_cb__network_model(const char *name, int pos)
 
   if (!strcmp(val, "help")) {
     model_help("network", surf_network_model_description);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* New Module missing */
@@ -243,7 +247,7 @@ static void _sg_cfg_cb__coll(const char *category,
 
   if (!strcmp(val, "help")) {
     coll_help(category, table);
-    exit(0);
+    sg_cfg_exit_early();
   }
 
   /* New Module missing */
index 8915337..bfed0ba 100644 (file)
@@ -110,7 +110,11 @@ void SIMIX_global_init(int *argc, char **argv)
 
   SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
 
-  if(sg_cfg_get_boolean("clean_atexit")) atexit(SIMIX_clean);
+  if (sg_cfg_get_boolean("clean_atexit"))
+    atexit(SIMIX_clean);
+
+  if (_sg_cfg_exit_asap)
+    exit(0);
 }
 
 /**
@@ -121,6 +125,9 @@ void SIMIX_global_init(int *argc, char **argv)
  */
 static void SIMIX_clean(void)
 {
+#ifdef HAVE_TRACING
+  TRACE_end();
+#endif
 #ifdef TIME_BENCH_PER_SR
   smx_ctx_raw_new_sr();
 #endif