Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
detecting if TRACE_start was called too soon (before TRACE_global_init)
authorschnorr <schnorr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 5 Aug 2010 11:06:13 +0000 (11:06 +0000)
committerschnorr <schnorr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 5 Aug 2010 11:06:13 +0000 (11:06 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8111 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/instr/instr_config.c
src/instr/interface.c
src/instr/private.h

index 57a9ee9..a710162 100644 (file)
 #define OPT_TRACING_MSG_VOLUME    "tracing/msg/volume"
 #define OPT_TRACING_FILENAME      "tracing/filename"
 
 #define OPT_TRACING_MSG_VOLUME    "tracing/msg/volume"
 #define OPT_TRACING_FILENAME      "tracing/filename"
 
+static int trace_configured = 0;
+
+int _TRACE_configured (void)
+{
+  return trace_configured;
+}
+
 int _TRACE_smpi_enabled (void)
 {
   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
 int _TRACE_smpi_enabled (void)
 {
   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
@@ -89,6 +96,9 @@ void TRACE_global_init(int *argc, char **argv)
                    "Tracing of MSG communication volume (experimental).",
                    xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
                    NULL, NULL);
                    "Tracing of MSG communication volume (experimental).",
                    xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
                    NULL, NULL);
+
+  /* instrumentation can be considered configured now */
+  trace_configured = 1;
 }
 
 #endif
 }
 
 #endif
index 57157ce..5e2e219 100644 (file)
@@ -16,15 +16,25 @@ static xbt_dict_t created_categories;
 
 int TRACE_start ()
 {
 
 int TRACE_start ()
 {
-       FILE *file = NULL;
+  if (!_TRACE_configured()){
+    THROW0 (tracing_error, TRACE_ERROR_START,
+            "TRACE_start should be called after SimGrid initialization functions.");
+    return 0;
+  }
+
   if (IS_TRACING) { /* what? trace is already active... ignore.. */
   if (IS_TRACING) { /* what? trace is already active... ignore.. */
-       THROW0 (tracing_error, TRACE_ERROR_START,
-               "TRACE_start called, but tracing is already active");
+    THROW0 (tracing_error, TRACE_ERROR_START,
+                "TRACE_start called, but tracing is already active.");
     return 0;
   }
 
   char *filename = _TRACE_filename ();
     return 0;
   }
 
   char *filename = _TRACE_filename ();
-  file = fopen(filename, "w");
+  if (!filename){
+    THROW0 (tracing_error, TRACE_ERROR_START,
+            "Trace filename is not initialized.");
+    return 0;
+  }
+  FILE *file = fopen(filename, "w");
   if (!file) {
     THROW1 (tracing_error, TRACE_ERROR_START,
                "Tracefile %s could not be opened for writing.", filename);
   if (!file) {
     THROW1 (tracing_error, TRACE_ERROR_START,
                "Tracefile %s could not be opened for writing.", filename);
index 89b16ee..61c9d38 100644 (file)
@@ -130,6 +130,7 @@ int TRACE_surf_gtnets_get_dst (void *action);
 void TRACE_surf_gtnets_destroy (void *action);
 
 /* from instr_config.c */
 void TRACE_surf_gtnets_destroy (void *action);
 
 /* from instr_config.c */
+int _TRACE_configured (void);
 int _TRACE_smpi_enabled (void);
 int _TRACE_platform_enabled (void);
 int _TRACE_msg_task_enabled (void);
 int _TRACE_smpi_enabled (void);
 int _TRACE_platform_enabled (void);
 int _TRACE_msg_task_enabled (void);