Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused typedefs.
[simgrid.git] / src / instr / instr_paje_types.cpp
1 /* Copyright (c) 2012, 2014-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "src/instr/instr_private.hpp"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
10
11 extern FILE* tracing_file;
12
13 namespace simgrid {
14 namespace instr {
15
16 Type::Type(std::string name, std::string alias, std::string color, Type* father)
17     : id_(instr_new_paje_id()), name_(name), color_(color), father_(father)
18 {
19   if (name.empty() || alias.empty())
20     THROWF(tracing_error, 0, "can't create a new type with no name or alias");
21
22   if (father != nullptr){
23     father->children_.insert({alias, this});
24     XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname());
25   }
26 }
27
28 Type::~Type()
29 {
30   for (auto elm : children_)
31     delete elm.second;
32 }
33
34 ValueType::~ValueType()
35 {
36   for (auto elm : values_)
37     delete elm.second;
38 }
39
40 ContainerType::ContainerType(std::string name, Type* father) : Type(name, name, "", father)
41 {
42   XBT_DEBUG("ContainerType %s(%lld), child of %s(%lld)", getCname(), getId(), father->getCname(), father->getId());
43   logDefinition(PAJE_DefineContainerType);
44 }
45
46 EventType::EventType(std::string name, Type* father) : ValueType(name, father)
47 {
48   XBT_DEBUG("EventType %s(%lld), child of %s(%lld)", getCname(), getId(), father->getCname(), father->getId());
49   logDefinition(PAJE_DefineEventType);
50 }
51
52 StateType::StateType(std::string name, Type* father) : ValueType(name, father)
53 {
54   XBT_DEBUG("StateType %s(%lld), child of %s(%lld)", getCname(), getId(), father->getCname(), father->getId());
55   logDefinition(PAJE_DefineStateType);
56 }
57
58 StateType::~StateType()
59 {
60   events_.clear();
61 }
62
63 void StateType::setEvent(std::string value_name)
64 {
65   events_.push_back(new StateEvent(issuer_, this, PAJE_SetState, getEntityValue(value_name)));
66 }
67
68 void StateType::pushEvent(std::string value_name, TIData* extra)
69 {
70   events_.push_back(new StateEvent(issuer_, this, PAJE_PushState, getEntityValue(value_name), extra));
71 }
72
73 void StateType::pushEvent(std::string value_name)
74 {
75   events_.push_back(new StateEvent(issuer_, this, PAJE_PushState, getEntityValue(value_name)));
76 }
77
78 void StateType::popEvent()
79 {
80   events_.push_back(new StateEvent(issuer_, this, PAJE_PopState, nullptr));
81 }
82
83 VariableType::VariableType(std::string name, std::string color, Type* father) : Type(name, name, color, father)
84 {
85   XBT_DEBUG("VariableType %s(%lld), child of %s(%lld)", getCname(), getId(), father->getCname(), father->getId());
86   logDefinition(PAJE_DefineVariableType);
87 }
88
89 VariableType::~VariableType()
90 {
91   events_.clear();
92 }
93
94 void VariableType::setEvent(double timestamp, double value)
95 {
96   events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_SetVariable, value));
97 }
98
99 void VariableType::addEvent(double timestamp, double value)
100 {
101   events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_AddVariable, value));
102 }
103
104 void VariableType::subEvent(double timestamp, double value)
105 {
106   events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_SubVariable, value));
107 }
108
109 LinkType::LinkType(std::string name, std::string alias, Type* father) : ValueType(name, alias, father)
110 {
111 }
112 void LinkType::startEvent(container_t startContainer, std::string value, std::string key)
113 {
114   startEvent(startContainer, value, key, -1);
115 }
116
117 void LinkType::startEvent(container_t startContainer, std::string value, std::string key, int size)
118 {
119   new LinkEvent(issuer_, this, PAJE_StartLink, startContainer, value, key, size);
120 }
121
122 void LinkType::endEvent(container_t endContainer, std::string value, std::string key)
123 {
124   new LinkEvent(issuer_, this, PAJE_EndLink, endContainer, value, key);
125 }
126
127 void Type::logDefinition(e_event_type event_type)
128 {
129   if (instr_fmt_type != instr_fmt_paje)
130     return;
131   std::stringstream stream;
132   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, event_type, TRACE_precision(), 0.);
133   stream << std::fixed << std::setprecision(TRACE_precision()) << event_type << " " << getId();
134   stream << " " << father_->getId() << " " << getName();
135   if (isColored())
136     stream << " \"" << color_ << "\"";
137   XBT_DEBUG("Dump %s", stream.str().c_str());
138   stream << std::endl;
139   fprintf(tracing_file, "%s", stream.str().c_str());
140 }
141
142 void Type::logDefinition(simgrid::instr::Type* source, simgrid::instr::Type* dest)
143 {
144   if (instr_fmt_type != instr_fmt_paje)
145     return;
146   std::stringstream stream;
147   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
148   stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_DefineLinkType << " " << getId();
149   stream << " " << father_->getId() << " " << source->getId() << " " << dest->getId() << " " << getName();
150   XBT_DEBUG("Dump %s", stream.str().c_str());
151   stream << std::endl;
152   fprintf(tracing_file, "%s", stream.str().c_str());
153 }
154
155 Type* Type::byName(std::string name)
156 {
157   Type* ret = nullptr;
158   for (auto elm : children_) {
159     if (elm.second->name_ == name) {
160       if (ret != nullptr) {
161         THROWF (tracing_error, 0, "there are two children types with the same name?");
162       } else {
163         ret = elm.second;
164       }
165     }
166   }
167   if (ret == nullptr)
168     THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname());
169   return ret;
170 }
171
172 void ValueType::addEntityValue(std::string name)
173 {
174   addEntityValue(name, "");
175 }
176
177 void ValueType::addEntityValue(std::string name, std::string color)
178 {
179   if (name.empty())
180     THROWF(tracing_error, 0, "can't get a value with no name");
181
182   auto it = values_.find(name);
183   if (it == values_.end()) {
184     EntityValue* new_val = new EntityValue(name, color, this);
185     values_.insert({name, new_val});
186     XBT_DEBUG("new value %s, child of %s", name.c_str(), getCname());
187     new_val->print();
188   }
189 }
190
191 EntityValue* ValueType::getEntityValue(std::string name)
192 {
193   auto ret = values_.find(name);
194   if (ret == values_.end()) {
195     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), getCname());
196   }
197   return ret->second;
198 }
199
200 ContainerType* Type::getOrCreateContainerType(std::string name)
201 {
202   auto cont = children_.find(name);
203   return cont == children_.end() ? new ContainerType(name, this) : static_cast<ContainerType*>(cont->second);
204 }
205
206 EventType* Type::getOrCreateEventType(std::string name)
207 {
208   auto cont = children_.find(name);
209   return cont == children_.end() ? new EventType(name, this) : static_cast<EventType*>(cont->second);
210 }
211
212 StateType* Type::getOrCreateStateType(std::string name)
213 {
214   auto cont = children_.find(name);
215   return cont == children_.end() ? new StateType(name, this) : static_cast<StateType*>(cont->second);
216 }
217
218 VariableType* Type::getOrCreateVariableType(std::string name, std::string color)
219 {
220   auto cont = children_.find(name);
221   std::string mycolor = color.empty() ? "1 1 1" : color;
222   return cont == children_.end() ? new VariableType(name, mycolor, this) : static_cast<VariableType*>(cont->second);
223 }
224
225 LinkType* Type::getOrCreateLinkType(std::string name, Type* source, Type* dest)
226 {
227   std::string alias = name + "-" + std::to_string(source->id_) + "-" + std::to_string(dest->id_);
228   auto it           = children_.find(alias);
229   if (it == children_.end()) {
230     LinkType* ret = new LinkType(name, alias, this);
231     XBT_DEBUG("LinkType %s(%lld), child of %s(%lld)  %s(%lld)->%s(%lld)", ret->getCname(), ret->getId(), getCname(),
232               getId(), source->getCname(), source->getId(), dest->getCname(), dest->getId());
233     ret->logDefinition(source, dest);
234     return ret;
235   } else
236     return static_cast<LinkType*>(it->second);
237 }
238 }
239 }