Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stringify and objectify instr::Value (wip)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 10 Oct 2017 15:05:16 +0000 (17:05 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 10 Oct 2017 15:51:36 +0000 (17:51 +0200)
get -> byName
get_or_new -> byNameOrCreate (as for mailboxes)
constructor and most fields are private + accessors

src/instr/instr_interface.cpp
src/instr/instr_paje_trace.cpp
src/instr/instr_paje_types.cpp
src/instr/instr_paje_values.cpp
src/instr/instr_private.hpp
src/msg/instr_msg_process.cpp
src/msg/instr_msg_task.cpp
src/msg/msg_vm.cpp
src/smpi/colls/smpi_automatic_selector.cpp
src/smpi/internals/instr_smpi.cpp
src/surf/instr_routing.cpp

index 71762f4..bad1970 100644 (file)
@@ -193,7 +193,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar
     mark_color = white;
 
   XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
-  new simgrid::instr::Value(mark_value, mark_color, type);
+  simgrid::instr::Value::byNameOrCreate(mark_value, mark_color, type);
 }
 
 /** \ingroup TRACE_mark
@@ -246,7 +246,7 @@ void TRACE_mark(const char *mark_type, const char *mark_value)
 
   XBT_DEBUG("MARK %s %s", mark_type, mark_value);
   new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type,
-                               simgrid::instr::Value::get(mark_value, type));
+                               simgrid::instr::Value::byName(mark_value, type));
 }
 
 /** \ingroup TRACE_mark
@@ -947,8 +947,8 @@ void TRACE_host_set_state(const char* host, const char* state, const char* value
 {
   container_t container = PJ_container_get(host);
   simgrid::instr::Type* type = container->type_->getChild(state);
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
-      value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(
+      value_str, "", type); /* if user didn't declare a value with a color, use no color */
   new simgrid::instr::SetStateEvent(MSG_get_clock(), container, type, val);
 }
 
@@ -967,8 +967,8 @@ void TRACE_host_push_state(const char* host, const char* state, const char* valu
 {
   container_t container = PJ_container_get(host);
   simgrid::instr::Type* type = container->type_->getChild(state);
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(
-      value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(
+      value_str, "", type); /* if user didn't declare a value with a color, use no color */
   new simgrid::instr::PushStateEvent(MSG_get_clock(), container, type, val);
 }
 
index 23ed224..bc855cb 100644 (file)
@@ -285,16 +285,16 @@ if (instr_fmt_type == instr_fmt_paje) {
   }
 }
 
-void LogEntityValue(simgrid::instr::Value* val)
+void simgrid::instr::Value::print()
 {
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineEntityValue);
   //print it
 if (instr_fmt_type == instr_fmt_paje) {
     stream << std::fixed << std::setprecision(TRACE_precision());
     stream << simgrid::instr::PAJE_DefineEntityValue;
-    stream << " " << val->id_ << " " << val->father_->id_ << " " << val->name_;
-    if (val->color_)
-      stream << " \"" << val->color_ << "\"";
+    stream << " " << id_ << " " << father_->id_ << " " << name_;
+    if (isColored())
+      stream << " \"" << color_ << "\"";
     print_row();
   } else if (instr_fmt_type == instr_fmt_TI) {
     /* Nothing to do */
@@ -490,7 +490,7 @@ void simgrid::instr::SetStateEvent::print()
     stream << (int)this->eventType_;
     print_timestamp(this);
     stream << " " << type->id_ << " " << container->id_;
-    stream << " " << value->id_;
+    stream << " " << value->getId();
 #if HAVE_SMPI
     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
       stream << " \"" << filename << "\" " << linenumber;
@@ -535,7 +535,7 @@ void simgrid::instr::PushStateEvent::print()
     stream << (int)this->eventType_;
     print_timestamp(this);
     stream << " " << type->id_ << " " << container->id_;
-    stream << " " << value->id_;
+    stream << " " << value->getId();
 
     if (TRACE_display_sizes()) {
       stream << " ";
@@ -677,7 +677,7 @@ void simgrid::instr::PushStateEvent::print()
       case TRACING_SSEND:
       case TRACING_ISSEND:
       default:
-        XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name_);
+        XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
         break;
     }
 
@@ -841,7 +841,7 @@ void simgrid::instr::NewEvent::print()
     stream << std::fixed << std::setprecision(TRACE_precision());
     stream << (int)this->eventType_;
     print_timestamp(this);
-    stream << " " << type->id_ << " " << container->id_ << " " << val->id_;
+    stream << " " << type->id_ << " " << container->id_ << " " << val->getId();
     print_row();
   } else if (instr_fmt_type == instr_fmt_TI) {
     /* Nothing to do */
index b1e5532..1b03324 100644 (file)
@@ -42,7 +42,7 @@ simgrid::instr::Type::~Type()
   char *value_name;
   xbt_dict_cursor_t cursor = nullptr;
   xbt_dict_foreach (values_, cursor, value_name, val) {
-    XBT_DEBUG("free value %s, child of %s", val->name_, val->father_->name_);
+    XBT_DEBUG("free value %s, child of %s", val->getCname(), val->father_->name_);
     delete val;
   }
   xbt_dict_free(&values_);
index 5a4d269..f6cff86 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)");
 
