From 452818ba00f2dee02c41f5f87c0418d6b65b6028 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 27 Mar 2020 14:13:59 +0100 Subject: [PATCH 1/1] use signals to trigger logging of Paje type definitions --- src/instr/instr_config.cpp | 28 +++++++++++ src/instr/instr_paje_types.cpp | 85 ++++++---------------------------- src/instr/instr_paje_types.hpp | 41 ++++++++++------ 3 files changed, 67 insertions(+), 87 deletions(-) diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index b0b66ab369..c3abe0e370 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -235,6 +235,8 @@ static bool trace_active = false; xbt::signal Container::on_creation; xbt::signal Container::on_destruction; xbt::signal EntityValue::on_creation; +xbt::signal Type::on_creation; +xbt::signal LinkType::on_creation; static void on_container_creation_paje(Container& c) { @@ -329,6 +331,30 @@ static void on_entity_value_creation(EntityValue& value) tracing_file << stream.str() << std::endl; } +static void on_type_creation(Type& type, e_event_type event_type) +{ + if (event_type == PAJE_DefineLinkType) + 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 << event_type << " " << type.get_id() << " " << type.get_father()->get_id() << " " << type.get_name(); + if (type.is_colored()) + stream << " \"" << type.get_color() << "\""; + XBT_DEBUG("Dump %s", stream.str().c_str()); + tracing_file << stream.str() << std::endl; +} + +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.); + 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) @@ -351,6 +377,8 @@ static void on_simulation_start() 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); diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index b1e388edd0..4306c4c38b 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -9,44 +9,24 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)"); -extern std::ofstream tracing_file; // to check if variables were previously set to 0, otherwise paje won't simulate them static std::set platform_variables; namespace simgrid { namespace instr { -Type::Type(const std::string& name, const std::string& alias, const std::string& color, Type* father) +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) { if (name_.empty() || alias.empty()) - throw simgrid::TracingError(XBT_THROW_POINT, "can't create a new type with no name or alias"); + throw TracingError(XBT_THROW_POINT, "can't create a new type with no name or alias"); if (father != nullptr){ father->children_[alias].reset(this); XBT_DEBUG("new type %s, child of %s", get_cname(), father->get_cname()); + on_creation(*this, event_type); } - if (trace_format == simgrid::instr::TraceFormat::Paje) { - stream_ << std::fixed << std::setprecision(TRACE_precision()); - } -} - -ContainerType::ContainerType(const std::string& name, Type* father) : Type(name, name, "", father) -{ - XBT_DEBUG("ContainerType %s(%lld), child of %s(%lld)", get_cname(), get_id(), father->get_cname(), father->get_id()); - log_definition(PAJE_DefineContainerType); -} - -EventType::EventType(const std::string& name, Type* father) : ValueType(name, father) -{ - XBT_DEBUG("EventType %s(%lld), child of %s(%lld)", get_cname(), get_id(), father->get_cname(), father->get_id()); - log_definition(PAJE_DefineEventType); -} - -StateType::StateType(const std::string& name, Type* father) : ValueType(name, father) -{ - XBT_DEBUG("StateType %s(%lld), child of %s(%lld)", get_cname(), get_id(), father->get_cname(), father->get_id()); - log_definition(PAJE_DefineStateType); } void StateType::set_event(const std::string& value_name) @@ -74,13 +54,6 @@ void StateType::pop_event(TIData* extra) events_.push_back(new StateEvent(issuer_, this, PAJE_PopState, nullptr, extra)); } -VariableType::VariableType(const std::string& name, const std::string& color, Type* father) - : Type(name, name, color, father) -{ - XBT_DEBUG("VariableType %s(%lld), child of %s(%lld)", get_cname(), get_id(), father->get_cname(), father->get_id()); - log_definition(PAJE_DefineVariableType); -} - void VariableType::instr_event(double now, double delta, const char* resource, double value) { /* To trace resource utilization, we use AddEvent and SubEvent only. This implies to add a SetEvent first to set the @@ -116,9 +89,6 @@ void VariableType::sub_event(double timestamp, double value) events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_SubVariable, value)); } -LinkType::LinkType(const std::string& name, const std::string& alias, Type* father) : ValueType(name, alias, father) -{ -} void LinkType::start_event(Container* startContainer, const std::string& value, const std::string& key) { start_event(startContainer, value, key, -1); @@ -134,45 +104,21 @@ void LinkType::end_event(Container* endContainer, const std::string& value, cons new LinkEvent(issuer_, this, PAJE_EndLink, endContainer, value, key, -1); } -void Type::log_definition(e_event_type event_type) -{ - if (trace_format != simgrid::instr::TraceFormat::Paje) - return; - XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, event_type, TRACE_precision(), 0.); - stream_ << event_type << " " << get_id() << " " << father_->get_id() << " " << get_name(); - if (is_colored()) - stream_ << " \"" << color_ << "\""; - XBT_DEBUG("Dump %s", stream_.str().c_str()); - tracing_file << stream_.str() << std::endl; -} - -void Type::log_definition(simgrid::instr::Type* source, simgrid::instr::Type* dest) -{ - if (trace_format != simgrid::instr::TraceFormat::Paje) - return; - XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, PAJE_DefineLinkType, TRACE_precision(), 0.); - stream_ << PAJE_DefineLinkType << " " << get_id() << " " << father_->get_id() << " " << source->get_id(); - stream_ << " " << dest->get_id() << " " << get_name(); - XBT_DEBUG("Dump %s", stream_.str().c_str()); - tracing_file << stream_.str() << std::endl; -} - Type* Type::by_name(const std::string& name) { Type* ret = nullptr; for (auto const& elm : children_) { if (elm.second->name_ == name) { if (ret != nullptr) { - throw simgrid::TracingError(XBT_THROW_POINT, "there are two children types with the same name?"); + throw TracingError(XBT_THROW_POINT, "there are two children types with the same name?"); } else { ret = elm.second.get(); } } } if (ret == nullptr) - throw simgrid::TracingError( - XBT_THROW_POINT, - simgrid::xbt::string_printf("type with name (%s) not found in father type (%s)", name.c_str(), get_cname())); + throw TracingError(XBT_THROW_POINT, xbt::string_printf("type with name (%s) not found in father type (%s)", + name.c_str(), get_cname())); return ret; } @@ -184,7 +130,7 @@ void ValueType::add_entity_value(const std::string& name) void ValueType::add_entity_value(const std::string& name, const std::string& color) { if (name.empty()) - throw simgrid::TracingError(XBT_THROW_POINT, "can't get a value with no name"); + throw TracingError(XBT_THROW_POINT, "can't get a value with no name"); auto it = values_.find(name); if (it == values_.end()) { @@ -197,9 +143,8 @@ EntityValue* ValueType::get_entity_value(const std::string& name) { auto ret = values_.find(name); if (ret == values_.end()) { - throw simgrid::TracingError( - XBT_THROW_POINT, - simgrid::xbt::string_printf("value with name (%s) not found in father type (%s)", name.c_str(), get_cname())); + throw TracingError(XBT_THROW_POINT, xbt::string_printf("value with name (%s) not found in father type (%s)", + name.c_str(), get_cname())); } return &ret->second; } @@ -217,13 +162,9 @@ LinkType* Type::by_name_or_create(const std::string& name, Type* source, Type* d std::string alias = name + "-" + std::to_string(source->id_) + "-" + std::to_string(dest->id_); auto it = children_.find(alias); if (it == children_.end()) { - LinkType* ret = new LinkType(name, alias, this); - XBT_DEBUG("LinkType %s(%lld), child of %s(%lld) %s(%lld)->%s(%lld)", ret->get_cname(), ret->get_id(), get_cname(), - get_id(), source->get_cname(), source->get_id(), dest->get_cname(), dest->get_id()); - ret->log_definition(source, dest); - return ret; + return new LinkType(name, source, dest, alias, this); } else return static_cast(it->second.get()); } -} -} +} // namespace instr +} // namespace simgrid diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp index 4cc221cd83..c5b8149226 100644 --- a/src/instr/instr_paje_types.hpp +++ b/src/instr/instr_paje_types.hpp @@ -8,7 +8,6 @@ #include "src/instr/instr_private.hpp" #include -#include #include #include @@ -24,16 +23,19 @@ class Type { Type* father_; public: + static xbt::signal on_creation; std::map> children_; Container* issuer_ = nullptr; - std::stringstream stream_; - Type(const std::string& name, const std::string& alias, const std::string& color, Type* father); + Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color, + Type* father); virtual ~Type() = default; + long long int get_id() { return id_; } const std::string& get_name() const { return name_; } const char* get_cname() { return name_.c_str(); } - long long int get_id() { return id_; } + const std::string& get_color() const { return color_; } + Type* get_father() const { return father_; } bool is_colored() { return not color_.empty(); } Type* by_name(const std::string& name); @@ -52,20 +54,22 @@ public: return this; } - void log_definition(e_event_type event_type); void log_definition(Type* source, Type* dest); }; class ContainerType : public Type { public: - explicit ContainerType(const std::string& name) : Type(name, name, "", nullptr){}; - ContainerType(const std::string& name, Type* father); + explicit ContainerType(const std::string& name) : Type(PAJE_DefineContainerType, name, name, "", nullptr){}; + ContainerType(const std::string& name, Type* father) : Type(PAJE_DefineContainerType, name, name, "", father){}; }; class VariableType : public Type { std::vector events_; public: - VariableType(const std::string& name, const std::string& color, Type* father); + VariableType(const std::string& name, const std::string& color, Type* father) + : Type(PAJE_DefineVariableType, name, name, color, father) + { + } void instr_event(double now, double delta, const char* resource, double value); void set_event(double timestamp, double value); void add_event(double timestamp, double value); @@ -75,8 +79,10 @@ public: class ValueType : public Type { public: std::map values_; - ValueType(const std::string& name, const std::string& alias, Type* father) : Type(name, alias, "", father){}; - ValueType(const std::string& name, Type* father) : Type(name, name, "", father){}; + ValueType(e_event_type event_type, const std::string& name, const std::string& alias, Type* father) + : Type(event_type, name, alias, "", father){}; + ValueType(e_event_type event_type, const std::string& name, Type* father) + : Type(event_type, name, name, "", father){}; virtual ~ValueType() = default; void add_entity_value(const std::string& name, const std::string& color); void add_entity_value(const std::string& name); @@ -85,7 +91,12 @@ public: class LinkType : public ValueType { public: - LinkType(const std::string& name, const std::string& alias, Type* father); + static xbt::signal on_creation; + LinkType(const std::string& name, Type* source, Type* dest, const std::string& alias, Type* father) + : ValueType(PAJE_DefineLinkType, name, alias, father) + { + on_creation(*this, *source, *dest); + } void start_event(Container* startContainer, const std::string& value, const std::string& key); void start_event(Container* startContainer, const std::string& value, const std::string& key, int size); void end_event(Container* endContainer, const std::string& value, const std::string& key); @@ -93,19 +104,19 @@ public: class EventType : public ValueType { public: - EventType(const std::string& name, Type* father); + EventType(const std::string& name, Type* father) : ValueType(PAJE_DefineEventType, name, father) {} }; class StateType : public ValueType { std::vector events_; public: - StateType(const std::string& name, Type* father); + StateType(const std::string& name, Type* father) : ValueType(PAJE_DefineStateType, name, father) {} void set_event(const std::string& value_name); void push_event(const std::string& value_name); void push_event(const std::string& value_name, TIData* extra); void pop_event(); void pop_event(TIData* extra); }; -} -} +} // namespace instr +} // namespace simgrid #endif -- 2.30.2