Logo AND Algorithmique Numérique Distribuée

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