From: Frederic Suter Date: Wed, 18 Oct 2017 09:30:36 +0000 (+0200) Subject: Value is always attached to Type X-Git-Tag: v3.18~419 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c871d5837bd9fefd1942daf48982e3c34c507abb Value is always attached to Type replace Value::byNameOrCreate and Value::byName by Type::addEntityValue and Type::getEntityValue --- diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 6263fcde8d..65d54c7654 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -187,7 +187,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar mark_color = "1.0 1.0 1.0" /*white*/; XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color); - simgrid::instr::Value::byNameOrCreate(mark_value, mark_color, type); + type->addEntityValue(mark_value, mark_color); } /** \ingroup TRACE_mark @@ -239,8 +239,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::byName(mark_value, type)); + new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type, type->getEntityValue(mark_value)); } /** \ingroup TRACE_mark @@ -937,12 +936,12 @@ void TRACE_host_state_declare_value (const char *state, const char *value, const * * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state */ -void TRACE_host_set_state(const char* host, const char* state, const char* value_str) +void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name) { - container_t container = simgrid::instr::Container::byName(host); - simgrid::instr::Type* type = container->type_->byName(state); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(value_str, "", type); - new simgrid::instr::SetStateEvent(MSG_get_clock(), container, type, val); + container_t container = simgrid::instr::Container::byName(host); + simgrid::instr::Type* state = container->type_->byName(state_name); + state->addEntityValue(value_name); + new simgrid::instr::SetStateEvent(MSG_get_clock(), container, state, state->getEntityValue(value_name)); } /** \ingroup TRACE_user_variables @@ -956,12 +955,12 @@ void TRACE_host_set_state(const char* host, const char* state, const char* value * * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state */ -void TRACE_host_push_state(const char* host, const char* state, const char* value_str) +void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name) { container_t container = simgrid::instr::Container::byName(host); - simgrid::instr::Type* type = container->type_->byName(state); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(value_str, "", type); - new simgrid::instr::PushStateEvent(MSG_get_clock(), container, type, val); + simgrid::instr::Type* state = container->type_->byName(state_name); + state->addEntityValue(value_name); + new simgrid::instr::PushStateEvent(MSG_get_clock(), container, state, state->getEntityValue(value_name)); } /** \ingroup TRACE_user_variables diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 87c7f2030a..a6e5a95a25 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -53,6 +53,37 @@ Type* Type::byName(std::string name) return ret; } +void Type::addEntityValue(std::string name) +{ + addEntityValue(name, ""); +} + +void Type::addEntityValue(std::string name, std::string color) +{ + if (name.empty()) { + THROWF(tracing_error, 0, "can't get a value with no name"); + } + if (kind_ == TYPE_VARIABLE) + THROWF(tracing_error, 0, "variables can't have different values (%s)", getCname()); + + auto it = values_.find(name); + if (it == values_.end()) { + Value* new_val = new Value(name, color, this); + values_.insert({name, new_val}); + XBT_DEBUG("new value %s, child of %s", name_.c_str(), getCname()); + new_val->print(); + } +} + +Value* Type::getEntityValue(std::string name) +{ + auto ret = values_.find(name); + if (ret == values_.end()) { + THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), getCname()); + } + return ret->second; +} + Type* Type::createRootType() { simgrid::instr::Type* ret = new simgrid::instr::Type("0", "0", "", TYPE_CONTAINER, nullptr); diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 380f1c6a76..b49b3fec1c 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -14,14 +14,7 @@ namespace instr { Value::Value(std::string name, std::string color, Type* father) : name_(name), color_(color), father_(father) { - if (name.empty() || father == nullptr) { - THROWF(tracing_error, 0, "can't create a value with no name (or a nullptr father)"); - } this->id_ = std::to_string(instr_new_paje_id()); - - father->values_.insert({name, this}); - XBT_DEBUG("new value %s, child of %s", name_.c_str(), father_->getCname()); - print(); }; Value::~Value() @@ -29,30 +22,5 @@ Value::~Value() XBT_DEBUG("free value %s, child of %s", getCname(), father_->getCname()); } -Value* Value::byNameOrCreate(std::string name, std::string color, Type* father) -{ - Value* ret = nullptr; - try { - ret = Value::byName(name, father); - } catch (xbt_ex& e) { - ret = new Value(name, color, father); - } - return ret; -} - -Value* Value::byName(std::string name, Type* father) -{ - if (name.empty() || father == nullptr) { - THROWF(tracing_error, 0, "can't get a value with no name (or a nullptr father)"); - } - - if (father->getKind() == TYPE_VARIABLE) - THROWF(tracing_error, 0, "variables can't have different values (%s)", father->getCname()); - auto ret = father->values_.find(name); - if (ret == father->values_.end()) { - THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), father->getCname()); - } - return ret->second; -} } } diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index f7d6bedf6d..1a1c9c7d0a 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -85,6 +85,10 @@ public: Type* getOrCreateStateType(std::string name); Type* getOrCreateVariableType(std::string name, std::string color); + void addEntityValue(std::string name, std::string color); + void addEntityValue(std::string name); + Value* getEntityValue(std::string name); + void logContainerTypeDefinition(); void logVariableTypeDefinition(); void logStateTypeDefinition(); @@ -102,12 +106,9 @@ class Value { std::string color_; Type* father_; - explicit Value(std::string name, std::string color, Type* father); - public: + explicit Value(std::string name, std::string color, Type* father); ~Value(); - 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(); } diff --git a/src/msg/instr_msg_process.cpp b/src/msg/instr_msg_process.cpp index d82c9ca9e4..fbffce2e03 100644 --- a/src/msg/instr_msg_process.cpp +++ b/src/msg/instr_msg_process.cpp @@ -95,9 +95,9 @@ void TRACE_msg_process_suspend(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = simgrid::instr::Container::byName(instr_process_id(process, str, len)); - simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byName("suspend", type); - new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); + simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE"); + simgrid::instr::Value* val = state->getEntityValue("suspend"); + new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -120,9 +120,9 @@ void TRACE_msg_process_sleep_in(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = simgrid::instr::Container::byName(instr_process_id(process, str, len)); - simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byName("sleep", type); - new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); + simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE"); + simgrid::instr::Value* val = state->getEntityValue("sleep"); + new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } diff --git a/src/msg/instr_msg_task.cpp b/src/msg/instr_msg_task.cpp index 4eb14d30fa..633e0417f1 100644 --- a/src/msg/instr_msg_task.cpp +++ b/src/msg/instr_msg_task.cpp @@ -53,9 +53,9 @@ void TRACE_msg_task_execute_start(msg_task_t task) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byName("task_execute", type); - new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); + simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE"); + simgrid::instr::Value* val = state->getEntityValue("task_execute"); + new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -93,9 +93,9 @@ void TRACE_msg_task_get_start() char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byName("receive", type); - new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); + simgrid::instr::Type* state = process_container->type_->byName("MSG_PROCESS_STATE"); + simgrid::instr::Value* val = state->getEntityValue("receive"); + new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -129,7 +129,7 @@ int TRACE_msg_task_put_start(msg_task_t task) container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self(), str, len)); simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byName("send", type); + simgrid::instr::Value* val = type->getEntityValue("send"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); char key[INSTR_DEFAULT_STR_SIZE]; diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 126d3d83dd..032b24c774 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -185,10 +185,10 @@ void MSG_vm_start(msg_vm_t vm) { vm->start(); if (TRACE_msg_vm_is_enabled()) { - container_t vm_container = simgrid::instr::Container::byName(vm->getName()); - simgrid::instr::Type* type = vm_container->type_->byName("MSG_VM_STATE"); - 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); + container_t vm_container = simgrid::instr::Container::byName(vm->getName()); + simgrid::instr::Type* state = vm_container->type_->byName("MSG_VM_STATE"); + state->addEntityValue("start", "0 0 1"); // start is blue + new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, state, state->getEntityValue("start")); } } @@ -768,10 +768,10 @@ void MSG_vm_suspend(msg_vm_t vm) XBT_DEBUG("vm_suspend done"); if (TRACE_msg_vm_is_enabled()) { - container_t vm_container = simgrid::instr::Container::byName(vm->getName()); - simgrid::instr::Type* type = vm_container->type_->byName("MSG_VM_STATE"); - 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); + container_t vm_container = simgrid::instr::Container::byName(vm->getName()); + simgrid::instr::Type* state = vm_container->type_->byName("MSG_VM_STATE"); + state->addEntityValue("suspend", "1 0 0"); // suspend is red + new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, state, state->getEntityValue("suspend")); } } diff --git a/src/smpi/colls/smpi_automatic_selector.cpp b/src/smpi/colls/smpi_automatic_selector.cpp index 12ef8f3c8b..31ca8a976f 100644 --- a/src/smpi/colls/smpi_automatic_selector.cpp +++ b/src/smpi/colls/smpi_automatic_selector.cpp @@ -20,9 +20,9 @@ \ char cont_name[25]; \ snprintf(cont_name, 25, "rank-%d", smpi_process()->index()); \ - simgrid::instr::Value* val = \ - 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(), simgrid::instr::Container::byName(cont_name), type, val); \ + type->addEntityValue(Colls::mpi_coll_##cat##_description[i].name, "1.0 1.0 1.0"); \ + new simgrid::instr::NewEvent(SIMIX_get_clock(), simgrid::instr::Container::byName(cont_name), type, \ + type->getEntityValue(Colls::mpi_coll_##cat##_description[i].name)); \ } #define AUTOMATIC_COLL_BENCH(cat, ret, args, args2) \ diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 2d07348478..58ee601491 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -237,8 +237,9 @@ void TRACE_smpi_collective_in(int rank, const char *operation, instr_extra_data container_t container = simgrid::instr::Container::byName(str); simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); const char *color = instr_find_color (operation); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(operation, color, type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); + type->addEntityValue(operation, color); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, type->getEntityValue(operation), + static_cast(extra)); } void TRACE_smpi_collective_out(int rank, const char *operation) @@ -264,9 +265,8 @@ void TRACE_smpi_computing_init(int rank) smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - const char* color = instr_find_color("computing"); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, - simgrid::instr::Value::byNameOrCreate("computing", color, type)); + type->addEntityValue("computing", instr_find_color("computing")); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, type->getEntityValue("computing")); } void TRACE_smpi_computing_in(int rank, instr_extra_data extra) @@ -281,8 +281,9 @@ void TRACE_smpi_computing_in(int rank, instr_extra_data extra) smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("computing", "", type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); + type->addEntityValue("computing"); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, type->getEntityValue("computing"), + static_cast(extra)); } void TRACE_smpi_computing_out(int rank) @@ -305,10 +306,9 @@ void TRACE_smpi_sleeping_init(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); - simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - const char *color = instr_find_color ("sleeping"); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("sleeping", color, type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val); + simgrid::instr::Type* state = container->type_->byName("MPI_STATE"); + state->addEntityValue("sleeping", instr_find_color("sleeping")); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, state, state->getEntityValue("sleeping")); } void TRACE_smpi_sleeping_in(int rank, instr_extra_data extra) @@ -322,9 +322,10 @@ void TRACE_smpi_sleeping_in(int rank, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); - simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("sleeping", "", type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); + simgrid::instr::Type* state = container->type_->byName("MPI_STATE"); + state->addEntityValue("sleeping"); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, state, state->getEntityValue("sleeping"), + static_cast(extra)); } void TRACE_smpi_sleeping_out(int rank) @@ -349,9 +350,10 @@ void TRACE_smpi_testing_in(int rank, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); - simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate("test", "", type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); + simgrid::instr::Type* state = container->type_->byName("MPI_STATE"); + state->addEntityValue("test"); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, state, state->getEntityValue("test"), + static_cast(extra)); } void TRACE_smpi_testing_out(int rank) @@ -375,10 +377,10 @@ void TRACE_smpi_ptp_in(int rank, const char *operation, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = simgrid::instr::Container::byName(str); - simgrid::instr::Type* type = container->type_->byName("MPI_STATE"); - const char *color = instr_find_color (operation); - simgrid::instr::Value* val = simgrid::instr::Value::byNameOrCreate(operation, color, type); - new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); + simgrid::instr::Type* state = container->type_->byName("MPI_STATE"); + state->addEntityValue(operation, instr_find_color(operation)); + new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, state, state->getEntityValue(operation), + static_cast(extra)); } void TRACE_smpi_ptp_out(int rank, int dst, const char *operation) diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 6447bce76b..ccb7013263 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -223,11 +223,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) if (TRACE_msg_process_is_enabled()) { simgrid::instr::Type* msg_process = container->type_->getOrCreateContainerType("MSG_PROCESS"); simgrid::instr::Type* state = msg_process->getOrCreateStateType("MSG_PROCESS_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); + state->addEntityValue("suspend", "1 0 1"); + state->addEntityValue("sleep", "1 1 0"); + state->addEntityValue("receive", "1 0 0"); + state->addEntityValue("send", "0 0 1"); + state->addEntityValue("task_execute", "0 1 1"); simgrid::instr::Type::getRootType()->getOrCreateLinkType("MSG_PROCESS_LINK", msg_process, msg_process); simgrid::instr::Type::getRootType()->getOrCreateLinkType("MSG_PROCESS_TASK_LINK", msg_process, msg_process); } @@ -235,11 +235,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) if (TRACE_msg_vm_is_enabled()) { simgrid::instr::Type* msg_vm = container->type_->getOrCreateContainerType("MSG_VM"); simgrid::instr::Type* state = msg_vm->getOrCreateStateType("MSG_VM_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); + state->addEntityValue("suspend", "1 0 1"); + state->addEntityValue("sleep", "1 1 0"); + state->addEntityValue("receive", "1 0 0"); + state->addEntityValue("send", "0 0 1"); + state->addEntityValue("task_execute", "0 1 1"); simgrid::instr::Type::getRootType()->getOrCreateLinkType("MSG_VM_LINK", msg_vm, msg_vm); simgrid::instr::Type::getRootType()->getOrCreateLinkType("MSG_VM_PROCESS_LINK", msg_vm, msg_vm); } @@ -333,7 +333,7 @@ static void recursiveNewValueForUserStateType(std::string type_name, const char* simgrid::instr::Type* root) { if (root->getName() == type_name) - simgrid::instr::Value::byNameOrCreate(val, color, root); + root->addEntityValue(val, color); for (auto elm : root->children_) recursiveNewValueForUserStateType(type_name, val, color, elm.second);