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(const char* typeNameBuff, const char* key, std::string color, e_entity_types kind,
20 : color_(color), kind_(kind), father_(father)
22 if (typeNameBuff == nullptr || key == nullptr){
23 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
26 this->name_ = xbt_strdup(typeNameBuff);
27 this->id_ = bprintf("%lld", instr_new_paje_id());
29 if (father != nullptr){
30 father->children_.insert({key, this});
31 XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_);
35 simgrid::instr::Type::~Type()
37 for (auto elm : values_) {
38 XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->name_);
41 for (auto elm : children_) {
48 simgrid::instr::Type* simgrid::instr::Type::getChild(const char* name)
50 simgrid::instr::Type* ret = this->getChildOrNull(name);
52 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, this->name_);
56 simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(const char* name)
58 xbt_assert(name != nullptr, "can't get type with a nullptr name");
60 simgrid::instr::Type* ret = nullptr;
61 for (auto elm : children_) {
62 if (strcmp(elm.second->name_, name) == 0) {
64 THROWF (tracing_error, 0, "there are two children types with the same name?");
73 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
76 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
79 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, father);
80 if (father == nullptr) {
83 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
84 LogContainerTypeDefinition(ret);
89 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
92 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
95 Type* ret = new Type(name, name, "", TYPE_EVENT, father);
96 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
97 LogDefineEventType(ret);
101 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, std::string color,
102 simgrid::instr::Type* father)
104 if (name == nullptr){
105 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
111 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
112 ret = new Type (name, name, white, TYPE_VARIABLE, father);
114 ret = new Type (name, name, color, TYPE_VARIABLE, father);
116 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
117 LogVariableTypeDefinition (ret);
121 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
123 if (name == nullptr){
124 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
127 char key[INSTR_DEFAULT_STR_SIZE];
128 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_);
129 Type* ret = new Type(name, key, "", TYPE_LINK, father);
130 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_,
131 source->name_, source->id_, dest->name_, dest->id_);
132 LogLinkTypeDefinition(ret, source, dest);
136 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
138 if (name == nullptr){
139 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
142 Type* ret = new Type(name, name, "", TYPE_STATE, father);
143 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
144 LogStateTypeDefinition(ret);