From 585eeb393ae78877bab30573f224a2171074a6ca Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 12 Oct 2017 11:47:36 +0200 Subject: [PATCH] more stringification/privatization --- src/instr/instr_paje_containers.cpp | 2 +- src/instr/instr_paje_trace.cpp | 38 +++++++++++----------- src/instr/instr_paje_types.cpp | 41 +++++++++++------------- src/instr/instr_paje_values.cpp | 6 ++-- src/instr/instr_private.hpp | 16 +++++---- src/instr/instr_resource_utilization.cpp | 2 +- src/surf/instr_routing.cpp | 18 +++++------ 7 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index fe6615676b..32b40bfce8 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -125,7 +125,7 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain //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_); + trivaNodeTypes.insert(this->type_->getName()); } } simgrid::instr::Container::~Container() diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index eb8b257db3..81f33e6940 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -200,7 +200,7 @@ void LogContainerTypeDefinition(simgrid::instr::Type* type) TRACE_precision(), 0.); stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineContainerType; - stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_; + stream << " " << type->getId() << " " << type->father_->getId() << " " << type->getName(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -219,7 +219,7 @@ void LogVariableTypeDefinition(simgrid::instr::Type* type) TRACE_precision(), 0.); stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineVariableType; - stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_; + stream << " " << type->getId() << " " << type->father_->getId() << " " << type->getName(); if (type->isColored()) stream << " \"" << type->color_ << "\""; print_row(); @@ -238,7 +238,7 @@ if (instr_fmt_type == instr_fmt_paje) { 0.); stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineStateType; - stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_; + stream << " " << type->getId() << " " << type->father_->getId() << " " << type->getName(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -255,7 +255,7 @@ void LogDefineEventType(simgrid::instr::Type* type) TRACE_precision(), 0.); stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineEventType; - stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_; + stream << " " << type->getId() << " " << type->father_->getId() << " " << type->getName(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -273,8 +273,8 @@ if (instr_fmt_type == instr_fmt_paje) { 0.); stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineLinkType; - stream << " " << type->id_ << " " << type->father_->id_ << " " << source->id_ << " " << dest->id_ << " " - << type->name_; + stream << " " << type->getId() << " " << type->father_->getId() << " " << source->getId() << " " << dest->getId() + << " " << type->getName(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -290,7 +290,7 @@ void simgrid::instr::Value::print() if (instr_fmt_type == instr_fmt_paje) { stream << std::fixed << std::setprecision(TRACE_precision()); stream << simgrid::instr::PAJE_DefineEntityValue; - stream << " " << id_ << " " << father_->id_ << " " << name_; + stream << " " << id_ << " " << father_->getId() << " " << name_; if (isColored()) stream << " \"" << color_ << "\""; print_row(); @@ -316,7 +316,7 @@ void LogContainerCreation (container_t container) stream << 0; else stream << timestamp; - stream << " " << container->id_ << " " << container->type_->id_ << " " << container->father_->id_ << " \"" + stream << " " << container->id_ << " " << container->type_->getId() << " " << container->father_->id_ << " \"" << container->name_ << "\""; print_row(); @@ -366,7 +366,7 @@ void LogContainerDestruction(container_t container) stream << 0; else stream << timestamp; - stream << " " << container->type_->id_ << " " << container->id_; + stream << " " << container->type_->getId() << " " << container->id_; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || tracing_files.size() == 1) { @@ -393,7 +393,7 @@ void simgrid::instr::SetVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->id_ << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -417,7 +417,7 @@ void simgrid::instr::AddVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->id_ << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -440,7 +440,7 @@ void simgrid::instr::SubVariableEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->id_ << " " << value; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -471,7 +471,7 @@ void simgrid::instr::SetStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_; + stream << " " << type->getId() << " " << container->id_; stream << " " << value->getId(); #if HAVE_SMPI if (xbt_cfg_get_boolean("smpi/trace-call-location")) { @@ -513,7 +513,7 @@ void simgrid::instr::PushStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_; + stream << " " << type->getId() << " " << container->id_; stream << " " << value->getId(); if (TRACE_display_sizes()) { @@ -686,7 +686,7 @@ void simgrid::instr::PopStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_; + stream << " " << type->getId() << " " << container->id_; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -710,7 +710,7 @@ void simgrid::instr::ResetStateEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_; + stream << " " << type->getId() << " " << container->id_; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ @@ -744,7 +744,7 @@ void simgrid::instr::StartLinkEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value_; + stream << " " << type->getId() << " " << container->id_ << " " << value_; stream << " " << sourceContainer_->id_ << " " << key_; if (TRACE_display_sizes()) { @@ -776,7 +776,7 @@ void simgrid::instr::EndLinkEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value; + stream << " " << type->getId() << " " << container->id_ << " " << value; stream << " " << destContainer->id_ << " " << key; print_row(); } else if (instr_fmt_type == instr_fmt_TI) { @@ -803,7 +803,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->getId(); + stream << " " << type->getId() << " " << container->id_ << " " << val->getId(); print_row(); } else if (instr_fmt_type == instr_fmt_TI) { /* Nothing to do */ diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index abc3104466..711a8a6e1c 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -15,51 +15,47 @@ simgrid::instr::Type* PJ_type_get_root() return rootType; } -simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, std::string color, e_entity_types kind, - Type* father) - : color_(color), kind_(kind), father_(father) +simgrid::instr::Type::Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father) + : name_(name), color_(color), kind_(kind), father_(father) { - if (typeNameBuff == nullptr || key == nullptr){ + if (name.empty() || key == nullptr) { THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr"); } - this->name_ = xbt_strdup(typeNameBuff); - this->id_ = bprintf("%lld", instr_new_paje_id()); + this->id_ = std::to_string(instr_new_paje_id()); if (father != nullptr){ father->children_.insert({key, this}); - XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_); + XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname()); } } simgrid::instr::Type::~Type() { for (auto elm : values_) { - XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->name_); + XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->getCname()); delete elm.second; } for (auto elm : children_) { delete elm.second; } - xbt_free(name_); - xbt_free(id_); } -simgrid::instr::Type* simgrid::instr::Type::getChild(const char* name) +simgrid::instr::Type* simgrid::instr::Type::getChild(std::string name) { simgrid::instr::Type* ret = this->getChildOrNull(name); if (ret == nullptr) - THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, this->name_); + THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname()); return ret; } -simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(const char* name) +simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(std::string name) { - xbt_assert(name != nullptr, "can't get type with a nullptr name"); + xbt_assert(not name.empty(), "can't get type with a nullptr name"); simgrid::instr::Type* ret = nullptr; for (auto elm : children_) { - if (strcmp(elm.second->name_, name) == 0) { + if (elm.second->name_ == name) { if (ret != nullptr) { THROWF (tracing_error, 0, "there are two children types with the same name?"); } else { @@ -80,7 +76,8 @@ simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgr if (father == nullptr) { rootType = ret; } else { - XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_); + XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), + father->getId()); LogContainerTypeDefinition(ret); } return ret; @@ -93,7 +90,7 @@ simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid:: } Type* ret = new Type(name, name, "", TYPE_EVENT, father); - XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_); + XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId()); LogDefineEventType(ret); return ret; } @@ -113,7 +110,7 @@ simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, std::s }else{ ret = new Type (name, name, color, TYPE_VARIABLE, father); } - XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_); + XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId()); LogVariableTypeDefinition (ret); return ret; } @@ -125,10 +122,10 @@ simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* fath } char key[INSTR_DEFAULT_STR_SIZE]; - snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_); + snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->getId(), dest->getId()); Type* ret = new Type(name, key, "", TYPE_LINK, father); - XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_, - source->name_, source->id_, dest->name_, dest->id_); + XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->getCname(), ret->getId(), father->getCname(), + father->getId(), source->getCname(), source->getId(), dest->getCname(), dest->getId()); LogLinkTypeDefinition(ret, source, dest); return ret; } @@ -140,7 +137,7 @@ simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* fat } Type* ret = new Type(name, name, "", TYPE_STATE, father); - XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_); + XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId()); LogStateTypeDefinition(ret); return ret; } diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 2c66f147ce..4d77238d68 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -19,7 +19,7 @@ simgrid::instr::Value::Value(std::string name, std::string color, simgrid::instr 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_->name_); + XBT_DEBUG("new value %s, child of %s", name_.c_str(), father_->getCname()); print(); }; @@ -42,10 +42,10 @@ simgrid::instr::Value* simgrid::instr::Value::byName(std::string name, Type* fat } if (father->kind_ == TYPE_VARIABLE) - THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_); + 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->name_); + 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 2af3f1825b..af513ac141 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -58,31 +58,33 @@ enum e_entity_types { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE //-------------------------------------------------- class Type { + std::string id_; + std::string name_; + public: - char* id_; - char* name_; std::string color_; - e_entity_types kind_; Type* father_; std::map children_; std::map values_; // valid for all types except variable and container - Type(const char* typeNameBuff, const char* key, std::string color, e_entity_types kind, Type* father); + Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father); ~Type(); - Type* getChild(const char* name); - Type* getChildOrNull(const char* name); + Type* getChild(std::string name); + Type* getChildOrNull(std::string name); static Type* containerNew(const char* name, Type* father); static Type* eventNew(const char* name, Type* father); static Type* variableNew(const char* name, std::string color, Type* father); static Type* linkNew(const char* name, Type* father, Type* source, Type* dest); static Type* stateNew(const char* name, Type* father); + std::string getName() { return name_; } + const char* getCname() { return name_.c_str(); } + const char* getId() { return id_.c_str(); } bool isColored() { return not color_.empty(); } }; //-------------------------------------------------- class Value { -private: std::string name_; std::string id_; std::string color_; diff --git a/src/instr/instr_resource_utilization.cpp b/src/instr/instr_resource_utilization.cpp index e4d8d9d204..c8b025245b 100644 --- a/src/instr/instr_resource_utilization.cpp +++ b/src/instr/instr_resource_utilization.cpp @@ -36,7 +36,7 @@ static void __TRACE_surf_check_variable_set_to_zero(double now, const char* vari static void instr_event(double now, double delta, simgrid::instr::Type* variable, container_t resource, double value) { - __TRACE_surf_check_variable_set_to_zero(now, variable->name_, resource->name_); + __TRACE_surf_check_variable_set_to_zero(now, variable->getCname(), resource->name_); new simgrid::instr::AddVariableEvent(now, resource, variable, value); new simgrid::instr::SubVariableEvent(now + delta, resource, variable, value); } diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index ba7a057fdf..4766523bae 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -97,14 +97,14 @@ static void linkContainers(container_t src, container_t dst, std::settype_->name_, src->type_->name_, - src->type_->id_, dst->type_->name_, dst->type_->id_); + snprintf(link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s", father->type_->getCname(), src->type_->getCname(), + src->type_->getId(), dst->type_->getCname(), dst->type_->getId()); simgrid::instr::Type* link_type = father->type_->getChildOrNull(link_typename); if (link_type == nullptr) link_type = simgrid::instr::Type::linkNew(link_typename, father->type_, src->type_, dst->type_); //register EDGE types for triva configuration - trivaEdgeTypes.insert(link_type->name_); + trivaEdgeTypes.insert(link_type->getName()); //create the link static long long counter = 0; @@ -325,17 +325,17 @@ void instr_routing_define_callbacks () static void recursiveNewVariableType(const char* new_typename, const char* color, simgrid::instr::Type* root) { - if (not strcmp(root->name_, "HOST")) { + if (root->getName() == "HOST") { char tnstr[INSTR_DEFAULT_STR_SIZE]; snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename); simgrid::instr::Type::variableNew(tnstr, color == nullptr ? "" : color, root); } - if (not strcmp(root->name_, "MSG_VM")) { + if (root->getName() == "MSG_VM") { char tnstr[INSTR_DEFAULT_STR_SIZE]; snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename); simgrid::instr::Type::variableNew(tnstr, color == nullptr ? "" : color, root); } - if (not strcmp(root->name_, "LINK")) { + if (root->getName() == "LINK") { char tnstr[INSTR_DEFAULT_STR_SIZE]; snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename); simgrid::instr::Type::variableNew(tnstr, color == nullptr ? "" : color, root); @@ -353,7 +353,7 @@ void instr_new_variable_type (const char *new_typename, const char *color) static void recursiveNewUserVariableType(const char* father_type, const char* new_typename, const char* color, simgrid::instr::Type* root) { - if (not strcmp(root->name_, father_type)) { + if (root->getName() == father_type) { simgrid::instr::Type::variableNew(new_typename, color == nullptr ? "" : color, root); } for (auto elm : root->children_) @@ -367,7 +367,7 @@ void instr_new_user_variable_type (const char *father_type, const char *new_typ static void recursiveNewUserStateType(const char* father_type, const char* new_typename, simgrid::instr::Type* root) { - if (not strcmp(root->name_, father_type)) { + if (root->getName() == father_type) { simgrid::instr::Type::stateNew(new_typename, root); } for (auto elm : root->children_) @@ -382,7 +382,7 @@ void instr_new_user_state_type (const char *father_type, const char *new_typenam static void recursiveNewValueForUserStateType(const char* type_name, const char* val, const char* color, simgrid::instr::Type* root) { - if (not strcmp(root->name_, type_name)) + if (root->getName() == type_name) simgrid::instr::Value::byNameOrCreate(val, color, root); for (auto elm : root->children_) -- 2.20.1