Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
77715de3501497445cbb5f00aa259efa66b745e7
[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_ = nullptr;
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 Container* byNameOrNull(std::string name);
133   static Container* byName(std::string name);
134   void removeFromParent();
135 };
136
137 //--------------------------------------------------
138 class PajeEvent {
139 protected:
140   Container* container;
141   Type* type;
142
143 public:
144   double timestamp_;
145   e_event_type eventType_;
146   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
147       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
148   virtual void print() = 0;
149   virtual ~PajeEvent();
150   void insertIntoBuffer();
151 };
152
153 //--------------------------------------------------
154 class SetVariableEvent : public PajeEvent {
155   double value;
156
157 public:
158   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
159   void print() override;
160 };
161
162 class AddVariableEvent : public PajeEvent {
163   double value;
164
165 public:
166   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
167   void print() override;
168 };
169 //--------------------------------------------------
170
171 class SubVariableEvent : public PajeEvent {
172   double value;
173
174 public:
175   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
176   void print() override;
177 };
178 //--------------------------------------------------
179
180 class SetStateEvent : public PajeEvent {
181   Value* value;
182   const char* filename;
183   int linenumber;
184
185 public:
186   SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
187   void print() override;
188 };
189
190 class PushStateEvent : public PajeEvent {
191   Value* value;
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 public:
204   PopStateEvent(double timestamp, Container* container, Type* type);
205   void print() override;
206 };
207
208 class ResetStateEvent : public PajeEvent {
209 public:
210   ResetStateEvent(double timestamp, Container* container, Type* type);
211   void print() override;
212 };
213
214 class StartLinkEvent : public PajeEvent {
215   Container* sourceContainer_;
216   std::string value_;
217   std::string key_;
218   int size_;
219
220 public:
221   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
222                  std::string key);
223   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
224                  std::string key, int size);
225   void print() override;
226 };
227
228 class EndLinkEvent : public PajeEvent {
229   Container* destContainer;
230   std::string value;
231   std::string key;
232
233 public:
234   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
235                std::string key);
236   ~EndLinkEvent() = default;
237   void print() override;
238 };
239
240 class NewEvent : public PajeEvent {
241   Value* val;
242
243 public:
244   NewEvent(double timestamp, Container* container, Type* type, Value* val);
245   void print() override;
246 };
247 }
248 } // namespace simgrid::instr
249 typedef simgrid::instr::Container* container_t;
250
251 extern "C" {
252
253 extern XBT_PRIVATE std::set<std::string> created_categories;
254 extern XBT_PRIVATE std::set<std::string> declared_marks;
255 extern XBT_PRIVATE std::set<std::string> user_host_variables;
256 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
257 extern XBT_PRIVATE std::set<std::string> user_link_variables;
258 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
259
260 /* instr_paje_header.c */
261 XBT_PRIVATE void TRACE_header(int basic, int size);
262
263 /* from paje.c */
264 XBT_PRIVATE void TRACE_paje_start();
265 XBT_PRIVATE void TRACE_paje_end();
266 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
267
268 /* from instr_config.c */
269 XBT_PRIVATE bool TRACE_needs_platform();
270 XBT_PRIVATE bool TRACE_is_enabled();
271 XBT_PRIVATE bool TRACE_platform();
272 XBT_PRIVATE bool TRACE_platform_topology();
273 XBT_PRIVATE bool TRACE_is_configured();
274 XBT_PRIVATE bool TRACE_categorized();
275 XBT_PRIVATE bool TRACE_uncategorized();
276 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
277 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
278 XBT_PRIVATE bool TRACE_buffer();
279 XBT_PRIVATE bool TRACE_disable_link();
280 XBT_PRIVATE bool TRACE_disable_speed();
281 XBT_PRIVATE bool TRACE_onelink_only();
282 XBT_PRIVATE bool TRACE_disable_destroy();
283 XBT_PRIVATE bool TRACE_basic();
284 XBT_PRIVATE bool TRACE_display_sizes();
285 XBT_PRIVATE char* TRACE_get_comment();
286 XBT_PRIVATE char* TRACE_get_comment_file();
287 XBT_PRIVATE int TRACE_precision();
288 XBT_PRIVATE char* TRACE_get_filename();
289 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
290 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
291 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
292 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
293 XBT_PRIVATE void instr_pause_tracing();
294 XBT_PRIVATE void instr_resume_tracing();
295
296 /* Public functions used in SMPI */
297 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
298 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
299 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
300 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
301 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
302
303 /* from resource_utilization.c */
304 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
305                                                  double delta);
306 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
307                                                  double delta);
308 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
309
310 /* instr_paje.c */
311 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
312 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
313 XBT_PRIVATE long long int instr_new_paje_id();
314 XBT_PUBLIC(container_t) PJ_container_get_root ();
315 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
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