-simgrid::instr::Value::Value(const char* name, const char* color, simgrid::instr::Type* father) : father_(father)
+simgrid::instr::Value::Value(std::string name, std::string color, simgrid::instr::Type* father) : father_(father)
 {
-  if (name == nullptr || father == nullptr){
-    THROWF (tracing_error, 0, "can't create a value with a nullptr name (or a nullptr father)");
+  if (name.empty() || father == nullptr) {
+    THROWF(tracing_error, 0, "can't create a value with no name (or a nullptr father)");
   }
-  this->name_   = xbt_strdup(name);
-  this->color_  = xbt_strdup(color);
+  this->name_  = name;
+  this->color_ = color;
+  this->id_    = std::to_string(instr_new_paje_id());
 
-  this->id_ = bprintf("%lld", instr_new_paje_id());
-
-  xbt_dict_set(father->values_, name, this, nullptr);
-  XBT_DEBUG("new value %s, child of %s", name_, father_->name_);
-  LogEntityValue(this);
+  xbt_dict_set(father->values_, name.c_str(), this, nullptr);
+  XBT_DEBUG("new value %s, child of %s", name_.c_str(), father_->name_);
+  print();
 };
 
-simgrid::instr::Value::~Value()
-{
-  xbt_free(name_);
-  xbt_free(color_);
-  xbt_free(id_);
-}
-
-simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const char* color,
-                                                         simgrid::instr::Type* father)
+simgrid::instr::Value* simgrid::instr::Value::byNameOrCreate(std::string name, std::string color,
+                                                             simgrid::instr::Type* father)
 {
   Value* ret = 0;
   try {
-    ret = Value::get(name, father);
+    ret = Value::byName(name, father);
   }
   catch(xbt_ex& e) {
     ret = new Value(name, color, father);
@@ -45,17 +37,17 @@ simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const
   return ret;
 }
 
-simgrid::instr::Value* simgrid::instr::Value::get(const char* name, Type* father)
+simgrid::instr::Value* simgrid::instr::Value::byName(std::string name, Type* father)
 {
-  if (name == nullptr || father == nullptr){
-    THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
+  if (name.empty() || father == nullptr) {
+    THROWF(tracing_error, 0, "can't get a value with no name (or a nullptr father)");
   }
 
   if (father->kind_ == TYPE_VARIABLE)
     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_);
-  Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name);
+  Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name.c_str());
   if (ret == nullptr) {
-    THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name_);
+    THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), father->name_);
   }
   return ret;
 }
index 0e3d8ec..cc7fcc4 100644 (file)
@@ -78,16 +78,22 @@ public:
 
 //--------------------------------------------------
 class Value {
-public:
-  char* id_;
-  char* name_;
-  char* color_;
+private:
+  std::string name_;
+  std::string id_;
+  std::string color_;
+
+  explicit Value(std::string name, std::string color, Type* father);
 
+public:
+  ~Value() = default;
   Type* father_;
-  Value(const char* name, const char* color, Type* father);
-  ~Value();
-  static Value* get_or_new(const char* name, const char* color, Type* father);
-  static Value* get(const char* name, Type* father);
+  static Value* byNameOrCreate(std::string name, std::string color, Type* father);
+  static Value* byName(std::string name, Type* father);
+  const char* getCname() { return name_.c_str(); }
+  const char* getId() { return id_.c_str(); }
+  bool isColored() { return not color_.empty(); }
+  void print();
 };
 
 //--------------------------------------------------
@@ -404,7 +410,6 @@ void LogContainerTypeDefinition(simgrid::instr::Type* type);
 void LogVariableTypeDefinition(simgrid::instr::Type* type);
 void LogStateTypeDefinition(simgrid::instr::Type* type);
 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
-void LogEntityValue(simgrid::instr::Value* val);
 void LogContainerCreation(container_t container);
 void LogContainerDestruction(container_t container);
 void LogDefineEventType(simgrid::instr::Type* type);
