From: Frederic Suter Date: Wed, 9 May 2018 11:58:14 +0000 (+0200) Subject: refactor TRACE_start and TRACE_end X-Git-Tag: v3.20~264 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/eb543cc29c42f9144694e275b520dc4bdb1c0c9c refactor TRACE_start and TRACE_end --- diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 965994ba87..7ea943f98a 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -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 #include 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(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(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; diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index a811e79cf6..4d55e557b0 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -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 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()); -} diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 293ae81ef5..26aed0e47c 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -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", ""); diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index ed3d1c524d..ce0ed557db 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -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);