From: Frederic Suter Date: Fri, 20 Oct 2017 12:22:35 +0000 (+0200) Subject: get rid of Container kind_ X-Git-Tag: v3.18~402 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/bd3293edb97258154dfa1a4222b384ef0145e369?ds=sidebyside get rid of Container kind_ --- diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 3d002d6e9d..b1979f37bd 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -181,13 +181,13 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName(mark_type); if (not type) { THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type); - } - - if (not mark_color) - mark_color = "1.0 1.0 1.0" /*white*/; + } else { + if (not mark_color) + mark_color = "1.0 1.0 1.0" /*white*/; - XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color); - type->addEntityValue(mark_value, mark_color); + XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color); + type->addEntityValue(mark_value, mark_color); + } } /** \ingroup TRACE_mark @@ -236,10 +236,10 @@ void TRACE_mark(const char *mark_type, const char *mark_value) simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName(mark_type); if (not type) { THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type); + } else { + XBT_DEBUG("MARK %s %s", mark_type, mark_value); + new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type, type->getEntityValue(mark_value)); } - - XBT_DEBUG("MARK %s %s", mark_type, mark_value); - new simgrid::instr::NewEvent(MSG_get_clock(), PJ_container_get_root(), type, type->getEntityValue(mark_value)); } /** \ingroup TRACE_mark diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 3316dbd057..1c8e4b47bd 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -39,63 +39,56 @@ void PJ_container_set_root (container_t root) namespace simgrid { namespace instr { -Container::Container(std::string name, e_container_types kind, Container* father) - : kind_(kind), name_(name), father_(father) +NetZoneContainer::NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father) + : Container::Container(name, "", father) +{ + netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); + xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); + if (father_) { + type_ = father_->type_->getOrCreateContainerType(std::string("L") + std::to_string(level)); + father_->children_.insert({getName(), this}); + logCreation(); + } else { + type_ = Type::createRootType(); + PJ_container_set_root(this); + } +} + +RouterContainer::RouterContainer(std::string name, Container* father) : Container::Container(name, "ROUTER", father) +{ + xbt_assert(father, "Only the Root container has no father"); + + netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); + xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); + + trivaNodeTypes.insert(type_->getName()); +} + +HostContainer::HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father) + : Container::Container(host.getCname(), "HOST", father) +{ + xbt_assert(father, "Only the Root container has no father"); + + netpoint_ = host.pimpl_netpoint; + xbt_assert(netpoint_, "Element '%s' not found", host.getCname()); + + trivaNodeTypes.insert(type_->getName()); +} + +Container::Container(std::string name, std::string type_name, Container* father) : name_(name), father_(father) { static long long int container_id = 0; - id_ = std::to_string(container_id); // id (or alias) of the container + id_ = container_id; // id (or alias) of the container container_id++; if (father_) { - level_ = father_->level_ + 1; XBT_DEBUG("new container %s, child of %s", name.c_str(), father->name_.c_str()); - } - // Search for network_element_t for AS, ROUTER and HOST - // Name the kind of container. For AS otherwise, the name depends on its level - std::string typeNameBuff; - switch (kind_) { - case INSTR_AS: - netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); - xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); - typeNameBuff = std::string("L") + std::to_string(level_); - break; - case INSTR_ROUTER: - netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); - xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); - typeNameBuff = std::string("ROUTER"); - break; - case INSTR_HOST: - netpoint_ = sg_host_by_name(name.c_str())->pimpl_netpoint; - xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); - typeNameBuff = std::string("HOST"); - break; - case INSTR_LINK: - typeNameBuff = std::string("LINK"); - break; - case INSTR_SMPI: - typeNameBuff = std::string("MPI"); - break; - case INSTR_MSG_PROCESS: - typeNameBuff = std::string("MSG_PROCESS"); - break; - case INSTR_MSG_VM: - typeNameBuff = std::string("MSG_VM"); - break; - case INSTR_MSG_TASK: - typeNameBuff = std::string("MSG_TASK"); - break; - default: - THROWF(tracing_error, 0, "new container kind is unknown."); - break; - } - - if (father_) { - type_ = father_->type_->getOrCreateContainerType(typeNameBuff); - father_->children_.insert({name_, this}); - logCreation(); - } else if (kind_ == INSTR_AS) { - type_ = Type::createRootType(); + if (not type_name.empty()) { + type_ = father_->type_->getOrCreateContainerType(type_name); + father_->children_.insert({name_, this}); + logCreation(); + } } //register all kinds by name @@ -106,7 +99,7 @@ Container::Container(std::string name, e_container_types kind, Container* father XBT_DEBUG("Add container name '%s'", name_.c_str()); //register NODE types for triva configuration - if (kind_ == INSTR_HOST || kind_ == INSTR_LINK || kind_ == INSTR_ROUTER) + if (type_name == "LINK") trivaNodeTypes.insert(type_->getName()); } diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index 1d7f079ce2..973f6d0db3 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -301,7 +301,7 @@ void simgrid::instr::SetVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->getId() << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -325,7 +325,7 @@ void simgrid::instr::AddVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->getId() << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -348,7 +348,7 @@ void simgrid::instr::SubVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->getId() << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -379,7 +379,7 @@ void simgrid::instr::SetStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_; + stream << " " << type->getId() << " " << container->getId(); stream << " " << value->getId(); #if HAVE_SMPI if (xbt_cfg_get_boolean("smpi/trace-call-location")) { @@ -422,7 +422,7 @@ void simgrid::instr::PushStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_; + stream << " " << type->getId() << " " << container->getId(); stream << " " << value->getId(); if (TRACE_display_sizes()) { @@ -595,7 +595,7 @@ void simgrid::instr::PopStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_; + stream << " " << type->getId() << " " << container->getId(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -619,7 +619,7 @@ void simgrid::instr::ResetStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_; + stream << " " << type->getId() << " " << container->getId(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -653,8 +653,8 @@ void simgrid::instr::StartLinkEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << value_; - stream << " " << sourceContainer_->id_ << " " << key_; + stream << " " << type->getId() << " " << container->getId() << " " << value_; + stream << " " << sourceContainer_->getId() << " " << key_; if (TRACE_display_sizes()) { stream << " " << size_; @@ -685,8 +685,8 @@ void simgrid::instr::EndLinkEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << value; - stream << " " << destContainer->id_ << " " << key; + stream << " " << type->getId() << " " << container->getId() << " " << value; + stream << " " << destContainer->getId() << " " << key; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -712,7 +712,7 @@ void simgrid::instr::NewEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->getId() << " " << container->id_ << " " << val->getId(); + stream << " " << type->getId() << " " << container->getId() << " " << val->getId(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 4c1136d52c..3e632e5f07 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -97,7 +97,6 @@ public: static Type* getRootType(); }; -//-------------------------------------------------- class Value { std::string name_; std::string id_; @@ -113,42 +112,43 @@ public: void print(); }; -//-------------------------------------------------- -enum e_container_types { - INSTR_HOST, - INSTR_LINK, - INSTR_ROUTER, - INSTR_AS, - INSTR_SMPI, - INSTR_MSG_VM, - INSTR_MSG_PROCESS, - INSTR_MSG_TASK -}; - class Container { - e_container_types kind_; /* This container is of what kind */ + long long int id_; std::string name_; /* Unique name of this container */ - int level_ = 0; /* Level in the hierarchy, root level is 0 */ - sg_netpoint_t netpoint_ = nullptr; - public: - Container(std::string name, simgrid::instr::e_container_types kind, Container* father); + Container(std::string name, std::string type_name, Container* father); virtual ~Container(); - std::string id_; /* Unique id of this container */ Type* type_; /* Type of this container */ Container* father_; std::map children_; + sg_netpoint_t netpoint_ = nullptr; + static Container* byNameOrNull(std::string name); static Container* byName(std::string name); std::string getName() { return name_; } const char* getCname() { return name_.c_str(); } + long long int getId() { return id_; } void removeFromParent(); void logCreation(); void logDestruction(); }; -//-------------------------------------------------- +class NetZoneContainer : public Container { +public: + NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father); +}; + +class RouterContainer : public Container { +public: + RouterContainer(std::string name, Container* father); +}; + +class HostContainer : public Container { +public: + HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father); +}; + class PajeEvent { protected: Container* container; diff --git a/src/msg/instr_msg_process.cpp b/src/msg/instr_msg_process.cpp index 92c01a1617..0343d4fbb0 100644 --- a/src/msg/instr_msg_process.cpp +++ b/src/msg/instr_msg_process.cpp @@ -44,8 +44,8 @@ void TRACE_msg_process_create (const char *process_name, int process_pid, msg_ho { if (TRACE_msg_process_is_enabled()){ container_t host_container = simgrid::instr::Container::byName(host->getName()); - new simgrid::instr::Container(std::string(process_name) + "-" + std::to_string(process_pid), - simgrid::instr::INSTR_MSG_PROCESS, host_container); + new simgrid::instr::Container(std::string(process_name) + "-" + std::to_string(process_pid), "MSG_PROCESS", + host_container); } } diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 2a569bd846..00ea1e87ec 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -303,8 +303,7 @@ static int migration_rx_fun(int argc, char *argv[]) delete existing_container; // create new container on the new_host location - new simgrid::instr::Container(vm->getCname(), simgrid::instr::INSTR_MSG_VM, - simgrid::instr::Container::byName(ms->dst_pm->getName())); + new simgrid::instr::Container(vm->getCname(), "MSG_VM", simgrid::instr::Container::byName(ms->dst_pm->getName())); // end link msg = simgrid::instr::Container::byName(vm->getName()); diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 8e74223a10..3dd17c2970 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -33,7 +33,7 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount) if (TRACE_msg_vm_is_enabled()) { container_t host_container = simgrid::instr::Container::byName(pm->getName()); - new simgrid::instr::Container(name, simgrid::instr::INSTR_MSG_VM, host_container); + new simgrid::instr::Container(name, "MSG_VM", host_container); } } diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 581f87fabb..f5f7708c98 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -164,7 +164,7 @@ void TRACE_smpi_init(int rank) #if HAVE_PAPI container_t container = #endif - new simgrid::instr::Container(str, simgrid::instr::INSTR_SMPI, father); + new simgrid::instr::Container(str, "MPI", father); #if HAVE_PAPI papi_counter_t counters = smpi_process()->papi_counters(); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index fdb97b0faa..1a68583a5e 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -17,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy"); static int platform_created = 0; /* indicate whether the platform file has been traced */ -static std::vector currentContainer; /* push and pop, used only in creation */ +static std::vector currentContainer; /* push and pop, used only in creation */ static const char *instr_node_name (xbt_node_t node) { @@ -154,8 +154,7 @@ static void sg_instr_AS_begin(simgrid::s4u::NetZone& netzone) std::string id = netzone.getName(); if (PJ_container_get_root() == nullptr){ - container_t root = new simgrid::instr::Container(id, simgrid::instr::INSTR_AS, nullptr); - PJ_container_set_root (root); + simgrid::instr::NetZoneContainer* root = new simgrid::instr::NetZoneContainer(id, 0, nullptr); if (TRACE_smpi_is_enabled()) { simgrid::instr::Type* mpi = root->type_->getOrCreateContainerType("MPI"); @@ -171,8 +170,8 @@ static void sg_instr_AS_begin(simgrid::s4u::NetZone& netzone) } if (TRACE_needs_platform()){ - container_t father = currentContainer.back(); - container_t container = new simgrid::instr::Container(id, simgrid::instr::INSTR_AS, father); + simgrid::instr::NetZoneContainer* container = + new simgrid::instr::NetZoneContainer(id, currentContainer.size(), currentContainer.back()); currentContainer.push_back(container); } } @@ -190,7 +189,7 @@ static void instr_routing_parse_start_link(simgrid::s4u::Link& link) return; container_t father = currentContainer.back(); - container_t container = new simgrid::instr::Container(link.getName(), simgrid::instr::INSTR_LINK, father); + 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", ""); @@ -205,8 +204,7 @@ static void instr_routing_parse_start_link(simgrid::s4u::Link& link) static void sg_instr_new_host(simgrid::s4u::Host& host) { - container_t father = currentContainer.back(); - container_t container = new simgrid::instr::Container(host.getName(), simgrid::instr::INSTR_HOST, father); + 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", ""); @@ -246,10 +244,8 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) static void sg_instr_new_router(simgrid::kernel::routing::NetPoint * netpoint) { - if (not netpoint->isRouter()) - return; - if (TRACE_is_enabled() && TRACE_needs_platform()) - new simgrid::instr::Container(netpoint->getCname(), simgrid::instr::INSTR_ROUTER, currentContainer.back()); + if (netpoint->isRouter() && TRACE_is_enabled() && TRACE_needs_platform()) + new simgrid::instr::RouterContainer(netpoint->getCname(), currentContainer.back()); } static void instr_routing_parse_end_platform ()