xbt::signal<void(Container&)> Container::on_creation;
xbt::signal<void(Container&)> Container::on_destruction;
xbt::signal<void(EntityValue&)> EntityValue::on_creation;
+xbt::signal<void(Type&, e_event_type)> Type::on_creation;
+xbt::signal<void(LinkType&, Type&, Type&)> LinkType::on_creation;
static void on_container_creation_paje(Container& c)
{
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)
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);
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<std::string> 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)
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
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);
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;
}
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()) {
{
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;
}
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<LinkType*>(it->second.get());
}
-}
-}
+} // namespace instr
+} // namespace simgrid
#include "src/instr/instr_private.hpp"
#include <memory>
-#include <sstream>
#include <string>
#include <vector>
Type* father_;
public:
+ static xbt::signal<void(Type&, e_event_type event_type)> on_creation;
std::map<std::string, std::unique_ptr<Type>> 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);
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<VariableEvent*> 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);
class ValueType : public Type {
public:
std::map<std::string, EntityValue> 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);
class LinkType : public ValueType {
public:
- LinkType(const std::string& name, const std::string& alias, Type* father);
+ static xbt::signal<void(LinkType&, Type&, Type&)> 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);
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<StateEvent*> 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