1 /* Copyright (c) 2012, 2014-2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "src/instr/instr_private.hpp"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
11 static simgrid::instr::Type* rootType = nullptr; /* the root type */
13 simgrid::instr::Type* PJ_type_get_root()
18 simgrid::instr::Type::Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father)
19 : name_(name), color_(color), kind_(kind), father_(father)
21 if (name.empty() || key == nullptr) {
22 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
25 this->id_ = std::to_string(instr_new_paje_id());
27 if (father != nullptr){
28 father->children_.insert({key, this});
29 XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname());
33 simgrid::instr::Type::~Type()
35 for (auto elm : values_) {
36 XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->getCname());
39 for (auto elm : children_) {
44 simgrid::instr::Type* simgrid::instr::Type::getChild(std::string name)
46 simgrid::instr::Type* ret = this->getChildOrNull(name);
48 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname());
52 simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(std::string name)
54 xbt_assert(not name.empty(), "can't get type with a nullptr name");
56 simgrid::instr::Type* ret = nullptr;
57 for (auto elm : children_) {
58 if (elm.second->name_ == name) {
60 THROWF (tracing_error, 0, "there are two children types with the same name?");
69 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
72 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
75 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, father);
76 if (father == nullptr) {
79 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(),
81 LogContainerTypeDefinition(ret);
86 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
89 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
92 Type* ret = new Type(name, name, "", TYPE_EVENT, father);
93 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
94 LogDefineEventType(ret);
98 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, std::string color,
99 simgrid::instr::Type* father)
101 if (name == nullptr){
102 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
108 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
109 ret = new Type (name, name, white, TYPE_VARIABLE, father);
111 ret = new Type (name, name, color, TYPE_VARIABLE, father);
113 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
114 LogVariableTypeDefinition (ret);
118 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
120 if (name == nullptr){
121 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
124 char key[INSTR_DEFAULT_STR_SIZE];
125 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->getId(), dest->getId());
126 Type* ret = new Type(name, key, "", TYPE_LINK, father);
127 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->getCname(), ret->getId(), father->getCname(),
128 father->getId(), source->getCname(), source->getId(), dest->getCname(), dest->getId());
129 LogLinkTypeDefinition(ret, source, dest);
133 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
135 if (name == nullptr){
136 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
139 Type* ret = new Type(name, name, "", TYPE_STATE, father);
140 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
141 LogStateTypeDefinition(ret);