Logo AND Algorithmique Numérique Distribuée

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