From: Frederic Suter Date: Sun, 5 Apr 2020 16:15:44 +0000 (+0200) Subject: still fighting against this code X-Git-Tag: v3.26~658 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4929b7f325bed62b338613c63af15c75a185effe?ds=sidebyside;hp=8fb62dc5a69cd10bc48dae3c6e7ecf54b11ba378 still fighting against this code --- diff --git a/MANIFEST.in b/MANIFEST.in index 04946c2d24..49d39f9210 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2149,7 +2149,6 @@ include src/instr/instr_paje_header.cpp include src/instr/instr_paje_trace.cpp include src/instr/instr_paje_types.cpp include src/instr/instr_paje_types.hpp -include src/instr/instr_paje_values.cpp include src/instr/instr_paje_values.hpp include src/instr/instr_platform.cpp include src/instr/instr_private.hpp diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index c3abe0e370..f80a3795cc 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -9,7 +9,6 @@ #include "simgrid/version.h" #include "src/instr/instr_private.hpp" #include "surf/surf.hpp" -#include "xbt/virtu.h" /* xbt::cmdline */ #include #ifdef WIN32 @@ -88,8 +87,6 @@ static simgrid::config::Flag trace_disable_link{"tracing/disable_link", "Do not trace link bandwidth and latency.", false}; static simgrid::config::Flag trace_disable_power{"tracing/disable_power", "Do not trace host power.", false}; -simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje; - bool TRACE_needs_platform () { return TRACE_actor_is_enabled() || TRACE_vm_is_enabled() || TRACE_categorized() || TRACE_uncategorized() || @@ -166,26 +163,11 @@ bool TRACE_disable_speed() return trace_disable_power && trace_enabled; } -bool TRACE_basic () -{ - return trace_basic && trace_enabled; -} - bool TRACE_display_sizes () { return trace_display_sizes && trace_smpi_enabled && trace_enabled; } -int TRACE_precision () -{ - return simgrid::config::get_value("tracing/precision"); -} - -std::string TRACE_get_filename() -{ - return simgrid::config::get_value("tracing/filename"); -} - static void print_line(const char* option, const char* desc, const char* longdesc) { std::string str = std::string("--cfg=") + option + " "; @@ -227,8 +209,10 @@ void TRACE_help() namespace simgrid { namespace instr { - static bool trace_active = false; +TraceFormat trace_format = TraceFormat::Paje; +int trace_precision; + /************* * Callbacks * *************/ @@ -245,7 +229,7 @@ static void on_container_creation_paje(Container& c) XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, PAJE_CreateContainer, timestamp); - stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_CreateContainer << " "; + stream << std::fixed << std::setprecision(trace_precision) << PAJE_CreateContainer << " "; stream << timestamp << " " << c.get_id() << " " << c.type_->get_id() << " " << c.father_->get_id() << " \""; if (c.get_name().find("rank-") != 0) stream << c.get_name() << "\""; @@ -260,8 +244,8 @@ static void on_container_creation_paje(Container& c) static void on_container_destruction_paje(Container& c) { // obligation to dump previous events because they might reference the container that is about to be destroyed - TRACE_last_timestamp_to_dump = SIMIX_get_clock(); - TRACE_paje_dump_buffer(true); + last_timestamp_to_dump = SIMIX_get_clock(); + dump_buffer(true); // trace my destruction, but not if user requests so or if the container is root if (not trace_disable_destroy && &c != Container::get_root()) { @@ -270,7 +254,7 @@ static void on_container_destruction_paje(Container& c) XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, PAJE_DestroyContainer, timestamp); - stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_DestroyContainer << " "; + stream << std::fixed << std::setprecision(trace_precision) << PAJE_DestroyContainer << " "; stream << timestamp << " " << c.type_->get_id() << " " << c.get_id(); XBT_DEBUG("Dump %s", stream.str().c_str()); tracing_file << stream.str() << std::endl; @@ -306,8 +290,8 @@ static void on_container_creation_ti(Container& c) static void on_container_destruction_ti(Container& c) { // obligation to dump previous events because they might reference the container that is about to be destroyed - TRACE_last_timestamp_to_dump = SIMIX_get_clock(); - TRACE_paje_dump_buffer(true); + last_timestamp_to_dump = SIMIX_get_clock(); + dump_buffer(true); if (not trace_disable_destroy && &c != Container::get_root()) { XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, PAJE_DestroyContainer, SIMIX_get_clock()); @@ -323,7 +307,7 @@ static void on_entity_value_creation(EntityValue& value) { std::stringstream stream; XBT_DEBUG("%s: event_type=%u", __func__, PAJE_DefineEntityValue); - stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_DefineEntityValue; + stream << std::fixed << std::setprecision(trace_precision) << PAJE_DefineEntityValue; stream << " " << value.get_id() << " " << value.get_father()->get_id() << " " << value.get_name(); if (not value.get_color().empty()) stream << " \"" << value.get_color() << "\""; @@ -337,8 +321,8 @@ static void on_type_creation(Type& type, e_event_type event_type) return; // this kind of type has to be handled differently std::stringstream stream; - stream << std::fixed << std::setprecision(TRACE_precision()); - XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, event_type, TRACE_precision(), 0.); + stream << std::fixed << std::setprecision(trace_precision); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, event_type, trace_precision, 0.); stream << event_type << " " << type.get_id() << " " << type.get_father()->get_id() << " " << type.get_name(); if (type.is_colored()) stream << " \"" << type.get_color() << "\""; @@ -349,61 +333,45 @@ static void on_type_creation(Type& type, e_event_type event_type) static void on_link_type_creation(Type& type, Type& source, Type& dest) { std::stringstream stream; - XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, PAJE_DefineLinkType, TRACE_precision(), 0.); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, PAJE_DefineLinkType, trace_precision, 0.); stream << PAJE_DefineLinkType << " " << type.get_id() << " " << type.get_father()->get_id(); stream << " " << source.get_id() << " " << dest.get_id() << " " << type.get_name(); XBT_DEBUG("Dump %s", stream.str().c_str()); tracing_file << stream.str() << std::endl; } + static void on_simulation_start() { - if (trace_active) + if (trace_active || not TRACE_is_enabled()) return; - // tracing system must be: - // - enabled (with --cfg=tracing:yes) - // - already configured (simgrid::instr::init already called) - if (TRACE_is_enabled()) { - define_callbacks(); - - XBT_DEBUG("Tracing starts"); - - /* init the tracing module to generate the right output */ - std::string format = config::get_value("tracing/smpi/format"); - XBT_DEBUG("Tracing format %s", format.c_str()); - - /* Connect the callbacks associated to the creation/destruction of containers*/ - if (format == "Paje") { - Container::on_creation.connect(on_container_creation_paje); - Container::on_destruction.connect(on_container_destruction_paje); - EntityValue::on_creation.connect(on_entity_value_creation); - Type::on_creation.connect(on_type_creation); - LinkType::on_creation.connect(on_link_type_creation); - } else { - Container::on_creation.connect(on_container_creation_ti); - Container::on_destruction.connect(on_container_destruction_ti); - } + define_callbacks(); - /* open the trace file(s) */ - std::string filename = TRACE_get_filename(); - tracing_file.open(filename.c_str(), std::ofstream::out); - if (tracing_file.fail()) { - throw TracingError(XBT_THROW_POINT, - xbt::string_printf("Tracefile %s could not be opened for writing.", filename.c_str())); - } + XBT_DEBUG("Tracing starts"); + trace_precision = config::get_value("tracing/precision"); - XBT_DEBUG("Filename %s is open for writing", filename.c_str()); - - if (format == "Paje") { - /* output generator version */ - tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR - << "." << SIMGRID_VERSION_PATCH << std::endl; - tracing_file << "#["; - for (auto str : simgrid::xbt::cmdline) { - tracing_file << str << " "; - } - tracing_file << "]" << std::endl; - } + /* init the tracing module to generate the right output */ + std::string format = config::get_value("tracing/smpi/format"); + XBT_DEBUG("Tracing format %s", format.c_str()); + + /* open the trace file(s) */ + std::string filename = simgrid::config::get_value("tracing/filename"); + tracing_file.open(filename.c_str(), std::ofstream::out); + if (tracing_file.fail()) { + throw TracingError(XBT_THROW_POINT, + xbt::string_printf("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") { + Container::on_creation.connect(on_container_creation_paje); + Container::on_destruction.connect(on_container_destruction_paje); + EntityValue::on_creation.connect(on_entity_value_creation); + Type::on_creation.connect(on_type_creation); + LinkType::on_creation.connect(on_link_type_creation); + + paje::dump_generator_version(); /* output one line comment */ std::string comment = simgrid::config::get_value("tracing/comment"); @@ -411,17 +379,16 @@ static void on_simulation_start() tracing_file << "# " << comment << std::endl; /* output comment file */ - dump_comment_file(simgrid::config::get_value(OPT_TRACING_COMMENT_FILE)); - - if (format == "Paje") { - /* output Pajé header */ - TRACE_header(TRACE_basic(), TRACE_display_sizes()); - } else - trace_format = TraceFormat::Ti; - - trace_active = true; - XBT_DEBUG("Tracing is on"); + paje::dump_comment_file(config::get_value(OPT_TRACING_COMMENT_FILE)); + paje::dump_header(trace_basic, TRACE_display_sizes()); + } else { + trace_format = TraceFormat::Ti; + Container::on_creation.connect(on_container_creation_ti); + Container::on_destruction.connect(on_container_destruction_ti); } + + trace_active = true; + XBT_DEBUG("Tracing is on"); } static void on_simulation_end() @@ -430,8 +397,8 @@ static void on_simulation_end() return; /* dump trace buffer */ - TRACE_last_timestamp_to_dump = surf_get_clock(); - TRACE_paje_dump_buffer(true); + last_timestamp_to_dump = surf_get_clock(); + dump_buffer(true); const Type* root_type = Container::get_root()->type_; /* destroy all data structures of tracing (and free) */ @@ -440,7 +407,7 @@ static void on_simulation_end() /* close the trace files */ tracing_file.close(); - XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str()); + XBT_DEBUG("Filename %s is closed", config::get_value("tracing/filename").c_str()); /* de-activate trace */ trace_active = false; @@ -476,8 +443,9 @@ void init() "(expressed in number of digits after decimal point)", 6); - /* Connect callbacks */ + /* Connect Engine callbacks */ s4u::Engine::on_platform_creation.connect(on_simulation_start); + s4u::Engine::on_time_advance.connect([](double /*time_delta*/) { dump_buffer(false); }); s4u::Engine::on_deadlock.connect(on_simulation_end); s4u::Engine::on_simulation_end.connect(on_simulation_end); } diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 0680d8c9d3..9e5169fafd 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -13,15 +13,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing eve static container_t rootContainer = nullptr; /* the root container */ static std::map allContainers; /* all created containers indexed by name */ -long long int instr_new_paje_id () +namespace simgrid { +namespace instr { + +long long int new_paje_id() { static long long int type_id = 0; return type_id++; } -namespace simgrid { -namespace instr { - Container* Container::get_root() { return rootContainer; @@ -136,5 +136,13 @@ VariableType* Container::get_variable(const std::string& name) { return static_cast(type_->by_name(name)->set_calling_container(this)); } + +EntityValue::EntityValue(const std::string& name, const std::string& color, Type* father) + : name_(name), color_(color), father_(father) +{ + id_ = simgrid::instr::new_paje_id(); + on_creation(*this); +} + } // namespace instr } // namespace simgrid diff --git a/src/instr/instr_paje_containers.hpp b/src/instr/instr_paje_containers.hpp index 71cfda3da3..ec2930d622 100644 --- a/src/instr/instr_paje_containers.hpp +++ b/src/instr/instr_paje_containers.hpp @@ -59,7 +59,7 @@ public: class HostContainer : public Container { public: - HostContainer(simgrid::s4u::Host const& host, NetZoneContainer* father); + HostContainer(s4u::Host const& host, NetZoneContainer* father); }; } // namespace instr } // namespace simgrid diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index bdb2146de2..5161881910 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -18,9 +18,9 @@ namespace instr { PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType) : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType) { - XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, trace_precision, timestamp_); if (trace_format == TraceFormat::Paje) { - stream_ << std::fixed << std::setprecision(TRACE_precision()); + stream_ << std::fixed << std::setprecision(trace_precision); stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id(); } insert_into_buffer(); diff --git a/src/instr/instr_paje_header.cpp b/src/instr/instr_paje_header.cpp index cfd8a036df..594462811f 100644 --- a/src/instr/instr_paje_header.cpp +++ b/src/instr/instr_paje_header.cpp @@ -4,86 +4,94 @@ /* 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 "simgrid/sg_config.hpp" +#include "simgrid/Exception.hpp" #include "src/instr/instr_private.hpp" +#include "xbt/virtu.h" /* xbt::cmdline */ extern std::ofstream tracing_file; +namespace simgrid { +namespace instr { +namespace paje { -static void TRACE_header_PajeTypes(bool basic) +void dump_generator_version() { - tracing_file << "%EventDef PajeDefineContainerType " << simgrid::instr::PAJE_DefineContainerType << std::endl; + tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR + << "." << SIMGRID_VERSION_PATCH << std::endl; + tracing_file << "#["; + for (auto str : simgrid::xbt::cmdline) { + tracing_file << str << " "; + } + tracing_file << "]" << std::endl; +} + +void dump_comment_file(const std::string& filename) +{ + if (filename.empty()) + return; + std::ifstream fs(filename.c_str(), std::ifstream::in); + + if (fs.fail()) + throw TracingError(XBT_THROW_POINT, + xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str())); + + while (not fs.eof()) { + std::string line; + std::getline(fs, line); + tracing_file << "# " << line; + } + fs.close(); +} + +void dump_header(bool basic, bool display_sizes) +{ + // Types + tracing_file << "%EventDef PajeDefineContainerType " << PAJE_DefineContainerType << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ + if (basic) tracing_file << "% ContainerType string" << std::endl; - }else{ + else tracing_file << "% Type string" << std::endl; - } + tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeDefineVariableType " << simgrid::instr::PAJE_DefineVariableType << std::endl; + tracing_file << "%EventDef PajeDefineVariableType " << PAJE_DefineVariableType << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ - tracing_file << "% ContainerType string" << std::endl; - }else{ - tracing_file << "% Type string" << std::endl; - } + tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "% Color color" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeDefineStateType " << simgrid::instr::PAJE_DefineStateType << std::endl; + tracing_file << "%EventDef PajeDefineStateType " << PAJE_DefineStateType << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ - tracing_file << "% ContainerType string" << std::endl; - }else{ - tracing_file << "% Type string" << std::endl; - } + tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeDefineEventType " << simgrid::instr::PAJE_DefineEventType << std::endl; + tracing_file << "%EventDef PajeDefineEventType " << PAJE_DefineEventType << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ - tracing_file << "% ContainerType string" << std::endl; - }else{ - tracing_file << "% Type string" << std::endl; - } + tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeDefineLinkType " << simgrid::instr::PAJE_DefineLinkType << std::endl; + tracing_file << "%EventDef PajeDefineLinkType " << PAJE_DefineLinkType << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ - tracing_file << "% ContainerType string" << std::endl; - tracing_file << "% SourceContainerType string" << std::endl; - tracing_file << "% DestContainerType string" << std::endl; - }else{ - tracing_file << "% Type string" << std::endl; - tracing_file << "% StartContainerType string" << std::endl; - tracing_file << "% EndContainerType string" << std::endl; - } + tracing_file << "% " << (basic ? "Container" : "") << "Type string" << std::endl; + tracing_file << "% " << (basic ? "Source" : "Start") << "ContainerType string" << std::endl; + tracing_file << "% " << (basic ? "Dest" : "End") << "ContainerType string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; -} -static void TRACE_header_PajeDefineEntityValue(bool basic) -{ - tracing_file << "%EventDef PajeDefineEntityValue " << simgrid::instr::PAJE_DefineEntityValue << std::endl; + // EntityValue + tracing_file << "%EventDef PajeDefineEntityValue " << PAJE_DefineEntityValue << std::endl; tracing_file << "% Alias string" << std::endl; - if (basic){ - tracing_file << "% EntityType string" << std::endl; - }else{ - tracing_file << "% Type string" << std::endl; - } + tracing_file << "% " << (basic ? "Entity" : "") << "Type string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "% Color color" << std::endl; tracing_file << "%EndEventDef" << std::endl; -} -static void TRACE_header_PajeContainer() -{ - tracing_file << "%EventDef PajeCreateContainer " << simgrid::instr::PAJE_CreateContainer << std::endl; + // Container + tracing_file << "%EventDef PajeCreateContainer " << PAJE_CreateContainer << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Alias string" << std::endl; tracing_file << "% Type string" << std::endl; @@ -91,52 +99,48 @@ static void TRACE_header_PajeContainer() tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeDestroyContainer " << simgrid::instr::PAJE_DestroyContainer << std::endl; + tracing_file << "%EventDef PajeDestroyContainer " << PAJE_DestroyContainer << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Name string" << std::endl; tracing_file << "%EndEventDef" << std::endl; -} -static void TRACE_header_PajeVariable() -{ - tracing_file << "%EventDef PajeSetVariable " << simgrid::instr::PAJE_SetVariable << std::endl; + // Variable + tracing_file << "%EventDef PajeSetVariable " << PAJE_SetVariable << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value double" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeAddVariable " << simgrid::instr::PAJE_AddVariable << std::endl; + tracing_file << "%EventDef PajeAddVariable " << PAJE_AddVariable << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value double" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeSubVariable " << simgrid::instr::PAJE_SubVariable << std::endl; + tracing_file << "%EventDef PajeSubVariable " << PAJE_SubVariable << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value double" << std::endl; tracing_file << "%EndEventDef" << std::endl; -} -static void TRACE_header_PajeState(bool basic, int size) -{ - tracing_file << "%EventDef PajeSetState " << simgrid::instr::PAJE_SetState << std::endl; + // State + tracing_file << "%EventDef PajeSetState " << PAJE_SetState << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajePushState " << simgrid::instr::PAJE_PushState << std::endl; + tracing_file << "%EventDef PajePushState " << PAJE_PushState << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value string" << std::endl; - if (size) + if (display_sizes) tracing_file << "% Size int" << std::endl; #if HAVE_SMPI if (simgrid::config::get_value("smpi/trace-call-location")) { @@ -147,70 +151,49 @@ static void TRACE_header_PajeState(bool basic, int size) #endif tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajePopState " << simgrid::instr::PAJE_PopState << std::endl; + tracing_file << "%EventDef PajePopState " << PAJE_PopState << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "%EndEventDef" << std::endl; - if (basic) - return; - - tracing_file << "%EventDef PajeResetState " << simgrid::instr::PAJE_ResetState << std::endl; - tracing_file << "% Time date" << std::endl; - tracing_file << "% Type string" << std::endl; - tracing_file << "% Container string" << std::endl; - tracing_file << "%EndEventDef" << std::endl; -} + if (not basic) { + tracing_file << "%EventDef PajeResetState " << PAJE_ResetState << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; + } -static void TRACE_header_PajeLink(bool basic, bool size) -{ - tracing_file << "%EventDef PajeStartLink " << simgrid::instr::PAJE_StartLink << std::endl; + // Link + tracing_file << "%EventDef PajeStartLink " << PAJE_StartLink << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value string" << std::endl; - if (basic){ - tracing_file << "% SourceContainer string" << std::endl; - } else { - tracing_file << "% StartContainer string" << std::endl; - } + tracing_file << "% " << (basic ? "Source" : "Start") << "Container string" << std::endl; tracing_file << "% Key string" << std::endl; - if (size) + if (display_sizes) tracing_file << "% Size int" << std::endl; tracing_file << "%EndEventDef" << std::endl; - tracing_file << "%EventDef PajeEndLink " << simgrid::instr::PAJE_EndLink << std::endl; + tracing_file << "%EventDef PajeEndLink " << PAJE_EndLink << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value string" << std::endl; - if (basic){ - tracing_file << "% DestContainer string" << std::endl; - }else{ - tracing_file << "% EndContainer string" << std::endl; - } + tracing_file << "% " << (basic ? "Dest" : "End") << "Container string" << std::endl; tracing_file << "% Key string" << std::endl; tracing_file << "%EndEventDef" << std::endl; -} -static void TRACE_header_PajeNewEvent() -{ - tracing_file << "%EventDef PajeNewEvent " << simgrid::instr::PAJE_NewEvent << std::endl; + // Event + tracing_file << "%EventDef PajeNewEvent " << PAJE_NewEvent << std::endl; tracing_file << "% Time date" << std::endl; tracing_file << "% Type string" << std::endl; tracing_file << "% Container string" << std::endl; tracing_file << "% Value string" << std::endl; tracing_file << "%EndEventDef" << std::endl; } - -void TRACE_header(bool basic, bool size) -{ - TRACE_header_PajeTypes(basic); - TRACE_header_PajeDefineEntityValue(basic); - TRACE_header_PajeContainer(); - TRACE_header_PajeVariable(); - TRACE_header_PajeState(basic, size); - TRACE_header_PajeLink(basic, size); - TRACE_header_PajeNewEvent(); -} +} // namespace paje +} // namespace instr +} // namespace simgrid diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index 510c59ed80..45113de4b3 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -14,36 +14,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system"); -extern std::ofstream tracing_file; +namespace simgrid { +namespace instr { +static std::vector buffer; -static std::vector buffer; - -void dump_comment_file(const std::string& filename) -{ - if (filename.empty()) - return; - std::ifstream fs(filename.c_str(), std::ifstream::in); - - if (fs.fail()) - throw simgrid::TracingError( - XBT_THROW_POINT, - simgrid::xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str())); - - while (not fs.eof()) { - std::string line; - std::getline(fs, line); - tracing_file << "# " << line; - } - fs.close(); -} - -double TRACE_last_timestamp_to_dump = 0; -//dumps the trace file until the timestamp TRACE_last_timestamp_to_dump -void TRACE_paje_dump_buffer(bool force) +double last_timestamp_to_dump = 0; +// dumps the trace file until the last_timestamp_to_dump +void dump_buffer(bool force) { if (not TRACE_is_enabled()) return; - XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump); + XBT_DEBUG("%s: dump until %f. starts", __func__, last_timestamp_to_dump); if (force){ for (auto const& event : buffer) { event->print(); @@ -51,10 +32,10 @@ void TRACE_paje_dump_buffer(bool force) } buffer.clear(); } else { - std::vector::iterator i = buffer.begin(); + std::vector::iterator i = buffer.begin(); for (auto const& event : buffer) { double head_timestamp = event->timestamp_; - if (head_timestamp > TRACE_last_timestamp_to_dump) + if (head_timestamp > last_timestamp_to_dump) break; event->print(); delete event; @@ -66,12 +47,12 @@ void TRACE_paje_dump_buffer(bool force) } /* internal do the instrumentation module */ -void simgrid::instr::PajeEvent::insert_into_buffer() +void PajeEvent::insert_into_buffer() { XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size()); - std::vector::reverse_iterator i; + std::vector::reverse_iterator i; for (i = buffer.rbegin(); i != buffer.rend(); ++i) { - simgrid::instr::PajeEvent* e1 = *i; + PajeEvent* e1 = *i; XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_); if (e1->timestamp_ <= timestamp_) break; @@ -84,3 +65,6 @@ void simgrid::instr::PajeEvent::insert_into_buffer() XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i)); buffer.insert(i.base(), this); } + +} // namespace instr +} // namespace simgrid diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 4306c4c38b..6bf9e2c0ca 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -17,7 +17,7 @@ namespace instr { Type::Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color, Type* father) - : id_(instr_new_paje_id()), name_(name), color_(color), father_(father) + : id_(new_paje_id()), name_(name), color_(color), father_(father) { if (name_.empty() || alias.empty()) throw TracingError(XBT_THROW_POINT, "can't create a new type with no name or alias"); diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp deleted file mode 100644 index 743cfaf479..0000000000 --- a/src/instr/instr_paje_values.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) 2012-2020. The SimGrid Team. - * All rights reserved. */ - -/* 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 "src/instr/instr_private.hpp" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)"); - -namespace simgrid { -namespace instr { - -EntityValue::EntityValue(const std::string& name, const std::string& color, Type* father) - : name_(name), color_(color), father_(father) -{ - id_ = instr_new_paje_id(); - on_creation(*this); -} -} // namespace instr -} // namespace simgrid diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 8de841bb97..7889d9717c 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -306,6 +306,7 @@ static void on_link_creation(s4u::Link const& link) latency->set_calling_container(container); latency->set_event(0, link.get_latency()); } + if (TRACE_uncategorized()) { container->type_->by_name_or_create("bandwidth_used", "0.5 0.5 0.5"); } @@ -389,7 +390,7 @@ static void on_platform_created() recursiveGraphExtraction(s4u::Engine::get_instance()->get_netzone_root(), Container::get_root(), filter); XBT_DEBUG("Graph extraction finished."); delete filter; - TRACE_paje_dump_buffer(true); + dump_buffer(true); } static void on_actor_creation(s4u::Actor const& actor) @@ -462,7 +463,6 @@ void define_callbacks() kernel::routing::NetPoint::on_creation.connect(on_netpoint_creation); } s4u::NetZone::on_creation.connect(on_netzone_creation); - s4u::Engine::on_time_advance.connect([](double /*time_delta*/) { TRACE_paje_dump_buffer(false); }); kernel::resource::CpuAction::on_state_change.connect(on_action_state_change); s4u::Link::on_communication_state_change.connect(on_action_state_change); diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 755f3493ff..f58bf9f074 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -29,13 +29,12 @@ typedef simgrid::instr::Container* container_t; namespace simgrid { namespace instr { -void init(); -void define_callbacks(); +namespace paje { -void platform_graph_export_graphviz(const std::string& output_filename); - -void resource_set_utilization(const char* type, const char* name, const char* resource, const std::string& category, - double value, double now, double delta); +void dump_generator_version(); +void dump_comment_file(const std::string& filename); +void dump_header(bool basic, bool display_sizes); +} // namespace paje /* Format of TRACING output. * - paje is the regular format, that we all know @@ -45,6 +44,19 @@ void resource_set_utilization(const char* type, const char* name, const char* re */ enum class TraceFormat { Paje, /*TimeIndependent*/ Ti }; extern TraceFormat trace_format; +extern int trace_precision; +extern double last_timestamp_to_dump; + +long long int new_paje_id(); + +void init(); +void define_callbacks(); + +void platform_graph_export_graphviz(const std::string& output_filename); + +void resource_set_utilization(const char* type, const char* name, const char* resource, const std::string& category, + double value, double now, double delta); +void dump_buffer(bool force); class TIData { std::string name_; @@ -96,8 +108,8 @@ public: virtual ~TIData() {} - const std::string& getName() const { return name_; } - double getAmount() { return amount_; } + const std::string& get_name() const { return name_; } + double get_amount() const { return amount_; } virtual std::string print() = 0; virtual std::string display_size() = 0; }; @@ -105,7 +117,7 @@ public: class NoOpTIData : public TIData { public: explicit NoOpTIData(const std::string& name) : TIData(name){}; - std::string print() override { return getName(); } + std::string print() override { return get_name(); } std::string display_size() override { return "NA"; } }; @@ -115,10 +127,10 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " " << getAmount(); + stream << get_name() << " " << get_amount(); return stream.str(); } - std::string display_size() override { return std::to_string(getAmount()); } + std::string display_size() override { return std::to_string(get_amount()); } }; class Pt2PtTIData : public TIData { @@ -133,7 +145,7 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " " << endpoint << " "; + stream << get_name() << " " << endpoint << " "; stream << tag << " " << send_size << " " << send_type; return stream.str(); } @@ -148,11 +160,11 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " " << send_size << " "; + stream << get_name() << " " << send_size << " "; if (recv_size >= 0) stream << recv_size << " "; - if (getAmount() >= 0.0) - stream << getAmount() << " "; + if (get_amount() >= 0.0) + stream << get_amount() << " "; if (endpoint > 0 || (endpoint == 0 && not send_type.empty())) stream << endpoint << " "; stream << send_type << " " << recv_type; @@ -176,7 +188,7 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " "; + stream << get_name() << " "; if (send_size >= 0) stream << send_size << " "; if (sendcounts != nullptr) @@ -211,7 +223,7 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " " << src << " " << dest << " " << tag; + stream << get_name() << " " << src << " " << dest << " " << tag; return stream.str(); } @@ -227,7 +239,7 @@ public: std::string print() override { std::stringstream stream; - stream << getName() << " " << memory_consumption; + stream << get_name() << " " << memory_consumption; return stream.str(); } @@ -244,10 +256,6 @@ extern XBT_PRIVATE std::set declared_marks; extern XBT_PRIVATE std::set user_host_variables; extern XBT_PRIVATE std::set user_vm_variables; extern XBT_PRIVATE std::set user_link_variables; -extern XBT_PRIVATE double TRACE_last_timestamp_to_dump; - -/* instr_paje_header.c */ -XBT_PRIVATE void TRACE_header(bool basic, bool size); /* from instr_config.c */ XBT_PRIVATE bool TRACE_needs_platform(); @@ -260,9 +268,7 @@ XBT_PRIVATE bool TRACE_actor_is_enabled(); XBT_PRIVATE bool TRACE_vm_is_enabled(); XBT_PRIVATE bool TRACE_disable_link(); XBT_PRIVATE bool TRACE_disable_speed(); -XBT_PRIVATE bool TRACE_basic(); XBT_PRIVATE bool TRACE_display_sizes(); -XBT_PRIVATE int TRACE_precision(); /* Public functions used in SMPI */ XBT_PUBLIC bool TRACE_smpi_is_enabled(); @@ -272,7 +278,6 @@ XBT_PUBLIC bool TRACE_smpi_is_sleeping(); XBT_PUBLIC bool TRACE_smpi_view_internals(); /* instr_paje.c */ -XBT_PRIVATE long long int instr_new_paje_id(); void instr_new_variable_type(const std::string& new_typename, const std::string& color); void instr_new_user_variable_type(const std::string& father_type, const std::string& new_typename, const std::string& color); @@ -281,9 +286,4 @@ void instr_new_value_for_user_state_type(const std::string& new_typename, const XBT_PRIVATE void TRACE_help(); -XBT_PRIVATE void TRACE_paje_dump_buffer(bool force); -XBT_PRIVATE void dump_comment_file(const std::string& filename); - -XBT_PRIVATE std::string TRACE_get_filename(); - #endif diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index b100682d6e..b7bffa5bd1 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -565,7 +565,6 @@ set(TRACING_SRC src/instr/instr_paje_trace.cpp src/instr/instr_paje_types.cpp src/instr/instr_paje_types.hpp - src/instr/instr_paje_values.cpp src/instr/instr_paje_values.hpp src/instr/instr_platform.cpp src/instr/instr_private.hpp