Logo AND Algorithmique Numérique Distribuée

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