Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Apply clang-format on previously renamed files.
[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 public:
82   char* id_;
83   char* name_;
84   char* color_;
85
86   Type* father_;
87   Value(const char* name, const char* color, Type* father);
88   ~Value();
89   static Value* get_or_new(const char* name, const char* color, Type* father);
90   static Value* get(const char* name, Type* father);
91 };
92
93 //--------------------------------------------------
94 typedef enum {
95   INSTR_HOST,
96   INSTR_LINK,
97   INSTR_ROUTER,
98   INSTR_AS,
99   INSTR_SMPI,
100   INSTR_MSG_VM,
101   INSTR_MSG_PROCESS,
102   INSTR_MSG_TASK
103 } e_container_types;
104
105 //--------------------------------------------------
106
107 class Container {
108 public:
109   Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
110   virtual ~Container();
111
112   sg_netpoint_t netpoint_;
113   std::string name_;       /* Unique name of this container */
114   std::string id_;         /* Unique id of this container */
115   Type* type_;             /* Type of this container */
116   int level_ = 0;          /* Level in the hierarchy, root level is 0 */
117   e_container_types kind_; /* This container is of what kind */
118   Container* father_;
119   std::map<std::string, Container*> children_;
120 };
121
122 //--------------------------------------------------
123 class PajeEvent {
124 public:
125   double timestamp_;
126   e_event_type eventType_;
127   virtual void print() = 0;
128   virtual ~PajeEvent();
129 };
130
131 //--------------------------------------------------
132 class SetVariableEvent : public PajeEvent {
133 private:
134   Container* container;
135   Type* type;
136   double value;
137
138 public:
139   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
140   void print() override;
141 };
142
143 class AddVariableEvent : public PajeEvent {
144 private:
145   Container* container;
146   Type* type;
147   double value;
148
149 public:
150   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
151   void print() override;
152 };
153 //--------------------------------------------------
154
155 class SubVariableEvent : public PajeEvent {
156 private:
157   Container* container;
158   Type* type;
159   double value;
160
161 public:
162   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
163   void print() override;
164 };
165 //--------------------------------------------------
166
167 class SetStateEvent : public PajeEvent {
168 private:
169   Container* container;
170   Type* type;
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 public:
182   Container* container;
183   Type* type;
184   Value* value;
185   int size;
186   const char* filename;
187   int linenumber;
188   void* extra_;
189
190 public:
191   PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
192   PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
193   void print() override;
194 };
195
196 class PopStateEvent : public PajeEvent {
197   Container* container;
198   Type* type;
199
200 public:
201   PopStateEvent(double timestamp, Container* container, Type* type);
202   void print() override;
203 };
204
205 class ResetStateEvent : public PajeEvent {
206   Container* container;
207   Type* type;
208
209 public:
210   ResetStateEvent(double timestamp, Container* container, Type* type);
211   void print() override;
212 };
213
214 class StartLinkEvent : public PajeEvent {
215   Container* container_;
216   Type* type_;
217   Container* sourceContainer_;
218   std::string value_;
219   std::string key_;
220   int size_;
221
222 public:
223   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
224                  const char* key);
225   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
226                  const char* key, int size);
227   void print() override;
228 };
229
230 class EndLinkEvent : public PajeEvent {
231   Container* container;
232   Type* type;
233   Container* destContainer;
234   std::string value;
235   std::string key;
236
237 public:
238   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
239                std::string key);
240   ~EndLinkEvent() = default;
241   void print() override;
242 };
243
244 class NewEvent : public PajeEvent {
245 public:
246   Container* container;
247   Type* type;
248   Value* val;
249
250 public:
251   NewEvent(double timestamp, Container* container, Type* type, Value* val);
252   void print() override;
253 };
254 }
255 } // namespace simgrid::instr
256 typedef simgrid::instr::Container* container_t;
257
258 extern "C" {
259
260 extern XBT_PRIVATE std::set<std::string> created_categories;
261 extern XBT_PRIVATE std::set<std::string> declared_marks;
262 extern XBT_PRIVATE std::set<std::string> user_host_variables;
263 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
264 extern XBT_PRIVATE std::set<std::string> user_link_variables;
265 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
266
267 /* instr_paje_header.c */
268 XBT_PRIVATE void TRACE_header(int basic, int size);
269
270 /* from paje.c */
271 XBT_PRIVATE void TRACE_paje_start();
272 XBT_PRIVATE void TRACE_paje_end();
273 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
274
275 /* from instr_config.c */
276 XBT_PRIVATE bool TRACE_needs_platform();
277 XBT_PRIVATE bool TRACE_is_enabled();
278 XBT_PRIVATE bool TRACE_platform();
279 XBT_PRIVATE bool TRACE_platform_topology();
280 XBT_PRIVATE bool TRACE_is_configured();
281 XBT_PRIVATE bool TRACE_categorized();
282 XBT_PRIVATE bool TRACE_uncategorized();
283 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
284 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
285 XBT_PRIVATE bool TRACE_buffer();
286 XBT_PRIVATE bool TRACE_disable_link();
287 XBT_PRIVATE bool TRACE_disable_speed();
288 XBT_PRIVATE bool TRACE_onelink_only();
289 XBT_PRIVATE bool TRACE_disable_destroy();
290 XBT_PRIVATE bool TRACE_basic();
291 XBT_PRIVATE bool TRACE_display_sizes();
292 XBT_PRIVATE char* TRACE_get_comment();
293 XBT_PRIVATE char* TRACE_get_comment_file();
294 XBT_PRIVATE int TRACE_precision();
295 XBT_PRIVATE char* TRACE_get_filename();
296 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
297 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
298 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
299 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
300 XBT_PRIVATE void instr_pause_tracing();
301 XBT_PRIVATE void instr_resume_tracing();
302
303 /* Public functions used in SMPI */
304 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
305 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
306 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
307 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
308 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
309
310 /* from resource_utilization.c */
311 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
312                                                  double delta);
313 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
314                                                  double delta);
315 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
316
317 /* instr_paje.c */
318 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
319 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
320 XBT_PRIVATE long long int instr_new_paje_id();
321 XBT_PUBLIC(container_t) PJ_container_get(const char* name);
322 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
323 XBT_PUBLIC(container_t) PJ_container_get_root ();
324 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
325 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
326
327 /* instr_paje_types.c */
328 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
329
330 /* instr_config.c */
331 XBT_PRIVATE void TRACE_TI_start();
332 XBT_PRIVATE void TRACE_TI_end();
333
334 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
335 XBT_PRIVATE void dump_comment_file(const char* filename);
336 XBT_PRIVATE void dump_comment(const char* comment);
337
338 struct s_instr_extra_data;
339 typedef struct s_instr_extra_data* instr_extra_data;
340
341 typedef enum {
342   TRACING_INIT,
343   TRACING_FINALIZE,
344   TRACING_COMM_SIZE,
345   TRACING_COMM_SPLIT,
346   TRACING_COMM_DUP,
347   TRACING_SEND,
348   TRACING_ISEND,
349   TRACING_SSEND,
350   TRACING_ISSEND,
351   TRACING_RECV,
352   TRACING_IRECV,
353   TRACING_SENDRECV,
354   TRACING_TEST,
355   TRACING_WAIT,
356   TRACING_WAITALL,
357   TRACING_WAITANY,
358   TRACING_BARRIER,
359   TRACING_BCAST,
360   TRACING_REDUCE,
361   TRACING_ALLREDUCE,
362   TRACING_ALLTOALL,
363   TRACING_ALLTOALLV,
364   TRACING_GATHER,
365   TRACING_GATHERV,
366   TRACING_SCATTER,
367   TRACING_SCATTERV,
368   TRACING_ALLGATHER,
369   TRACING_ALLGATHERV,
370   TRACING_REDUCE_SCATTER,
371   TRACING_COMPUTING,
372   TRACING_SLEEPING,
373   TRACING_SCAN,
374   TRACING_EXSCAN
375 } e_caller_type;
376
377 typedef struct s_instr_extra_data {
378   e_caller_type type;
379   int send_size;
380   int recv_size;
381   double comp_size;
382   double sleep_duration;
383   int src;
384   int dst;
385   int root;
386   const char* datatype1;
387   const char* datatype2;
388   int* sendcounts;
389   int* recvcounts;
390   int num_processes;
391 } s_instr_extra_data_t;
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 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
400 extern instr_fmt_type_t instr_fmt_type;
401 }
402
403 void LogContainerTypeDefinition(simgrid::instr::Type* type);
404 void LogVariableTypeDefinition(simgrid::instr::Type* type);
405 void LogStateTypeDefinition(simgrid::instr::Type* type);
406 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
407 void LogEntityValue(simgrid::instr::Value* val);
408 void LogContainerCreation(container_t container);
409 void LogContainerDestruction(container_t container);
410 void LogDefineEventType(simgrid::instr::Type* type);
411
412 #endif