Logo AND Algorithmique Numérique Distribuée

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