Logo AND Algorithmique Numérique Distribuée

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