Logo AND Algorithmique Numérique Distribuée

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