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_);
64 void recursiveDestroyType(simgrid::instr::Type* type)
66 XBT_DEBUG("recursiveDestroyType %s", type->name_);
67 xbt_dict_cursor_t cursor = nullptr;
68 simgrid::instr::Type* child;
70 xbt_dict_foreach (type->children_, cursor, child_name, child) {
71 recursiveDestroyType (child);
76 simgrid::instr::Type* PJ_type_get(const char* name, simgrid::instr::Type* father)
78 simgrid::instr::Type* ret = simgrid::instr::Type::getOrNull(name, father);
80 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name_);
85 simgrid::instr::Type* simgrid::instr::Type::getOrNull(const char* name, simgrid::instr::Type* father)
87 if (name == nullptr || father == nullptr){
88 THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
91 simgrid::instr::Type* ret = nullptr;
92 simgrid::instr::Type* child;
94 xbt_dict_cursor_t cursor = nullptr;
95 xbt_dict_foreach (father->children_, cursor, child_name, child) {
96 if (strcmp(child->name_, name) == 0) {
98 THROWF (tracing_error, 0, "there are two children types with the same name?");
107 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
109 if (name == nullptr){
110 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
113 simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, nullptr, TYPE_CONTAINER, father);
114 if (father == nullptr) {
117 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
118 LogContainerTypeDefinition(ret);
123 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
125 if (name == nullptr){
126 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
129 Type* ret = new Type (name, name, nullptr, TYPE_EVENT, father);
130 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
131 LogDefineEventType(ret);
135 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, const char* color,
136 simgrid::instr::Type* father)
138 if (name == nullptr){
139 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
145 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
146 ret = new Type (name, name, white, TYPE_VARIABLE, father);
148 ret = new Type (name, name, color, TYPE_VARIABLE, father);
150 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
151 LogVariableTypeDefinition (ret);
155 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
157 if (name == nullptr){
158 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
163 char key[INSTR_DEFAULT_STR_SIZE];
164 snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_);
165 ret = new Type (name, key, nullptr, TYPE_LINK, father);
166 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_,
167 source->name_, source->id_, dest->name_, dest->id_);
168 LogLinkTypeDefinition(ret, source, dest);
172 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
174 if (name == nullptr){
175 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
180 ret = new Type (name, name, nullptr, TYPE_STATE, father);
181 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
182 LogStateTypeDefinition(ret);