Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
registering the source and destination of all onelink routes
[simgrid.git] / src / instr / interface.c
index 57157ce..3f998aa 100644 (file)
@@ -4,11 +4,12 @@
 /* This program is free software; you can redistribute it and/or modify it
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "instr/private.h"
-
+#include "simgrid_config.h"
 
 #ifdef HAVE_TRACING
 
+#include "instr/private.h"
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface");
 
 static xbt_dict_t defined_types;
@@ -16,15 +17,25 @@ static xbt_dict_t created_categories;
 
 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.. */
-       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 ();
-  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);
@@ -42,6 +53,8 @@ int TRACE_start ()
     pajeDefineVariableType ("power", "HOST", "power");
     pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
     pajeDefineVariableType ("latency", "LINK", "latency");
+    pajeDefineEventType ("source", "LINK", "source");
+    pajeDefineEventType ("destination", "LINK", "destination");
   }
 
   if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
@@ -65,6 +78,12 @@ int TRACE_start ()
     pajeDefineStateType("presence", "TASK", "presence");
   }
 
+  if (IS_TRACING_SMPI){
+    pajeDefineContainerType ("MPI_PROCESS", "HOST", "MPI_PROCESS");
+    pajeDefineStateType ("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
+    pajeDefineLinkType ("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS", "MPI_LINK");
+  }
+
   /* creating the platform */
   pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
 
@@ -72,8 +91,10 @@ int TRACE_start ()
   defined_types = xbt_dict_new();
   created_categories = xbt_dict_new();
   __TRACE_msg_init();
-  __TRACE_surf_init();
+  __TRACE_category_init ();
+  TRACE_surf_init();
   __TRACE_msg_process_init ();
+  __TRACE_smpi_init ();
 
   return 0;
 }
@@ -177,4 +198,18 @@ void TRACE_mark (const char *mark_type, const char *mark_value)
   pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value);
 }
 
+int TRACE_smpi_set_category (const char *category)
+{
+  //if category is NULL, trace of platform is disabled
+  if (!IS_TRACING) return 1;
+  if (category != NULL){
+    int ret = TRACE_category (category);
+    __TRACE_category_set (SIMIX_process_self(), category);
+    return ret;
+  }else{
+    __TRACE_category_unset (SIMIX_process_self());
+    return 0;
+  }
+}
+
 #endif /* HAVE_TRACING */