Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b158f63d2d60c0d9dbaf082b954795e875ec5419
[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 protected:
131   Container* container;
132   Type* type;
133
134 public:
135   double timestamp_;
136   e_event_type eventType_;
137   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
138       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
139   virtual void print() = 0;
140   virtual ~PajeEvent();
141 };
142
143 //--------------------------------------------------
144 class SetVariableEvent : public PajeEvent {
145   double value;
146
147 public:
148   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
149   void print() override;
150 };
151
152 class AddVariableEvent : public PajeEvent {
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   double value;
163
164 public:
165   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
166   void print() override;
167 };
168 //--------------------------------------------------
169
170 class SetStateEvent : public PajeEvent {
171   Value* value;
172   const char* filename;
173   int linenumber;
174
175 public:
176   SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
177   void print() override;
178 };
179
180 class PushStateEvent : public PajeEvent {
181   Value* value;
182   const char* filename;
183   int linenumber;
184   void* extra_;
185
186 public:
187   PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
188   PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
189   void print() override;
190 };
191
192 class PopStateEvent : public PajeEvent {
193 public:
194   PopStateEvent(double timestamp, Container* container, Type* type);
195   void print() override;
196 };
197
198 class ResetStateEvent : public PajeEvent {
199 public:
200   ResetStateEvent(double timestamp, Container* container, Type* type);
201   void print() override;
202 };
203
204 class StartLinkEvent : public PajeEvent {
205   Container* sourceContainer_;
206   std::string value_;
207   std::string key_;
208   int size_;
209
210 public:
211   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
212                  const char* key);
213   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
214                  const char* key, int size);
215   void print() override;
216 };
217
218 class EndLinkEvent : public PajeEvent {
219   Container* destContainer;
220   std::string value;
221   std::string key;
222
223 public:
224   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
225                std::string key);
226   ~EndLinkEvent() = default;
227   void print() override;
228 };
229
230 class NewEvent : public PajeEvent {
231   Value* val;
232
233 public:
234   NewEvent(double timestamp, Container* container, Type* type, Value* val);
235   void print() override;
236 };
237 }
238 } // namespace simgrid::instr
239 typedef simgrid::instr::Container* container_t;
240
241 extern "C" {
242
243 extern XBT_PRIVATE std::set<std::string> created_categories;
244 extern XBT_PRIVATE std::set<std::string> declared_marks;
245 extern XBT_PRIVATE std::set<std::string> user_host_variables;
246 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
247 extern XBT_PRIVATE std::set<std::string> user_link_variables;
248 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
249
250 /* instr_paje_header.c */
251 XBT_PRIVATE void TRACE_header(int basic, int size);
252
253 /* from paje.c */
254 XBT_PRIVATE void TRACE_paje_start();
255 XBT_PRIVATE void TRACE_paje_end();
256 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
257
258 /* from instr_config.c */
259 XBT_PRIVATE bool TRACE_needs_platform();
260 XBT_PRIVATE bool TRACE_is_enabled();
261 XBT_PRIVATE bool TRACE_platform();
262 XBT_PRIVATE bool TRACE_platform_topology();
263 XBT_PRIVATE bool TRACE_is_configured();
264 XBT_PRIVATE bool TRACE_categorized();
265 XBT_PRIVATE bool TRACE_uncategorized();
266 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
267 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
268 XBT_PRIVATE bool TRACE_buffer();
269 XBT_PRIVATE bool TRACE_disable_link();
270 XBT_PRIVATE bool TRACE_disable_speed();
271 XBT_PRIVATE bool TRACE_onelink_only();
272 XBT_PRIVATE bool TRACE_disable_destroy();
273 XBT_PRIVATE bool TRACE_basic();
274 XBT_PRIVATE bool TRACE_display_sizes();
275 XBT_PRIVATE char* TRACE_get_comment();
276 XBT_PRIVATE char* TRACE_get_comment_file();
277 XBT_PRIVATE int TRACE_precision();
278 XBT_PRIVATE char* TRACE_get_filename();
279 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
280 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
281 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
282 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
283 XBT_PRIVATE void instr_pause_tracing();
284 XBT_PRIVATE void instr_resume_tracing();
285
286 /* Public functions used in SMPI */
287 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
288 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
289 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
290 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
291 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
292
293 /* from resource_utilization.c */
294 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
295                                                  double delta);
296 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
297                                                  double delta);
298 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
299
300 /* instr_paje.c */
301 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
302 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
303 XBT_PRIVATE long long int instr_new_paje_id();
304 XBT_PUBLIC(container_t) PJ_container_get(const char* name);
305 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
306 XBT_PUBLIC(container_t) PJ_container_get_root ();
307 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
308 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
309
310 /* instr_paje_types.c */
311 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
312
313 /* instr_config.c */
314 XBT_PRIVATE void TRACE_TI_start();
315 XBT_PRIVATE void TRACE_TI_end();
316
317 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
318 XBT_PRIVATE void dump_comment_file(const char* filename);
319 XBT_PRIVATE void dump_comment(const char* comment);
320
321 struct s_instr_extra_data;
322 typedef struct s_instr_extra_data* instr_extra_data;
323
324 typedef enum {
325   TRACING_INIT,
326   TRACING_FINALIZE,
327   TRACING_COMM_SIZE,
328   TRACING_COMM_SPLIT,
329   TRACING_COMM_DUP,
330   TRACING_SEND,
331   TRACING_ISEND,
332   TRACING_SSEND,
333   TRACING_ISSEND,
334   TRACING_RECV,
335   TRACING_IRECV,
336   TRACING_SENDRECV,
337   TRACING_TEST,
338   TRACING_WAIT,
339   TRACING_WAITALL,
340   TRACING_WAITANY,
341   TRACING_BARRIER,
342   TRACING_BCAST,
343   TRACING_REDUCE,
344   TRACING_ALLREDUCE,
345   TRACING_ALLTOALL,
346   TRACING_ALLTOALLV,
347   TRACING_GATHER,
348   TRACING_GATHERV,
349   TRACING_SCATTER,
350   TRACING_SCATTERV,
351   TRACING_ALLGATHER,
352   TRACING_ALLGATHERV,
353   TRACING_REDUCE_SCATTER,
354   TRACING_COMPUTING,
355   TRACING_SLEEPING,
356   TRACING_SCAN,
357   TRACING_EXSCAN
358 } e_caller_type;
359
360 typedef struct s_instr_extra_data {
361   e_caller_type type;
362   int send_size;
363   int recv_size;
364   double comp_size;
365   double sleep_duration;
366   int src;
367   int dst;
368   int root;
369   const char* datatype1;
370   const char* datatype2;
371   int* sendcounts;
372   int* recvcounts;
373   int num_processes;
374 } s_instr_extra_data_t;
375
376 /* Format of TRACING output.
377  *   - paje is the regular format, that we all know
378  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
379  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
380  *     using the signal that we will create to cleanup the TRACING
381  */
382 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
383 extern instr_fmt_type_t instr_fmt_type;
384 }
385
386 void LogContainerTypeDefinition(simgrid::instr::Type* type);
387 void LogVariableTypeDefinition(simgrid::instr::Type* type);
388 void LogStateTypeDefinition(simgrid::instr::Type* type);
389 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
390 void LogContainerCreation(container_t container);
391 void LogContainerDestruction(container_t container);
392 void LogDefineEventType(simgrid::instr::Type* type);
393
394 #endif