Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stringify and objectify instr::Value (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 <map>
16 #include <set>
17 #include <string>
18
19 /* Need to define function drand48 for Windows */
20 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
21 #ifdef _WIN32
22 #define drand48() (rand() / (RAND_MAX + 1.0))
23 #endif
24
25 #define INSTR_DEFAULT_STR_SIZE 500
26
27 #include "xbt/dict.h"
28 #include "xbt/graph.h"
29
30 namespace simgrid {
31 namespace instr {
32 typedef enum {
33   PAJE_DefineContainerType,
34   PAJE_DefineVariableType,
35   PAJE_DefineStateType,
36   PAJE_DefineEventType,
37   PAJE_DefineLinkType,
38   PAJE_DefineEntityValue,
39   PAJE_CreateContainer,
40   PAJE_DestroyContainer,
41   PAJE_SetVariable,
42   PAJE_AddVariable,
43   PAJE_SubVariable,
44   PAJE_SetState,
45   PAJE_PushState,
46   PAJE_PopState,
47   PAJE_ResetState,
48   PAJE_StartLink,
49   PAJE_EndLink,
50   PAJE_NewEvent
51 } e_event_type;
52
53 typedef enum { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE_EVENT } e_entity_types;
54
55 //--------------------------------------------------
56
57 class Type {
58 public:
59   char* id_;
60   char* name_;
61   char* color_;
62
63   e_entity_types kind_;
64   Type* father_;
65   xbt_dict_t children_;
66   xbt_dict_t values_; // valid for all types except variable and container
67   Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind, Type* father);
68   ~Type();
69   Type* getChild(const char* name);
70   Type* getChildOrNull(const char* name);
71
72   static Type* containerNew(const char* name, Type* father);
73   static Type* eventNew(const char* name, Type* father);
74   static Type* variableNew(const char* name, const char* color, Type* father);
75   static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
76   static Type* stateNew(const char* name, Type* father);
77 };
78
79 //--------------------------------------------------
80 class Value {
81 private:
82   std::string name_;
83   std::string id_;
84   std::string color_;
85
86   explicit Value(std::string name, std::string color, Type* father);
87
88 public:
89   ~Value() = default;
90   Type* father_;
91   static Value* byNameOrCreate(std::string name, std::string color, Type* father);
92   static Value* byName(std::string name, Type* father);
93   const char* getCname() { return name_.c_str(); }
94   const char* getId() { return id_.c_str(); }
95   bool isColored() { return not color_.empty(); }
96   void print();
97 };
98
99 //--------------------------------------------------
100 typedef enum {
101   INSTR_HOST,
102   INSTR_LINK,
103   INSTR_ROUTER,
104   INSTR_AS,
105   INSTR_SMPI,
106   INSTR_MSG_VM,
107   INSTR_MSG_PROCESS,
108   INSTR_MSG_TASK
109 } e_container_types;
110
111 //--------------------------------------------------
112
113 class Container {
114 public:
115   Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
116   virtual ~Container();
117
118   sg_netpoint_t netpoint_;
119   std::string name_;       /* Unique name of this container */
120   std::string id_;         /* Unique id of this container */
121   Type* type_;             /* Type of this container */
122   int level_ = 0;          /* Level in the hierarchy, root level is 0 */
123   e_container_types kind_; /* This container is of what kind */
124   Container* father_;
125   std::map<std::string, Container*> children_;
126 };
127
128 //--------------------------------------------------
129 class PajeEvent {
130 public:
131   double timestamp_;
132   e_event_type eventType_;
133   virtual void print() = 0;
134   virtual ~PajeEvent();
135 };
136
137 //--------------------------------------------------
138 class SetVariableEvent : public PajeEvent {
139 private:
140   Container* container;
141   Type* type;
142   double value;
143
144 public:
145   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
146   void print() override;
147 };
148
149 class AddVariableEvent : public PajeEvent {
150 private:
151   Container* container;
152   Type* type;
153   double value;
154
155 public:
156   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
157   void print() override;
158 };
159 //--------------------------------------------------
160
161 class SubVariableEvent : public PajeEvent {
162 private:
163   Container* container;
164   Type* type;
165   double value;
166
167 public:
168   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
169   void print() override;
170 };
171 //--------------------------------------------------
172
173 class SetStateEvent : public PajeEvent {
174 private:
175   Container* container;
176   Type* type;
177   Value* value;
178   const char* filename;
179   int linenumber;
180
181 public:
182   SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
183   void print() override;
184 };
185
186 class PushStateEvent : public PajeEvent {
187 public:
188   Container* container;
189   Type* type;
190   Value* value;
191   int size;
192   const char* filename;
193   int linenumber;
194   void* extra_;
195
196 public:
197   PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
198   PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
199   void print() override;
200 };
201
202 class PopStateEvent : public PajeEvent {
203   Container* container;
204   Type* type;
205
206 public:
207   PopStateEvent(double timestamp, Container* container, Type* type);
208   void print() override;
209 };
210
211 class ResetStateEvent : public PajeEvent {
212   Container* container;
213   Type* type;
214
215 public:
216   ResetStateEvent(double timestamp, Container* container, Type* type);
217   void print() override;
218 };
219
220 class StartLinkEvent : public PajeEvent {
221   Container* container_;
222   Type* type_;
223   Container* sourceContainer_;
224   std::string value_;
225   std::string key_;
226   int size_;
227
228 public:
229   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
230                  const char* key);
231   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
232                  const char* key, int size);
233   void print() override;
234 };
235
236 class EndLinkEvent : public PajeEvent {
237   Container* container;
238   Type* type;
239   Container* destContainer;
240   std::string value;
241   std::string key;
242
243 public:
244   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
245                std::string key);
246   ~EndLinkEvent() = default;
247   void print() override;
248 };
249
250 class NewEvent : public PajeEvent {
251 public:
252   Container* container;
253   Type* type;
254   Value* val;
255
256 public:
257   NewEvent(double timestamp, Container* container, Type* type, Value* val);
258   void print() override;
259 };
260 }
261 } // namespace simgrid::instr
262 typedef simgrid::instr::Container* container_t;
263
264 extern "C" {
265
266 extern XBT_PRIVATE std::set<std::string> created_categories;
267 extern XBT_PRIVATE std::set<std::string> declared_marks;
268 extern XBT_PRIVATE std::set<std::string> user_host_variables;
269 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
270 extern XBT_PRIVATE std::set<std::string> user_link_variables;
271 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
272
273 /* instr_paje_header.c */
274 XBT_PRIVATE void TRACE_header(int basic, int size);
275
276 /* from paje.c */
277 XBT_PRIVATE void TRACE_paje_start();
278 XBT_PRIVATE void TRACE_paje_end();
279 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
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(const char* name);
328 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
329 XBT_PUBLIC(container_t) PJ_container_get_root ();
330 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
331 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
332
333 /* instr_paje_types.c */
334 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
335
336 /* instr_config.c */
337 XBT_PRIVATE void TRACE_TI_start();
338 XBT_PRIVATE void TRACE_TI_end();
339
340 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
341 XBT_PRIVATE void dump_comment_file(const char* filename);
342 XBT_PRIVATE void dump_comment(const char* comment);
343
344 struct s_instr_extra_data;
345 typedef struct s_instr_extra_data* instr_extra_data;
346
347 typedef enum {
348   TRACING_INIT,
349   TRACING_FINALIZE,
350   TRACING_COMM_SIZE,
351   TRACING_COMM_SPLIT,
352   TRACING_COMM_DUP,
353   TRACING_SEND,
354   TRACING_ISEND,
355   TRACING_SSEND,
356   TRACING_ISSEND,
357   TRACING_RECV,
358   TRACING_IRECV,
359   TRACING_SENDRECV,
360   TRACING_TEST,
361   TRACING_WAIT,
362   TRACING_WAITALL,
363   TRACING_WAITANY,
364   TRACING_BARRIER,
365   TRACING_BCAST,
366   TRACING_REDUCE,
367   TRACING_ALLREDUCE,
368   TRACING_ALLTOALL,
369   TRACING_ALLTOALLV,
370   TRACING_GATHER,
371   TRACING_GATHERV,
372   TRACING_SCATTER,
373   TRACING_SCATTERV,
374   TRACING_ALLGATHER,
375   TRACING_ALLGATHERV,
376   TRACING_REDUCE_SCATTER,
377   TRACING_COMPUTING,
378   TRACING_SLEEPING,
379   TRACING_SCAN,
380   TRACING_EXSCAN
381 } e_caller_type;
382
383 typedef struct s_instr_extra_data {
384   e_caller_type type;
385   int send_size;
386   int recv_size;
387   double comp_size;
388   double sleep_duration;
389   int src;
390   int dst;
391   int root;
392   const char* datatype1;
393   const char* datatype2;
394   int* sendcounts;
395   int* recvcounts;
396   int num_processes;
397 } s_instr_extra_data_t;
398
399 /* Format of TRACING output.
400  *   - paje is the regular format, that we all know
401  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
402  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
403  *     using the signal that we will create to cleanup the TRACING
404  */
405 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
406 extern instr_fmt_type_t instr_fmt_type;
407 }
408
409 void LogContainerTypeDefinition(simgrid::instr::Type* type);
410 void LogVariableTypeDefinition(simgrid::instr::Type* type);
411 void LogStateTypeDefinition(simgrid::instr::Type* type);
412 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
413 void LogContainerCreation(container_t container);
414 void LogContainerDestruction(container_t container);
415 void LogDefineEventType(simgrid::instr::Type* type);
416
417 #endif