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;
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)
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 ||
}
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
// 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);
}
allContainers.erase(name_);
// free
- xbt_free(name_);
- xbt_free(id_);
- xbt_dict_free(&children_);
}
simgrid::instr::Container* PJ_container_get(const char* name)
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_);
}
}
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;
}
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
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);
#include "simgrid/instr.h"
#include "simgrid_config.h"
#include "src/internal_config.h"
+#include <map>
#include <set>
#include <string>
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<std::string, Container*> children_;
};
//--------------------------------------------------
static std::unordered_map<std::string, std::string> 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
*/
// 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("");
static void linkContainers(container_t src, container_t dst, std::set<std::string>* 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;
}
}
// check if we already register this pair (we only need one direction)
- std::string aux1 = std::string(src->name_) + 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;
}
new simgrid::instr::StartLinkEvent(SIMIX_get_clock(), father, link_type, src, "topology", key);
new simgrid::instr::EndLinkEvent(SIMIX_get_clock(), father, link_type, dst, "topology", key);
- XBT_DEBUG(" linkContainers %s <-> %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,
if (not netzone->getChildren()->empty()) {
//bottom-up recursion
for (auto const& nz_son : *netzone->getChildren()) {
- container_t child_container = static_cast<container_t>(xbt_dict_get(container->children_, nz_son->getCname()));
+ container_t child_container = container->children_.at(nz_son->getCname());
recursiveGraphExtraction(nz_son, child_container, filter);
}
}
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)
if (not netzone->getChildren()->empty()) {
//bottom-up recursion
for (auto const& netzone_child : *netzone->getChildren()) {
- container_t child_container =
- static_cast<container_t>(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);
}
}