From: Frederic Suter Date: Mon, 9 Oct 2017 15:25:46 +0000 (+0200) Subject: sloppy replacement of dict by map and char* by string X-Git-Tag: v3.18~510 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4bff2cd38194b0f95d7a0d19867f7e4e19e8a328 sloppy replacement of dict by map and char* by string some tesh files have to be revalidated as the order in which the destruction of containers is logged has changed. --- diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 821217c3d0..32966ff879 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -31,28 +31,26 @@ void PJ_container_set_root (container_t root) rootContainer = root; } -simgrid::instr::Container::Container(const char* name, simgrid::instr::e_container_types kind, Container* father) - : name_(xbt_strdup(name)), kind_(kind), father_(father) +simgrid::instr::Container::Container(std::string name, simgrid::instr::e_container_types kind, Container* father) + : name_(name), kind_(kind), father_(father) { - xbt_assert(name != nullptr, "Container name cannot be nullptr"); - static long long int container_id = 0; - id_ = bprintf("%lld", container_id); // id (or alias) of the container + id_ = std::to_string(container_id); // id (or alias) of the container container_id++; //Search for network_element_t switch (kind){ case simgrid::instr::INSTR_HOST: - this->netpoint_ = sg_host_by_name(name)->pimpl_netpoint; - xbt_assert(this->netpoint_, "Element '%s' not found", name); + 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: this->netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); - xbt_assert(this->netpoint_, "Element '%s' not found", name); + xbt_assert(this->netpoint_, "Element '%s' not found", name.c_str()); break; case simgrid::instr::INSTR_AS: this->netpoint_ = simgrid::s4u::Engine::getInstance()->getNetpointByNameOrNull(name); - xbt_assert(this->netpoint_, "Element '%s' not found", name); + xbt_assert(this->netpoint_, "Element '%s' not found", name.c_str()); break; default: this->netpoint_ = nullptr; @@ -61,7 +59,7 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain if (father_) { this->level_ = father_->level_ + 1; - XBT_DEBUG("new container %s, child of %s", name, father->name_); + XBT_DEBUG("new container %s, child of %s", name.c_str(), father->name_.c_str()); } // type definition (method depends on kind of this new container) @@ -113,18 +111,17 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain this->type_ = type; } } - this->children_ = xbt_dict_new_homogeneous(nullptr); if (this->father_) { - xbt_dict_set(this->father_->children_, this->name_, this, nullptr); + this->father_->children_.insert({this->name_, this}); LogContainerCreation(this); } //register all kinds by name if (not allContainers.emplace(this->name_, this).second) { - THROWF(tracing_error, 1, "container %s already present in allContainers data structure", this->name_); + THROWF(tracing_error, 1, "container %s already present in allContainers data structure", this->name_.c_str()); } - XBT_DEBUG("Add container name '%s'", this->name_); + 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 || @@ -134,7 +131,7 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain } simgrid::instr::Container::~Container() { - XBT_DEBUG("destroy container %s", name_); + XBT_DEBUG("destroy container %s", name_.c_str()); // obligation to dump previous events because they might // reference the container that is about to be destroyed @@ -143,8 +140,7 @@ simgrid::instr::Container::~Container() // trace my destruction if (not TRACE_disable_destroy() && this != PJ_container_get_root()) { - // do not trace the container destruction if user requests - // or if the container is root + // do not trace the container destruction if user requests or if the container is root LogContainerDestruction(this); } @@ -152,9 +148,6 @@ simgrid::instr::Container::~Container() allContainers.erase(name_); // free - xbt_free(name_); - xbt_free(id_); - xbt_dict_free(&children_); } simgrid::instr::Container* PJ_container_get(const char* name) @@ -185,8 +178,8 @@ void PJ_container_remove_from_parent (container_t child) container_t parent = child->father_; if (parent){ - XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", child->name_, parent->name_); - xbt_dict_remove(parent->children_, child->name_); + XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", child->name_.c_str(), parent->name_.c_str()); + parent->children_.erase(child->name_); } } @@ -195,12 +188,9 @@ static void recursiveDestroyContainer (container_t container) if (container == nullptr){ THROWF (tracing_error, 0, "trying to recursively destroy a nullptr container"); } - XBT_DEBUG("recursiveDestroyContainer %s", container->name_); - xbt_dict_cursor_t cursor = nullptr; - container_t child; - char *child_name; - xbt_dict_foreach (container->children_, cursor, child_name, child) { - recursiveDestroyContainer (child); + XBT_DEBUG("recursiveDestroyContainer %s", container->name_.c_str()); + for (auto child : container->children_) { + recursiveDestroyContainer(child.second); } delete container; } diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index e057d6cc4a..29c3588c53 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -333,7 +333,7 @@ void LogContainerCreation (container_t container) if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) { char* folder_name = bprintf("%s_files", TRACE_get_filename()); - char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name_); + char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name_.c_str()); #ifdef WIN32 _mkdir(folder_name); #else @@ -566,10 +566,10 @@ void simgrid::instr::PushStateEvent::print() char* process_id = nullptr; // FIXME: dirty extract "rank-" from the name, as we want the bare process id here - if (strstr(container->name_, "rank-") == nullptr) - process_id = xbt_strdup(container->name_); + if (strstr(container->name_.c_str(), "rank-") == nullptr) + process_id = xbt_strdup(container->name_.c_str()); else - process_id = xbt_strdup(container->name_ + 5); + process_id = xbt_strdup(container->name_.c_str() + 5); FILE* trace_file = tracing_files.at(container); diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index 57e131c3a4..81ce04afdd 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -12,6 +12,7 @@ #include "simgrid/instr.h" #include "simgrid_config.h" #include "src/internal_config.h" +#include #include #include @@ -112,17 +113,17 @@ typedef enum { class Container { public: - Container(const char* name, simgrid::instr::e_container_types kind, Container* father); + Container(std::string name, simgrid::instr::e_container_types kind, Container* father); virtual ~Container(); sg_netpoint_t netpoint_; - char* name_; /* Unique name of this container */ - char* id_; /* Unique id of this container */ + std::string name_; /* Unique name of this container */ + std::string id_; /* Unique id of this container */ Type* type_; /* Type of this container */ int level_ = 0; /* Level in the hierarchy, root level is 0 */ e_container_types kind_; /* This container is of what kind */ Container* father_; - xbt_dict_t children_; + std::map children_; }; //-------------------------------------------------- diff --git a/src/instr/instr_resource_utilization.cpp b/src/instr/instr_resource_utilization.cpp index 6b7bfec6fe..374f569f3a 100644 --- a/src/instr/instr_resource_utilization.cpp +++ b/src/instr/instr_resource_utilization.cpp @@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorize static std::unordered_map platform_variables; //used by all methods -static void __TRACE_surf_check_variable_set_to_zero(double now, const char *variable, const char *resource) +static void __TRACE_surf_check_variable_set_to_zero(double now, const char* variable, std::string resource) { /* To trace resource utilization, we use pajeAddVariable and pajeSubVariable only. * The Paje simulator needs a pajeSetVariable in the first place so it knows the initial value of all variables for @@ -23,11 +23,11 @@ static void __TRACE_surf_check_variable_set_to_zero(double now, const char *vari */ // create a key considering the resource and variable - std::string key = std::string(resource) + variable; + std::string key = resource + variable; // check if key exists: if it doesn't, set the variable to zero and mark this in the dict if (platform_variables.find(key) == platform_variables.end()) { - container_t container = PJ_container_get (resource); + container_t container = PJ_container_get(resource.c_str()); simgrid::instr::Type* type = container->type_->getChild(variable); new simgrid::instr::SetVariableEvent(now, container, type, 0); platform_variables[key] = std::string(""); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 8fd4845cec..e5fe65c900 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -68,7 +68,7 @@ static container_t lowestCommonAncestor (container_t a1, container_t a2) static void linkContainers(container_t src, container_t dst, std::set* filter) { //ignore loopback - if (strcmp(src->name_, "__loopback__") == 0 || strcmp(dst->name_, "__loopback__") == 0) { + if (src->name_ == "__loopback__" || dst->name_ == "__loopback__") { XBT_DEBUG (" linkContainers: ignoring loopback link"); return; } @@ -80,14 +80,14 @@ static void linkContainers(container_t src, container_t dst, std::setname_) + dst->name_; - std::string aux2 = std::string(dst->name_) + src->name_; + std::string aux1 = src->name_ + dst->name_; + std::string aux2 = dst->name_ + src->name_; if (filter->find(aux1) != filter->end()) { - XBT_DEBUG(" linkContainers: already registered %s <-> %s (1)", src->name_, dst->name_); + XBT_DEBUG(" linkContainers: already registered %s <-> %s (1)", src->name_.c_str(), dst->name_.c_str()); return; } if (filter->find(aux2) != filter->end()) { - XBT_DEBUG(" linkContainers: already registered %s <-> %s (2)", dst->name_, src->name_); + XBT_DEBUG(" linkContainers: already registered %s <-> %s (2)", dst->name_.c_str(), src->name_.c_str()); return; } @@ -116,7 +116,7 @@ static void linkContainers(container_t src, container_t dst, std::set %s", src->name_, dst->name_); + XBT_DEBUG(" linkContainers %s <-> %s", src->name_.c_str(), dst->name_.c_str()); } static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t container, @@ -130,7 +130,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t if (not netzone->getChildren()->empty()) { //bottom-up recursion for (auto const& nz_son : *netzone->getChildren()) { - container_t child_container = static_cast(xbt_dict_get(container->children_, nz_son->getCname())); + container_t child_container = container->children_.at(nz_son->getCname()); recursiveGraphExtraction(nz_son, child_container, filter); } } @@ -281,7 +281,6 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) simgrid::instr::Type::linkNew("MSG_VM_PROCESS_LINK", PJ_type_get_root(), msg_vm, msg_vm); } } - } static void sg_instr_new_router(simgrid::kernel::routing::NetPoint * netpoint) @@ -423,8 +422,7 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, xbt_dict_t nodes, xbt if (not netzone->getChildren()->empty()) { //bottom-up recursion for (auto const& netzone_child : *netzone->getChildren()) { - container_t child_container = - static_cast(xbt_dict_get(container->children_, netzone_child->getCname())); + container_t child_container = container->children_.at(netzone_child->getCname()); recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child, child_container); } }