index 6c396a1..81526f6 100644 (file)
@@ -95,7 +95,7 @@ void TRACE_msg_process_suspend(msg_process_t process)
 
     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
     simgrid::instr::Type* type    = process_container->type_->getChild("MSG_PROCESS_STATE");
-    simgrid::instr::Value* val    = simgrid::instr::Value::get("suspend", type);
+    simgrid::instr::Value* val    = simgrid::instr::Value::byName("suspend", type);
     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
   }
 }
@@ -120,7 +120,7 @@ void TRACE_msg_process_sleep_in(msg_process_t process)
 
     container_t process_container = PJ_container_get (instr_process_id(process, str, len));
     simgrid::instr::Type* type    = process_container->type_->getChild("MSG_PROCESS_STATE");
-    simgrid::instr::Value* val    = simgrid::instr::Value::get("sleep", type);
+    simgrid::instr::Value* val    = simgrid::instr::Value::byName("sleep", type);
     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
   }
 }
index 4c54cf2..369aa77 100644 (file)
@@ -54,7 +54,7 @@ void TRACE_msg_task_execute_start(msg_task_t task)
 
     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
     simgrid::instr::Type* type    = process_container->type_->getChild("MSG_PROCESS_STATE");
-    simgrid::instr::Value* val    = simgrid::instr::Value::get("task_execute", type);
+    simgrid::instr::Value* val    = simgrid::instr::Value::byName("task_execute", type);
     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
   }
 }
@@ -94,7 +94,7 @@ void TRACE_msg_task_get_start()
 
     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
     simgrid::instr::Type* type    = process_container->type_->getChild("MSG_PROCESS_STATE");
-    simgrid::instr::Value* val    = simgrid::instr::Value::get("receive", type);
+    simgrid::instr::Value* val    = simgrid::instr::Value::byName("receive", type);
     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
   }
 }
@@ -129,7 +129,7 @@ int TRACE_msg_task_put_start(msg_task_t task)
 
     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
     simgrid::instr::Type* type    = process_container->type_->getChild("MSG_PROCESS_STATE");
-    simgrid::instr::Value* val    = simgrid::instr::Value::get("send", type);
+    simgrid::instr::Value* val    = simgrid::instr::Value::byName("send", type);
     new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val);
 
     char key[INSTR_DEFAULT_STR_SIZE];
index 50f0f47..14ac69d 100644 (file)
@@ -188,7 +188,7 @@ void MSG_vm_start(msg_vm_t vm)
   if (TRACE_msg_vm_is_enabled()) {
     container_t vm_container = PJ_container_get(vm->getCname());
     simgrid::instr::Type* type = vm_container->type_->getChild("MSG_VM_STATE");
-    simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("start", "0 0 1", type); // start is blue
+    simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("start", "0 0 1", type); // start is blue
     new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, type, val);
   }
 }
@@ -771,7 +771,7 @@ void MSG_vm_suspend(msg_vm_t vm)
   if (TRACE_msg_vm_is_enabled()) {
     container_t vm_container = PJ_container_get(vm->getCname());
     simgrid::instr::Type* type = vm_container->type_->getChild("MSG_VM_STATE");
-    simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("suspend", "1 0 0", type); // suspend is red
+    simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("suspend", "1 0 0", type); // suspend is red
     new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, type, val);
   }
 }
index 7b75b79..ec28e51 100644 (file)
@@ -23,7 +23,7 @@
     char cont_name[25];                                                                                                \
     snprintf(cont_name, 25, "rank-%d", smpi_process()->index());                                                       \
     simgrid::instr::Value* val =                                                                                       \
-        simgrid::instr::Value::get_or_new(Colls::mpi_coll_##cat##_description[i].name, "1.0 1.0 1.0", type);           \
+        simgrid::instr::Value::byNameOrCreate(Colls::mpi_coll_##cat##_description[i].name, "1.0 1.0 1.0", type);       \
     new simgrid::instr::NewEvent(SIMIX_get_clock(), PJ_container_get(cont_name), type, val);                           \
   }
 
index 305b232..ae223f0 100644 (file)
@@ -237,7 +237,7 @@ void TRACE_smpi_collective_in(int rank, const char *operation, instr_extra_data
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
   const char *color = instr_find_color (operation);
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(operation, color, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(operation, color, type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast<void*>(extra));
 }
 
@@ -266,7 +266,7 @@ void TRACE_smpi_computing_init(int rank)
  simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
  const char* color     = instr_find_color("computing");
  new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type,
-                                    simgrid::instr::Value::get_or_new("computing", color, type));
+                                    simgrid::instr::Value::byNameOrCreate("computing", color, type));
 }
 
 void TRACE_smpi_computing_in(int rank, instr_extra_data extra)
