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,
26 if (typeNameBuff == nullptr || key == nullptr){
27 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
30 this->name_ = xbt_strdup(typeNameBuff);
31 this->father_ = father;
33 this->children_ = xbt_dict_new_homogeneous(nullptr);
34 this->values_ = xbt_dict_new_homogeneous(nullptr);
35 this->color_ = xbt_strdup(color);
37 char str_id[INSTR_DEFAULT_STR_SIZE];
38 snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
39 this->id_ = xbt_strdup(str_id);
41 if (father != nullptr){
42 xbt_dict_set(father->children_, key, this, nullptr);
43 XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_);
47 void PJ_type_free(simgrid::instr::Type* type)
49 simgrid::instr::Value* val;
51 xbt_dict_cursor_t cursor = nullptr;
52 xbt_dict_foreach (type->values_, cursor, value_name, val) {
53 XBT_DEBUG("free value %s, child of %s", val->name_, val->father_->name_);
56 xbt_dict_free(&type->values_);
57 xbt_free(type->name_);
59 xbt_free(type->color_);
60 xbt_dict_free(&type->children_);
65 void recursiveDestroyType(simgrid::instr::Type* type)
67 XBT_DEBUG("recursiveDestroyType %s", type->name_);
68 xbt_dict_cursor_t cursor = nullptr;
69 simgrid::instr::Type* child;
71 xbt_dict_foreach (type->children_, cursor, child_name, child) {
72 recursiveDestroyType (child);
77 simgrid::instr::Type* PJ_type_get(const char* name, simgrid::instr::Type* father)
79 simgrid::instr::Type* ret = simgrid::instr::Type::getOrNull(name, father);
81 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name_);
86 simgrid::instr::Type* simgrid::instr::Type::getOrNull(const char* name, simgrid::instr::Type* father)
88 if (name == nullptr || father == nullptr){
89 THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
92 simgrid::instr::Type* ret = nullptr;
93 simgrid::instr::Type* child;
95 xbt_dict_cursor_t cursor = nullptr;
96 xbt_dict_foreach (father->children_, cursor, child_name, child) {
97 if (strcmp(child->name_, name) == 0) {
99 THROWF (tracing_error, 0, "there are two children types with the same name?");
108 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
110 if (name == nullptr){
111 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
114 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, nullptr, TYPE_CONTAINER, father);
115 if (father == nullptr) {
118 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
119 DefineContainerEvent(ret);
124 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
126 if (name == nullptr){
127 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
130 Type* ret = new Type (name, name, nullptr, TYPE_EVENT, father);
131 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
132 LogDefineEventType(ret);
136 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, const char* color,
137 simgrid::instr::Type* father)
139 if (name == nullptr){
140 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
146 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
147 ret = new Type (name, name, white, TYPE_VARIABLE, father);
149 ret = new Type (name, name, color, TYPE_VARIABLE, father);
151 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
152 LogVariableTypeDefinition (ret);
156 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
158 if (name == nullptr){
159 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
164 char key[INSTR_DEFAULT_STR_SIZE];
165 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_);
166 ret = new Type (name, key, nullptr, TYPE_LINK, father);
167 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_,
168 source->name_, source->id_, dest->name_, dest->id_);
169 LogLinkTypeDefinition(ret, source, dest);
173 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
175 if (name == nullptr){
176 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
181 ret = new Type (name, name, nullptr, TYPE_STATE, father);
182 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
183 LogStateTypeDefinition(ret);