Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use signals on PajeEvent creation/destruction
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Apr 2020 10:59:11 +0000 (12:59 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Apr 2020 12:37:21 +0000 (14:37 +0200)
src/instr/instr_config.cpp
src/instr/instr_paje_containers.cpp
src/instr/instr_paje_events.cpp
src/instr/instr_paje_events.hpp

index f80a379..f9fa1b4 100644 (file)
@@ -218,9 +218,12 @@ int trace_precision;
  *************/
 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;
+xbt::signal<void(PajeEvent&)> PajeEvent::on_creation;
+xbt::signal<void(PajeEvent&)> PajeEvent::on_destruction;
+xbt::signal<void(StateEvent&)> StateEvent::on_destruction;
+xbt::signal<void(EntityValue&)> EntityValue::on_creation;
 
 static void on_container_creation_paje(Container& c)
 {
@@ -243,10 +246,6 @@ 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
-  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()) {
     std::stringstream stream;
@@ -289,12 +288,7 @@ 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
-  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());
     if (not simgrid::config::get_value<bool>("tracing/smpi/format/ti-one-file") || tracing_files.size() == 1) {
       tracing_files.at(&c)->close();
       delete tracing_files.at(&c);
@@ -315,6 +309,26 @@ static void on_entity_value_creation(EntityValue& value)
   tracing_file << stream.str() << std::endl;
 }
 
+static void on_event_creation(PajeEvent& event)
+{
+  XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, event.eventType_, trace_precision, event.timestamp_);
+  event.stream_ << std::fixed << std::setprecision(trace_precision);
+  event.stream_ << event.eventType_ << " " << event.timestamp_ << " ";
+  event.stream_ << event.get_type()->get_id() << " " << event.get_container()->get_id();
+}
+
+static void on_event_destruction(PajeEvent& event)
+{
+  XBT_DEBUG("Dump %s", event.stream_.str().c_str());
+  tracing_file << event.stream_.str() << std::endl;
+}
+
+static void on_state_event_destruction(StateEvent& event)
+{
+  if (event.has_extra())
+    *tracing_files.at(event.get_container()) << event.stream_.str() << std::endl;
+}
+
 static void on_type_creation(Type& type, e_event_type event_type)
 {
   if (event_type == PAJE_DefineLinkType)
@@ -370,6 +384,8 @@ static void on_simulation_start()
     EntityValue::on_creation.connect(on_entity_value_creation);
     Type::on_creation.connect(on_type_creation);
     LinkType::on_creation.connect(on_link_type_creation);
+    PajeEvent::on_creation.connect(on_event_creation);
+    PajeEvent::on_destruction.connect(on_event_destruction);
 
     paje::dump_generator_version();
 
@@ -385,6 +401,7 @@ static void on_simulation_start()
     trace_format = TraceFormat::Ti;
     Container::on_creation.connect(on_container_creation_ti);
     Container::on_destruction.connect(on_container_destruction_ti);
+    StateEvent::on_destruction.connect(on_state_event_destruction);
   }
 
   trace_active = true;
index 9e5169f..941f2de 100644 (file)
@@ -91,6 +91,10 @@ Container::~Container()
   // remove me from the allContainers data structure
   allContainers.erase(name_);
 
+  // obligation to dump previous events because they might reference the container that is about to be destroyed
+  last_timestamp_to_dump = SIMIX_get_clock();
+  dump_buffer(true);
+
   on_destruction(*this);
 }
 
index 5161881..6ba97ee 100644 (file)
@@ -9,8 +9,6 @@
 #include "src/surf/surf_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
-extern std::ofstream tracing_file;
-extern std::map<container_t, std::ofstream*> tracing_files; // TI specific
 
 namespace simgrid {
 namespace instr {
@@ -18,21 +16,13 @@ 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_);
-  if (trace_format == TraceFormat::Paje) {
-    stream_ << std::fixed << std::setprecision(trace_precision);
-    stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
-  }
+  on_creation(*this);
   insert_into_buffer();
 }
 
