Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / instr / instr_private.hpp
1 /* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef INSTR_PRIVATE_HPP
7 #define INSTR_PRIVATE_HPP
8
9 #include <xbt/base.h>
10
11 #include "instr/instr_interface.h"
12 #include "simgrid/instr.h"
13 #include "simgrid_config.h"
14 #include "src/internal_config.h"
15 #include "xbt/graph.h"
16 #include <iomanip> /** std::setprecision **/
17 #include <map>
18 #include <set>
19 #include <sstream>
20 #include <string>
21 #include <sys/stat.h>
22 #ifdef WIN32
23 #include <direct.h> // _mkdir
24 /* Need to define function drand48 for Windows */
25 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
26 #define drand48() (rand() / (RAND_MAX + 1.0))
27 #endif
28
29 namespace simgrid {
30 namespace instr {
31
32 class Value;
33
34 enum e_event_type {
35   PAJE_DefineContainerType,
36   PAJE_DefineVariableType,
37   PAJE_DefineStateType,
38   PAJE_DefineEventType,
39   PAJE_DefineLinkType,
40   PAJE_DefineEntityValue,
41   PAJE_CreateContainer,
42   PAJE_DestroyContainer,
43   PAJE_SetVariable,
44   PAJE_AddVariable,
45   PAJE_SubVariable,
46   PAJE_SetState,
47   PAJE_PushState,
48   PAJE_PopState,
49   PAJE_ResetState,
50   PAJE_StartLink,
51   PAJE_EndLink,
52   PAJE_NewEvent
53 };
54
55 //--------------------------------------------------
56 enum e_entity_types { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE_EVENT };
57
58 class Type {
59   std::string id_;
60   std::string name_;
61   std::string color_;
62   e_entity_types kind_;
63   Type* father_;
64
65 public:
66   std::map<std::string, Type*> children_;
67   std::map<std::string, Value*> values_; // valid for all types except variable and container
68
69   Type(std::string name, std::string alias, std::string color, e_entity_types kind, Type* father);
70   ~Type();
71
72   std::string getName() { return name_; }
73   const char* getCname() { return name_.c_str(); }
74   const char* getId() { return id_.c_str(); }
75   e_entity_types getKind() { return kind_; }
76   bool isColored() { return not color_.empty(); }
77
78   Type* byName(std::string name);
79
80   Type* getOrCreateContainerType(std::string name);
81   Type* getOrCreateEventType(std::string name);
82   Type* getOrCreateLinkType(std::string name, Type* source, Type* dest);
83   Type* getOrCreateStateType(std::string name);
84   Type* getOrCreateVariableType(std::string name, std::string color);
85
86   void addEntityValue(std::string name, std::string color);
87   void addEntityValue(std::string name);
88   Value* getEntityValue(std::string name);
89
90   void logContainerTypeDefinition();
91   void logVariableTypeDefinition();
92   void logStateTypeDefinition();
93   void logLinkTypeDefinition(simgrid::instr::Type* source, simgrid::instr::Type* dest);
94   void logDefineEventType();
95
96   static Type* createRootType();
97   static Type* getRootType();
98 };
99
100 class Value {
101   std::string name_;
102   std::string id_;
103   std::string color_;
104   Type* father_;
105
106 public:
107   explicit Value(std::string name, std::string color, Type* father);
108   ~Value();
109   const char* getCname() { return name_.c_str(); }
110   const char* getId() { return id_.c_str(); }
111   bool isColored() { return not color_.empty(); }
112   void print();
113 };
114
115 class Container {
116   long long int id_;
117   std::string name_;       /* Unique name of this container */
118 public:
119   Container(std::string name, std::string type_name, Container* father);
120   virtual ~Container();
121
122   Type* type_;             /* Type of this container */
123   Container* father_;
124   std::map<std::string, Container*> children_;
125   sg_netpoint_t netpoint_ = nullptr;
126
127   static Container* byNameOrNull(std::string name);
128   static Container* byName(std::string name);
129   std::string getName() { return name_; }
130   const char* getCname() { return name_.c_str(); }
131   long long int getId() { return id_; }
132   void removeFromParent();
133   void logCreation();
134   void logDestruction();
135 };
136
137 class NetZoneContainer : public Container {
138 public:
139   NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father);
140 };
141
142 class RouterContainer : public Container {
143 public:
144   RouterContainer(std::string name, Container* father);
145 };
146
147 class HostContainer : public Container {
148 public:
149   HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father);
150 };
151
152 class PajeEvent {
153 protected:
154   Container* container;
155   Type* type;
156
157 public:
158   double timestamp_;
159   e_event_type eventType_;
160   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
161       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
162   virtual void print() = 0;
163   virtual ~PajeEvent();
164   void insertIntoBuffer();
165 };
166
167 //--------------------------------------------------
168 class SetVariableEvent : public PajeEvent {
169   double value;
170
171 public:
172   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
173   void print() override;
174 };
175
176 class AddVariableEvent : public PajeEvent {
177   double value;
178
179 public:
180   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
181   void print() override;
182 };
183 //--------------------------------------------------
184
185 class SubVariableEvent : public PajeEvent {
186   double value;
187
188 public:
189   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
190   void print() override;
191 };
192 //--------------------------------------------------
193
194 class SetStateEvent : public PajeEvent {
195   Value* value;
196   const char* filename;
197   int linenumber;
198
199 public:
200   SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
201   void print() override;
202 };
203
204 class PushStateEvent : public PajeEvent {
205   Value* value;
206   const char* filename;
207   int linenumber;
208   void* extra_;
209
210 public:
211   PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
212   PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
213   void print() override;
214 };
215
216 class PopStateEvent : public PajeEvent {
217 public:
218   PopStateEvent(double timestamp, Container* container, Type* type);
219   void print() override;
220 };
221
222 class ResetStateEvent : public PajeEvent {
223 public:
224   ResetStateEvent(double timestamp, Container* container, Type* type);
225   void print() override;
226 };
227
228 class StartLinkEvent : public PajeEvent {
229   Container* sourceContainer_;
230   std::string value_;
231   std::string key_;
232   int size_;
233
234 public:
235   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
236                  std::string key);
237   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
238                  std::string key, int size);
239   void print() override;
240 };
241
242 class EndLinkEvent : public PajeEvent {
243   Container* destContainer;
244   std::string value;
245   std::string key;
246
247 public:
248   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
249                std::string key);
250   ~EndLinkEvent() = default;
251   void print() override;
252 };
253
254 class NewEvent : public PajeEvent {
255   Value* val;
256
257 public:
258   NewEvent(double timestamp, Container* container, Type* type, Value* val);
259   void print() override;
260 };
261 }
262 } // namespace simgrid::instr
263 typedef simgrid::instr::Container* container_t;
264
265 extern "C" {
266
267 extern XBT_PRIVATE std::set<std::string> created_categories;
268 extern XBT_PRIVATE std::set<std::string> declared_marks;
269 extern XBT_PRIVATE std::set<std::string> user_host_variables;
270 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
271 extern XBT_PRIVATE std::set<std::string> user_link_variables;
272 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
273
274 /* instr_paje_header.c */
275 XBT_PRIVATE void TRACE_header(bool basic, int size);
276
277 /* from paje.c */
278 XBT_PRIVATE void TRACE_paje_start();
279 XBT_PRIVATE void TRACE_paje_end();
280
281 /* from instr_config.c */
282 XBT_PRIVATE bool TRACE_needs_platform();
283 XBT_PRIVATE bool TRACE_is_enabled();
284 XBT_PRIVATE bool TRACE_platform();
285 XBT_PRIVATE bool TRACE_platform_topology();
286 XBT_PRIVATE bool TRACE_is_configured();
287 XBT_PRIVATE bool TRACE_categorized();
288 XBT_PRIVATE bool TRACE_uncategorized();
289 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
290 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
291 XBT_PRIVATE bool TRACE_buffer();
292 XBT_PRIVATE bool TRACE_disable_link();
293 XBT_PRIVATE bool TRACE_disable_speed();
294 XBT_PRIVATE bool TRACE_onelink_only();
295 XBT_PRIVATE bool TRACE_disable_destroy();
296 XBT_PRIVATE bool TRACE_basic();
297 XBT_PRIVATE bool TRACE_display_sizes();
298 XBT_PRIVATE char* TRACE_get_comment();
299 XBT_PRIVATE char* TRACE_get_comment_file();
300 XBT_PRIVATE int TRACE_precision();
301 XBT_PRIVATE char* TRACE_get_filename();
302 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
303 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
304 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
305 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
306 XBT_PRIVATE void instr_pause_tracing();
307 XBT_PRIVATE void instr_resume_tracing();
308
309 /* Public functions used in SMPI */
310 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
311 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
312 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
313 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
314 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
315
316 /* from resource_utilization.c */
317 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
318                                                  double delta);
319 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
320                                                  double delta);
321 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
322
323 /* instr_paje.c */
324 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
325 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
326 XBT_PRIVATE long long int instr_new_paje_id();
327 XBT_PUBLIC(container_t) PJ_container_get_root ();
328 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
329 void instr_new_variable_type(std::string new_typename, std::string color);
330 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
331 void instr_new_user_state_type(std::string father_type, std::string new_typename);
332 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
333
334 /* instr_config.c */
335 XBT_PRIVATE void TRACE_TI_start();
336 XBT_PRIVATE void TRACE_TI_end();
337
338 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
339 XBT_PRIVATE void dump_comment_file(std::string filename);
340 XBT_PRIVATE void dump_comment(std::string comment);
341
342 enum e_caller_type {
343   TRACING_INIT,
344   TRACING_FINALIZE,
345   TRACING_COMM_SIZE,
346   TRACING_COMM_SPLIT,
347   TRACING_COMM_DUP,
348   TRACING_SEND,
349   TRACING_ISEND,
350   TRACING_SSEND,
351   TRACING_ISSEND,
352   TRACING_RECV,
353   TRACING_IRECV,
354   TRACING_SENDRECV,
355   TRACING_TEST,
356   TRACING_WAIT,
357   TRACING_WAITALL,
358   TRACING_WAITANY,
359   TRACING_BARRIER,
360   TRACING_BCAST,
361   TRACING_REDUCE,
362   TRACING_ALLREDUCE,
363   TRACING_ALLTOALL,
364   TRACING_ALLTOALLV,
365   TRACING_GATHER,
366   TRACING_GATHERV,
367   TRACING_SCATTER,
368   TRACING_SCATTERV,
369   TRACING_ALLGATHER,
370   TRACING_ALLGATHERV,
371   TRACING_REDUCE_SCATTER,
372   TRACING_COMPUTING,
373   TRACING_SLEEPING,
374   TRACING_SCAN,
375   TRACING_EXSCAN
376 };
377
378 struct s_instr_extra_data_t {
379   e_caller_type type;
380   int send_size;
381   int recv_size;
382   double comp_size;
383   double sleep_duration;
384   int src;
385   int dst;
386   int root;
387   const char* datatype1;
388   const char* datatype2;
389   int* sendcounts;
390   int* recvcounts;
391   int num_processes;
392 };
393 typedef s_instr_extra_data_t* instr_extra_data;
394
395 /* Format of TRACING output.
396  *   - paje is the regular format, that we all know
397  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
398  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
399  *     using the signal that we will create to cleanup the TRACING
400  */
401 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
402 extern instr_fmt_type_t instr_fmt_type;
403 }
404
405 #endif