]> AND Public Git Repository - simgrid.git/blob - src/instr/instr_paje_types.cpp
Logo AND Algorithmique Numérique Distribuée

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