Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refactor TRACE_start and TRACE_end
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 9 May 2018 11:58:14 +0000 (13:58 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 9 May 2018 11:59:25 +0000 (13:59 +0200)
src/instr/instr_config.cpp
src/instr/instr_paje_trace.cpp
src/instr/instr_platform.cpp
src/instr/instr_private.hpp

index 965994b..7ea943f 100644 (file)
@@ -7,12 +7,15 @@
 #include "simgrid/s4u/Engine.hpp"
 #include "src/instr/instr_private.hpp"
 #include "surf/surf.hpp"
+#include "xbt/virtu.h" /* sg_cmdline */
 #include <string>
 #include <vector>
 
 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
 
+extern FILE* tracing_file;
+
 #define OPT_TRACING_BASIC                "tracing/basic"
 #define OPT_TRACING_BUFFER               "tracing/buffer"
 #define OPT_TRACING_CATEGORIZED          "tracing/categorized"
@@ -89,19 +92,43 @@ static void TRACE_start()
 
     XBT_DEBUG("Tracing starts");
     /* init the tracing module to generate the right output */
-
-    /* open the trace file(s) */
     std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
     XBT_DEBUG("Tracing format %s", format.c_str());
+
+    /* open the trace file(s) */
+    std::string filename = TRACE_get_filename();
+    tracing_file         = fopen(filename.c_str(), "w");
+    if (tracing_file == nullptr) {
+      THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
+    }
+
+    XBT_DEBUG("Filename %s is open for writing", filename.c_str());
+
     if (format == "Paje") {
-      TRACE_paje_start();
-    } else if (format == "TI") {
-      simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
-      TRACE_TI_start();
-    }else{
-      xbt_die("Unknown trace format :%s ", format.c_str());
+      /* output generator version */
+      fprintf(tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n", SIMGRID_VERSION_MAJOR,
+              SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
+      fprintf(tracing_file, "#[");
+      unsigned int cpt;
+      char* str;
+      xbt_dynar_foreach (xbt_cmdline, cpt, str) {
+        fprintf(tracing_file, "%s ", str);
+      }
+      fprintf(tracing_file, "]\n");
     }
 
+    /* output one line comment */
+    dump_comment(TRACE_get_comment());
+
+    /* output comment file */
+    dump_comment_file(TRACE_get_comment_file());
+
+    if (format == "Paje") {
+      /* output Pajé header */
+      TRACE_header(TRACE_basic(), TRACE_display_sizes());
+    } else
+      simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
+
     trace_active = true;
     XBT_DEBUG("Tracing is on");
   }
@@ -122,15 +149,8 @@ static void TRACE_end()
   delete root_type;
 
   /* close the trace files */
-  std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
-  XBT_DEBUG("Tracing format %s\n", format.c_str());
-  if (format == "Paje") {
-    TRACE_paje_end();
-  } else if (format == "TI") {
-    TRACE_TI_end();
-  } else {
-    xbt_die("Unknown trace format :%s ", format.c_str());
-  }
+  fclose(tracing_file);
+  XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
 
   /* de-activate trace */
   trace_active = false;
index a811e79..4d55e55 100644 (file)
@@ -9,7 +9,6 @@
 #include "src/instr/instr_smpi.hpp"
 #include "src/smpi/include/private.hpp"
 #include "typeinfo"
-#include "xbt/virtu.h" /* sg_cmdline */
 #include <fstream>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
@@ -116,62 +115,3 @@ void simgrid::instr::PajeEvent::insertIntoBuffer()
 
   buffer_debug(&buffer);
 }
-
-void TRACE_paje_start() {
-  std::string filename = TRACE_get_filename();
-  tracing_file         = fopen(filename.c_str(), "w");
-  if (tracing_file == nullptr){
-    THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
-  }
-
-  XBT_DEBUG("Filename %s is open for writing", filename.c_str());
-
-  /* output generator version */
-  fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
-           SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
-  fprintf (tracing_file, "#[");
-  unsigned int cpt;
-  char *str;
-  xbt_dynar_foreach (xbt_cmdline, cpt, str){
-    fprintf(tracing_file, "%s ",str);
-  }
-  fprintf (tracing_file, "]\n");
-
-  /* output one line comment */
-  dump_comment (TRACE_get_comment());
-
-  /* output comment file */
-  dump_comment_file (TRACE_get_comment_file());
-
-  /* output header */
-  TRACE_header(TRACE_basic(),TRACE_display_sizes());
-}
-
-void TRACE_paje_end() {
-  fclose(tracing_file);
-  XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
-}
-
-
-void TRACE_TI_start()
-{
-  std::string filename = TRACE_get_filename();
-  tracing_file         = fopen(filename.c_str(), "w");
-  if (tracing_file == nullptr) {
-    THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
-  }
-
-  XBT_DEBUG("Filename %s is open for writing", filename.c_str());
-
-  /* output one line comment */
-  dump_comment(TRACE_get_comment());
-
-  /* output comment file */
-  dump_comment_file(TRACE_get_comment_file());
-}
-
-void TRACE_TI_end()
-{
-  fclose(tracing_file);
-  XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
-}
index 293ae81..26aed0e 100644 (file)
@@ -192,8 +192,7 @@ static void instr_link_on_creation(simgrid::s4u::Link& link)
   if (currentContainer.empty()) // No ongoing parsing. Are you creating the loopback?
     return;
 
-  container_t father    = currentContainer.back();
-  container_t container = new simgrid::instr::Container(link.get_name(), "LINK", father);
+  container_t container = new simgrid::instr::Container(link.get_name(), "LINK", currentContainer.back());
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_link())) {
     simgrid::instr::VariableType* bandwidth = container->type_->getOrCreateVariableType("bandwidth", "");
index ed3d1c5..ce0ed55 100644 (file)
@@ -210,10 +210,6 @@ extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
 /* instr_paje_header.c */
 XBT_PRIVATE void TRACE_header(bool basic, int size);
 
-/* from paje.c */
-XBT_PRIVATE void TRACE_paje_start();
-XBT_PRIVATE void TRACE_paje_end();
-
 /* from instr_config.c */
 XBT_PRIVATE bool TRACE_needs_platform();
 XBT_PRIVATE bool TRACE_is_enabled();
@@ -254,9 +250,6 @@ void instr_new_user_variable_type(std::string father_type, std::string new_typen
 void instr_new_user_state_type(std::string father_type, std::string new_typename);
 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
 
-/* instr_config.c */
-XBT_PRIVATE void TRACE_TI_start();
-XBT_PRIVATE void TRACE_TI_end();
 XBT_PRIVATE void TRACE_global_init();
 XBT_PRIVATE void TRACE_help(int detailed);