Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rework Variable related events
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 27 Oct 2017 19:03:58 +0000 (21:03 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 27 Oct 2017 19:03:58 +0000 (21:03 +0200)
src/instr/instr_interface.cpp
src/instr/instr_paje_events.cpp
src/instr/instr_paje_trace.cpp
src/instr/instr_paje_types.cpp
src/instr/instr_paje_types.hpp
src/instr/instr_private.hpp
src/instr/instr_resource_utilization.cpp
src/surf/instr_routing.cpp
src/surf/instr_surf.cpp

index 0182dd2..17c13fc 100644 (file)
@@ -260,7 +260,7 @@ xbt_dynar_t TRACE_get_marks ()
   return instr_set_to_dynar(&declared_marks);
 }
 
-static void instr_user_variable(double time, const char* resource, const char* variable, const char* father_type,
+static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* father_type,
                                 double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
 {
   /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
@@ -268,27 +268,28 @@ static void instr_user_variable(double time, const char* resource, const char* v
     return;
 
   //check if variable is already declared
-  auto created = filter->find(variable);
+  auto created = filter->find(variable_name);
   if (what == INSTR_US_DECLARE){
     if (created == filter->end()) { // not declared yet
-      filter->insert(variable);
-      instr_new_user_variable_type(father_type, variable, color == nullptr ? "" : color);
+      filter->insert(variable_name);
+      instr_new_user_variable_type(father_type, variable_name, color == nullptr ? "" : color);
     }
   }else{
     if (created != filter->end()) { // declared, let's work
       char valuestr[100];
       snprintf(valuestr, 100, "%g", value);
       container_t container      = simgrid::instr::Container::byName(resource);
-      simgrid::instr::Type* type = container->type_->byName(variable);
+      simgrid::instr::VariableType* variable =
+          static_cast<simgrid::instr::VariableType*>(container->type_->byName(variable_name));
       switch (what){
       case INSTR_US_SET:
-        new simgrid::instr::SetVariableEvent(time, container, type, value);
+        variable->setEvent(time, container, value);
         break;
       case INSTR_US_ADD:
-        new simgrid::instr::AddVariableEvent(time, container, type, value);
+        variable->addEvent(time, container, value);
         break;
       case INSTR_US_SUB:
-        new simgrid::instr::SubVariableEvent(time, container, type, value);
+        variable->subEvent(time, container, value);
         break;
       default:
         THROW_IMPOSSIBLE;
index 7997d0f..5f897c6 100644 (file)
@@ -15,6 +15,13 @@ std::map<container_t, FILE*> tracing_files; // TI specific
 namespace simgrid {
 namespace instr {
 
+VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
+    : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
+{
+  XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
+  insertIntoBuffer();
+}
+
 StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value)
     : StateEvent(timestamp, container, type, event_type, value, nullptr)
 {
@@ -36,6 +43,22 @@ StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_eve
   insertIntoBuffer();
 };
 
+void VariableEvent::print()
+{
+  std::stringstream stream;
+  stream << std::fixed << std::setprecision(TRACE_precision());
+  XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
+  if (instr_fmt_type != instr_fmt_paje)
+    return;
+
+  if (timestamp_ < 1e-12)
+    stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value;
+  else
+    stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value;
+  XBT_DEBUG("Dump %s", stream.str().c_str());
+  fprintf(tracing_file, "%s\n", stream.str().c_str());
+}
+
 void StateEvent::print()
 {
   std::stringstream stream;
index 255c28e..555746b 100644 (file)
@@ -176,75 +176,6 @@ void TRACE_paje_end() {
   XBT_DEBUG("Filename %s is closed", filename);
 }
 
-simgrid::instr::SetVariableEvent::SetVariableEvent(double timestamp, container_t container, Type* type, double value)
-    : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SetVariable), value(value)
-{
-  XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
-  insertIntoBuffer();
-}
-
-void simgrid::instr::SetVariableEvent::print()
-{
-  if (instr_fmt_type == instr_fmt_paje) {
-    XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
-    stream << std::fixed << std::setprecision(TRACE_precision()) << this->eventType_;
-    print_timestamp(this);
-    stream << " " << type->getId() << " " << container->getId() << " " << value;
-    print_row();
-  } else if (instr_fmt_type == instr_fmt_TI) {
-    /* Nothing to do */
-  } else {
-    THROW_IMPOSSIBLE;
-  }
-}
-
-simgrid::instr::AddVariableEvent::AddVariableEvent(double timestamp, container_t container, simgrid::instr::Type* type,
-                                                   double value)
-    : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_AddVariable), value(value)
-{
-  XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
-  insertIntoBuffer();
-}
-
-void simgrid::instr::AddVariableEvent::print()
-{
-  if (instr_fmt_type == instr_fmt_paje) {
-    XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
-    stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << eventType_;
-    print_timestamp(this);
-    stream << " " << type->getId() << " " << container->getId() << " " << value;
-    print_row();
-  } else if (instr_fmt_type == instr_fmt_TI) {
-    /* Nothing to do */
-  } else {
-    THROW_IMPOSSIBLE;
-  }
-}
-
-simgrid::instr::SubVariableEvent::SubVariableEvent(double timestamp, container_t container, Type* type, double value)
-    : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SubVariable), value(value)
-{
-  XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
-  insertIntoBuffer();
-}
-
-void simgrid::instr::SubVariableEvent::print()
-{
-  if (instr_fmt_type == instr_fmt_paje) {
-    XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
-    stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << eventType_;
-    print_timestamp(this);
-    stream << " " << type->getId() << " " << container->getId() << " " << value;
-    print_row();
-  } else if (instr_fmt_type == instr_fmt_TI) {
-    /* Nothing to do */
-  } else {
-    THROW_IMPOSSIBLE;
-  }
-}
-
 simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
                                                container_t sourceContainer, std::string value, std::string key)
     : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
index f86eb05..efac49e 100644 (file)
@@ -87,6 +87,26 @@ VariableType::VariableType(std::string name, std::string color, Type* father) :
   logDefinition(PAJE_DefineVariableType);
 }
 
+VariableType::~VariableType()
+{
+  events_.clear();
+}
+
+void VariableType::setEvent(double timestamp, Container* container, double value)
+{
+  events_.push_back(new VariableEvent(timestamp, container, this, PAJE_SetVariable, value));
+}
+
+void VariableType::addEvent(double timestamp, Container* container, double value)
+{
+  events_.push_back(new VariableEvent(timestamp, container, this, PAJE_AddVariable, value));
+}
+
+void VariableType::subEvent(double timestamp, Container* container, double value)
+{
+  events_.push_back(new VariableEvent(timestamp, container, this, PAJE_SubVariable, value));
+}
+
 LinkType::LinkType(std::string name, std::string alias, Type* father) : ValueType(name, alias, father)
 {
 }
index c487ed0..8ec8648 100644 (file)
@@ -20,6 +20,7 @@ class LinkType;
 class StateType;
 class VariableType;
 class StateEvent;
+class VariableEvent;
 
 class Type {
   long long int id_;
@@ -59,8 +60,14 @@ public:
 };
 
 class VariableType : public Type {
+  std::vector<VariableEvent*> events_;
+
 public:
   VariableType(std::string name, std::string color, Type* father);
+  ~VariableType();
+  void setEvent(double timestamp, Container* container, double value);
+  void addEvent(double timestamp, Container* container, double value);
+  void subEvent(double timestamp, Container* container, double value);
 };
 
 class ValueType : public Type {
index 4a9433b..4aa9285 100644 (file)
@@ -90,27 +90,11 @@ public:
   void insertIntoBuffer();
 };
 
-class SetVariableEvent : public PajeEvent {
+class VariableEvent : public PajeEvent {
   double value;
 
 public:
-  SetVariableEvent(double timestamp, Container* container, Type* type, double value);
-  void print() override;
-};
-
-class AddVariableEvent : public PajeEvent {
-  double value;
-
-public:
-  AddVariableEvent(double timestamp, Container* container, Type* type, double value);
-  void print() override;
-};
-
-class SubVariableEvent : public PajeEvent {
-  double value;
-
-public:
-  SubVariableEvent(double timestamp, Container* container, Type* type, double value);
+  VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value);
   void print() override;
 };
 
index 5c2eb80..7de5c32 100644 (file)
@@ -13,11 +13,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorize
 //to check if variables were previously set to 0, otherwise paje won't simulate them
 static std::set<std::string> platform_variables;
 
-static void instr_event(double now, double delta, simgrid::instr::Type* variable, container_t resource, double value)
+static void instr_event(double now, double delta, simgrid::instr::VariableType* variable, container_t resource,
+                        double value)
 {
-  /* To trace resource utilization, we use AddVariableEvent and SubVariableEvent only. This implies to add a
-   * SetVariableEvent first to set the initial value of all variables for subsequent adds/subs. If we don't do so,
-   * the first AddVariableEvent would be added to a non-determined value, hence causing analysis problems.
+  /* To trace resource utilization, we use AddEvent and SubEvent only. This implies to add a SetEvent first to set the
+   * initial value of all variables for subsequent adds/subs. If we don't do so, the first AddEvent would be added to a
+   * non-determined value, hence causing analysis problems.
    */
 
   // create a key considering the resource and variable
@@ -25,12 +26,12 @@ static void instr_event(double now, double delta, simgrid::instr::Type* variable
 
   // check if key exists: if it doesn't, set the variable to zero and mark this in the global map.
   if (platform_variables.find(key) == platform_variables.end()) {
-    new simgrid::instr::SetVariableEvent(now, resource, variable, 0);
+    variable->setEvent(now, resource, 0);
     platform_variables.insert(key);
   }
 
-  new simgrid::instr::AddVariableEvent(now, resource, variable, value);
-  new simgrid::instr::SubVariableEvent(now + delta, resource, variable, value);
+  variable->addEvent(now, resource, value);
+  variable->subEvent(now + delta, resource, value);
 }
 
 /* TRACE_surf_link_set_utilization: entry point from SimGrid */
@@ -44,8 +45,9 @@ void TRACE_surf_link_set_utilization(const char *resource, const char *category,
   //trace uncategorized link utilization
   if (TRACE_uncategorized()){
     XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now + delta, resource, value);
-    simgrid::instr::Type* type = container->type_->byName("bandwidth_used");
-    instr_event (now, delta, type, container, value);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName("bandwidth_used"));
+    instr_event(now, delta, variable, container, value);
   }
 
   //trace categorized utilization
@@ -55,8 +57,9 @@ void TRACE_surf_link_set_utilization(const char *resource, const char *category,
     //variable of this category starts by 'b', because we have a link here
     std::string category_type = std::string("b") + category;
     XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
-    simgrid::instr::Type* type = container->type_->byName(category_type);
-    instr_event (now, delta, type, container, value);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
+    instr_event(now, delta, variable, container, value);
   }
 }
 
@@ -71,8 +74,9 @@ void TRACE_surf_host_set_utilization(const char *resource, const char *category,
   //trace uncategorized host utilization
   if (TRACE_uncategorized()){
     XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
-    simgrid::instr::Type* type = container->type_->byName("power_used");
-    instr_event (now, delta, type, container, value);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName("power_used"));
+    instr_event(now, delta, variable, container, value);
   }
 
   //trace categorized utilization
@@ -82,7 +86,8 @@ void TRACE_surf_host_set_utilization(const char *resource, const char *category,
     //variable of this category starts by 'p', because we have a host here
     std::string category_type = std::string("p") + category;
     XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
-    simgrid::instr::Type* type = container->type_->byName(category_type);
-    instr_event (now, delta, type, container, value);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
+    instr_event(now, delta, variable, container, value);
   }
 }
index 9501542..3272ca9 100644 (file)
@@ -193,10 +193,8 @@ static void instr_routing_parse_start_link(simgrid::s4u::Link& link)
   container_t container = new simgrid::instr::Container(link.getName(), "LINK", father);
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_link())) {
-    simgrid::instr::Type* bandwidth = container->type_->getOrCreateVariableType("bandwidth", "");
-    simgrid::instr::Type* latency   = container->type_->getOrCreateVariableType("latency", "");
-    new simgrid::instr::SetVariableEvent(0, container, bandwidth, link.bandwidth());
-    new simgrid::instr::SetVariableEvent(0, container, latency, link.latency());
+    container->type_->getOrCreateVariableType("bandwidth", "")->setEvent(0, container, link.bandwidth());
+    container->type_->getOrCreateVariableType("latency", "")->setEvent(0, container, link.latency());
   }
   if (TRACE_uncategorized()) {
     container->type_->getOrCreateVariableType("bandwidth_used", "0.5 0.5 0.5");
@@ -208,8 +206,7 @@ static void sg_instr_new_host(simgrid::s4u::Host& host)
   container_t container = new simgrid::instr::HostContainer(host, currentContainer.back());
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) {
-    simgrid::instr::Type* speed = container->type_->getOrCreateVariableType("power", "");
-    new simgrid::instr::SetVariableEvent(0, container, speed, host.getSpeed());
+    container->type_->getOrCreateVariableType("power", "")->setEvent(0, container, host.getSpeed());
   }
 
   if (TRACE_uncategorized())
index 8c6e0b1..b53c55f 100644 (file)
@@ -13,8 +13,9 @@ void TRACE_surf_host_set_speed(double date, const char *resource, double speed)
 {
   if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
     container_t container      = simgrid::instr::Container::byName(resource);
-    simgrid::instr::Type* type = container->type_->byName("power");
-    new simgrid::instr::SetVariableEvent(date, container, type, speed);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName("power"));
+    variable->setEvent(date, container, speed);
   }
 }
 
@@ -22,8 +23,9 @@ void TRACE_surf_link_set_bandwidth(double date, const char *resource, double ban
 {
   if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
     container_t container      = simgrid::instr::Container::byName(resource);
-    simgrid::instr::Type* type = container->type_->byName("bandwidth");
-    new simgrid::instr::SetVariableEvent(date, container, type, bandwidth);
+    simgrid::instr::VariableType* variable =
+        static_cast<simgrid::instr::VariableType*>(container->type_->byName("bandwidth"));
+    variable->setEvent(date, container, bandwidth);
   }
 }