X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f007dc1ac31aa9c04cc02e3b87d525d7f198b7f6..064b14e9ad70077e74cbc8ce42d4925f80d76ed4:/src/instr/instr_paje_containers.cpp diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 0ab2877c7e..c449a97006 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -5,18 +5,15 @@ #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" - #include "surf/surf.h" - -#include "src/instr/instr_private.h" +#include "src/instr/instr_private.hpp" #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing event system (containers)"); static container_t rootContainer = nullptr; /* the root container */ -static std::unordered_map - allContainers; /* all created containers indexed by name */ +static std::unordered_map allContainers; /* all created containers indexed by name */ std::set trivaNodeTypes; /* all host types defined */ std::set trivaEdgeTypes; /* all link types defined */ @@ -26,12 +23,20 @@ long long int instr_new_paje_id () return type_id++; } +container_t PJ_container_get_root() +{ + return rootContainer; +} + void PJ_container_set_root (container_t root) { rootContainer = root; } -simgrid::instr::Container::Container(std::string name, simgrid::instr::e_container_types kind, Container* father) +namespace simgrid { +namespace instr { + +Container::Container(std::string name, e_container_types kind, Container* father) : name_(name), kind_(kind), father_(father) { static long long int container_id = 0; @@ -40,15 +45,15 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain //Search for network_element_t switch (kind){ - case simgrid::instr::INSTR_HOST: + case INSTR_HOST: this->netpoint_ = sg_host_by_name(name.c_str())->pimpl_netpoint; xbt_assert(this->netpoint_, "Element '%s' not found", name.c_str()); break; - case simgrid::instr::INSTR_ROUTER: + case INSTR_ROUTER: this->netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); xbt_assert(this->netpoint_, "Element '%s' not found", name.c_str()); break; - case simgrid::instr::INSTR_AS: + case INSTR_AS: this->netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); xbt_assert(this->netpoint_, "Element '%s' not found", name.c_str()); break; @@ -63,50 +68,50 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain } // type definition (method depends on kind of this new container) - if (this->kind_ == simgrid::instr::INSTR_AS) { + if (this->kind_ == INSTR_AS) { //if this container is of an AS, its type name depends on its level char as_typename[INSTR_DEFAULT_STR_SIZE]; snprintf(as_typename, INSTR_DEFAULT_STR_SIZE, "L%d", this->level_); if (this->father_) { this->type_ = this->father_->type_->getChildOrNull(as_typename); if (this->type_ == nullptr) { - this->type_ = simgrid::instr::Type::containerNew(as_typename, this->father_->type_); + this->type_ = Type::containerNew(as_typename, this->father_->type_); } }else{ - this->type_ = simgrid::instr::Type::containerNew("0", nullptr); + this->type_ = Type::containerNew("0", nullptr); } } else { //otherwise, the name is its kind char typeNameBuff[INSTR_DEFAULT_STR_SIZE]; switch (this->kind_) { - case simgrid::instr::INSTR_HOST: + case INSTR_HOST: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "HOST"); break; - case simgrid::instr::INSTR_LINK: + case INSTR_LINK: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "LINK"); break; - case simgrid::instr::INSTR_ROUTER: + case INSTR_ROUTER: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "ROUTER"); break; - case simgrid::instr::INSTR_SMPI: + case INSTR_SMPI: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "MPI"); break; - case simgrid::instr::INSTR_MSG_PROCESS: + case INSTR_MSG_PROCESS: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "MSG_PROCESS"); break; - case simgrid::instr::INSTR_MSG_VM: + case INSTR_MSG_VM: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "MSG_VM"); break; - case simgrid::instr::INSTR_MSG_TASK: + case INSTR_MSG_TASK: snprintf (typeNameBuff, INSTR_DEFAULT_STR_SIZE, "MSG_TASK"); break; default: THROWF (tracing_error, 0, "new container kind is unknown."); break; } - simgrid::instr::Type* type = this->father_->type_->getChildOrNull(typeNameBuff); + Type* type = this->father_->type_->getChildOrNull(typeNameBuff); if (type == nullptr){ - this->type_ = simgrid::instr::Type::containerNew(typeNameBuff, this->father_->type_); + this->type_ = Type::containerNew(typeNameBuff, this->father_->type_); }else{ this->type_ = type; } @@ -124,12 +129,12 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain XBT_DEBUG("Add container name '%s'", this->name_.c_str()); //register NODE types for triva configuration - if (this->kind_ == simgrid::instr::INSTR_HOST || this->kind_ == simgrid::instr::INSTR_LINK || - this->kind_ == simgrid::instr::INSTR_ROUTER) { - trivaNodeTypes.insert(this->type_->name_); + if (this->kind_ == INSTR_HOST || this->kind_ == INSTR_LINK || this->kind_ == INSTR_ROUTER) { + trivaNodeTypes.insert(this->type_->getName()); } } -simgrid::instr::Container::~Container() + +Container::~Container() { XBT_DEBUG("destroy container %s", name_.c_str()); // Begin with destroying my own children @@ -151,35 +156,27 @@ simgrid::instr::Container::~Container() allContainers.erase(name_); } -simgrid::instr::Container* PJ_container_get(const char* name) -{ - container_t ret = PJ_container_get_or_null (name); - if (ret == nullptr){ - THROWF(tracing_error, 1, "container with name %s not found", name); - } - return ret; -} - -simgrid::instr::Container* PJ_container_get_or_null(const char* name) +Container* Container::byNameOrNull(std::string name) { auto cont = allContainers.find(name); return cont == allContainers.end() ? nullptr : cont->second; } -simgrid::instr::Container* PJ_container_get_root() +Container* Container::byName(std::string name) { - return rootContainer; + Container* ret = Container::byNameOrNull(name); + if (ret == nullptr) + THROWF(tracing_error, 1, "container with name %s not found", name.c_str()); + + return ret; } -void PJ_container_remove_from_parent (container_t child) +void Container::removeFromParent() { - if (child == nullptr){ - THROWF (tracing_error, 0, "can't remove from parent with a nullptr child"); - } - - container_t parent = child->father_; - if (parent){ - XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", child->name_.c_str(), parent->name_.c_str()); - parent->children_.erase(child->name_); + if (father_) { + XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", name_.c_str(), father_->name_.c_str()); + father_->children_.erase(name_); } } +} +}