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()
21 Type::Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father)
22 : name_(name), color_(color), kind_(kind), father_(father)
24 if (name.empty() || key == nullptr) {
25 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
28 id_ = std::to_string(instr_new_paje_id());
30 if (father != nullptr){
31 father->children_.insert({key, this});
32 XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname());
38 for (auto elm : values_) {
39 XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->getCname());
42 for (auto elm : children_) {
47 Type* Type::byName(std::string name)
49 Type* ret = this->getChildOrNull(name);
51 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname());
55 Type* Type::getChildOrNull(std::string name)
57 xbt_assert(not name.empty(), "can't get type with a nullptr name");
60 for (auto elm : children_) {
61 if (elm.second->name_ == name) {
63 THROWF (tracing_error, 0, "there are two children types with the same name?");
72 Type* simgrid::instr::Type::containerNew(const char* name, Type* father)
75 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
78 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, father);
79 if (father == nullptr) {
82 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(),
84 LogContainerTypeDefinition(ret);
89 Type* Type::eventNew(const char* name, 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->getCname(), ret->getId(), father->getCname(), father->getId());
97 LogDefineEventType(ret);
101 Type* Type::variableNew(const char* name, std::string color, Type* father)
103 if (name == nullptr){
104 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
110 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
111 ret = new Type (name, name, white, TYPE_VARIABLE, father);
113 ret = new Type (name, name, color, TYPE_VARIABLE, father);
115 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
116 LogVariableTypeDefinition (ret);
120 Type* Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
122 if (name == nullptr){
123 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
126 char key[INSTR_DEFAULT_STR_SIZE];
127 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->getId(), dest->getId());
128 Type* ret = new Type(name, key, "", TYPE_LINK, father);
129 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->getCname(), ret->getId(), father->getCname(),
130 father->getId(), source->getCname(), source->getId(), dest->getCname(), dest->getId());
131 LogLinkTypeDefinition(ret, source, dest);
135 Type* Type::stateNew(const char* name, Type* father)
137 if (name == nullptr){
138 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
141 Type* ret = new Type(name, name, "", TYPE_STATE, father);
142 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
143 LogStateTypeDefinition(ret);