Logo AND Algorithmique Numérique Distribuée

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