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.h"
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 void PJ_type_release ()
18 simgrid::instr::Type* PJ_type_get_root()
23 simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind,
25 : kind_(kind), father_(father)
27 if (typeNameBuff == nullptr || key == nullptr){
28 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
31 this->name_ = xbt_strdup(typeNameBuff);
32 this->children_ = xbt_dict_new_homogeneous(nullptr);
33 this->values_ = xbt_dict_new_homogeneous(nullptr);
34 this->color_ = xbt_strdup(color);
36 char str_id[INSTR_DEFAULT_STR_SIZE];
37 snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
38 this->id_ = xbt_strdup(str_id);
40 if (father != nullptr){
41 xbt_dict_set(father->children_, key, this, nullptr);
42 XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_);
46 void PJ_type_free(simgrid::instr::Type* type)
48 simgrid::instr::Value* val;
50 xbt_dict_cursor_t cursor = nullptr;
51 xbt_dict_foreach (type->values_, cursor, value_name, val) {
52 XBT_DEBUG("free value %s, child of %s", val->name_, val->father_->name_);
55 xbt_dict_free(&type->values_);
56 xbt_free(type->name_);
58 xbt_free(type->color_);
59 xbt_dict_free(&type->children_);
63 void recursiveDestroyType(simgrid::instr::Type* type)
65 XBT_DEBUG("recursiveDestroyType %s", type->name_);
66 xbt_dict_cursor_t cursor = nullptr;
67 simgrid::instr::Type* child;
69 xbt_dict_foreach (type->children_, cursor, child_name, child) {
70 recursiveDestroyType (child);
75 simgrid::instr::Type* PJ_type_get(const char* name, simgrid::instr::Type* father)
77 simgrid::instr::Type* ret = simgrid::instr::Type::getOrNull(name, father);
79 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name_);
84 simgrid::instr::Type* simgrid::instr::Type::getOrNull(const char* name, simgrid::instr::Type* father)
86 if (name == nullptr || father == nullptr){
87 THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
90 simgrid::instr::Type* ret = nullptr;
91 simgrid::instr::Type* child;
93 xbt_dict_cursor_t cursor = nullptr;
94 xbt_dict_foreach (father->children_, cursor, child_name, child) {
95 if (strcmp(child->name_, name) == 0) {
97 THROWF (tracing_error, 0, "there are two children types with the same name?");
106 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
108 if (name == nullptr){
109 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
112 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, nullptr, TYPE_CONTAINER, father);
113 if (father == nullptr) {
116 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
117 LogContainerTypeDefinition(ret);
122 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
124 if (name == nullptr){
125 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
128 Type* ret = new Type (name, name, nullptr, TYPE_EVENT, father);
129 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
130 LogDefineEventType(ret);
134 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, const char* color,
135 simgrid::instr::Type* father)
137 if (name == nullptr){
138 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
144 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
145 ret = new Type (name, name, white, TYPE_VARIABLE, father);
147 ret = new Type (name, name, color, TYPE_VARIABLE, father);
149 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
150 LogVariableTypeDefinition (ret);
154 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
156 if (name == nullptr){
157 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
160 char key[INSTR_DEFAULT_STR_SIZE];
161 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_);
162 Type* ret = new Type(name, key, nullptr, TYPE_LINK, father);
163 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_,
164 source->name_, source->id_, dest->name_, dest->id_);
165 LogLinkTypeDefinition(ret, source, dest);
169 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
171 if (name == nullptr){
172 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
175 Type* ret = new Type(name, name, nullptr, TYPE_STATE, father);
176 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
177 LogStateTypeDefinition(ret);