@@ -281,7 +281,7 @@ void TRACE_smpi_computing_in(int rank, instr_extra_data extra)
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("computing", nullptr, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("computing", "", type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast<void*>(extra));
 }
 
@@ -307,7 +307,7 @@ void TRACE_smpi_sleeping_init(int rank)
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
   const char *color = instr_find_color ("sleeping");
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("sleeping", color, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("sleeping", color, type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val);
 }
 
@@ -323,7 +323,7 @@ void TRACE_smpi_sleeping_in(int rank, instr_extra_data extra)
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("sleeping", nullptr, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("sleeping", "", type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast<void*>(extra));
 }
 
@@ -350,7 +350,7 @@ void TRACE_smpi_testing_in(int rank, instr_extra_data extra)
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("test", nullptr, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("test", "", type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast<void*>(extra));
 }
 
@@ -377,7 +377,7 @@ void TRACE_smpi_ptp_in(int rank, const char *operation, instr_extra_data extra)
   container_t container = PJ_container_get (str);
   simgrid::instr::Type* type = container->type_->getChild("MPI_STATE");
   const char *color = instr_find_color (operation);
-  simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(operation, color, type);
+  simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(operation, color, type);
   new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast<void*>(extra));
 }
 
index 50f60c2..7bf6a62 100644 (file)
@@ -257,11 +257,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host)
     if (msg_process == nullptr){
       msg_process                 = simgrid::instr::Type::containerNew("MSG_PROCESS", container->type_);
       simgrid::instr::Type* state = simgrid::instr::Type::stateNew("MSG_PROCESS_STATE", msg_process);
-      new simgrid::instr::Value("suspend", "1 0 1", state);
-      simgrid::instr::Value::get_or_new("sleep", "1 1 0", state);
-      simgrid::instr::Value::get_or_new("receive", "1 0 0", state);
-      simgrid::instr::Value::get_or_new("send", "0 0 1", state);
-      simgrid::instr::Value::get_or_new("task_execute", "0 1 1", state);
+      simgrid::instr::Value::byNameOrCreate("suspend", "1 0 1", state);
+      simgrid::instr::Value::byNameOrCreate("sleep", "1 1 0", state);
+      simgrid::instr::Value::byNameOrCreate("receive", "1 0 0", state);
+      simgrid::instr::Value::byNameOrCreate("send", "0 0 1", state);
+      simgrid::instr::Value::byNameOrCreate("task_execute", "0 1 1", state);
       simgrid::instr::Type::linkNew("MSG_PROCESS_LINK", PJ_type_get_root(), msg_process, msg_process);
       simgrid::instr::Type::linkNew("MSG_PROCESS_TASK_LINK", PJ_type_get_root(), msg_process, msg_process);
     }
@@ -272,11 +272,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host)
     if (msg_vm == nullptr){
       msg_vm                      = simgrid::instr::Type::containerNew("MSG_VM", container->type_);
       simgrid::instr::Type* state = simgrid::instr::Type::stateNew("MSG_VM_STATE", msg_vm);
-      new simgrid::instr::Value("suspend", "1 0 1", state);
-      simgrid::instr::Value::get_or_new("sleep", "1 1 0", state);
-      simgrid::instr::Value::get_or_new("receive", "1 0 0", state);
-      simgrid::instr::Value::get_or_new("send", "0 0 1", state);
-      simgrid::instr::Value::get_or_new("task_execute", "0 1 1", state);
+      simgrid::instr::Value::byNameOrCreate("suspend", "1 0 1", state);
+      simgrid::instr::Value::byNameOrCreate("sleep", "1 1 0", state);
+      simgrid::instr::Value::byNameOrCreate("receive", "1 0 0", state);
+      simgrid::instr::Value::byNameOrCreate("send", "0 0 1", state);
+      simgrid::instr::Value::byNameOrCreate("task_execute", "0 1 1", state);
       simgrid::instr::Type::linkNew("MSG_VM_LINK", PJ_type_get_root(), msg_vm, msg_vm);
       simgrid::instr::Type::linkNew("MSG_VM_PROCESS_LINK", PJ_type_get_root(), msg_vm, msg_vm);
     }
@@ -394,7 +394,7 @@ static void recursiveNewValueForUserStateType(const char* type_name, const char*
                                               simgrid::instr::Type* root)
 {
   if (not strcmp(root->name_, type_name)) {
-    new simgrid::instr::Value(val, color, root);
+    simgrid::instr::Value::byNameOrCreate(val, color, root);
   }
   xbt_dict_cursor_t cursor = nullptr;
   simgrid::instr::Type* child_type;