-void PajeEvent::print()
+PajeEvent::~PajeEvent()
 {
-  if (trace_format != TraceFormat::Paje)
-    return;
-
-  XBT_DEBUG("Dump %s", stream_.str().c_str());
-  tracing_file << stream_.str() << std::endl;
+  on_destruction(*this);
 }
 
 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
@@ -49,38 +39,15 @@ StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type
 
 void NewEvent::print()
 {
-  if (trace_format != TraceFormat::Paje)
-    return;
-
   stream_ << " " << value->get_id();
-
-  XBT_DEBUG("Dump %s", stream_.str().c_str());
-  tracing_file << stream_.str() << std::endl;
 }
 
 void LinkEvent::print()
 {
-  if (trace_format != TraceFormat::Paje)
-    return;
-
   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
 
   if (TRACE_display_sizes() && size_ != -1)
     stream_ << " " << size_;
-
-  XBT_DEBUG("Dump %s", stream_.str().c_str());
-  tracing_file << stream_.str() << std::endl;
-}
-
-void VariableEvent::print()
-{
-  if (trace_format != TraceFormat::Paje)
-    return;
-
-  stream_ << " " << value_;
-
-  XBT_DEBUG("Dump %s", stream_.str().c_str());
-  tracing_file << stream_.str() << std::endl;
 }
 
 void StateEvent::print()
@@ -93,12 +60,9 @@ void StateEvent::print()
       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : "");
 
 #if HAVE_SMPI
-    if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
+    if (simgrid::config::get_value<bool>("smpi/trace-call-location"))
       stream_ << " \"" << filename << "\" " << linenumber;
-    }
 #endif
-    XBT_DEBUG("Dump %s", stream_.str().c_str());
-    tracing_file << stream_.str() << std::endl;
   } else if (trace_format == TraceFormat::Ti) {
     if (extra_ == nullptr)
       return;
@@ -111,12 +75,10 @@ void StateEvent::print()
       container_name=std::to_string(stoi(container_name.erase(0, 5)) - 1);
     }
 #if HAVE_SMPI
-    if (config::get_value<bool>("smpi/trace-call-location")) {
+    if (config::get_value<bool>("smpi/trace-call-location"))
       stream_ << container_name << " location " << filename << " " << linenumber << std::endl ;
-    }
 #endif
     stream_ << container_name << " " << extra_->print();
-    *tracing_files.at(get_container()) << stream_.str() << std::endl;
   } else {
     THROW_IMPOSSIBLE;
   }
index 668eabc..744ada9 100644 (file)
@@ -40,16 +40,21 @@ enum e_event_type : unsigned int {
 class PajeEvent {
   Container* container_;
   Type* type_;
-protected:
-  Container* get_container() { return container_; }
 public:
+  static xbt::signal<void(PajeEvent&)> on_creation;
+  static xbt::signal<void(PajeEvent&)> on_destruction;
+
   double timestamp_;
   e_event_type eventType_;
   std::stringstream stream_;
 
   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType);
-  virtual ~PajeEvent() = default;
-  virtual void print();
+  virtual ~PajeEvent();
+
+  Container* get_container() const { return container_; }
+  Type* get_type() const { return type_; }
+
+  virtual void print() = 0;
   void insert_into_buffer();
 };
 
@@ -61,7 +66,7 @@ public:
       : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
   {
   }
-  void print() override;
+  void print() override { stream_ << " " << value_; }
 };
 
 class StateEvent : public PajeEvent {
@@ -73,7 +78,10 @@ class StateEvent : public PajeEvent {
   std::unique_ptr<TIData> extra_;
 
 public:
+  static xbt::signal<void(StateEvent&)> on_destruction;
   StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra);
+  ~StateEvent() { on_destruction(*this); }
+  bool has_extra() { return extra_ != nullptr; }
   void print() override;
 };
 
@@ -106,6 +114,6 @@ public:
   }
   void print() override;
 };
-}
-}
+} // namespace instr
+} // namespace simgrid
 #endif