Logo AND Algorithmique Numérique Distribuée

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