Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanup plugging a memleak
[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   static Type* getOrNull(const char* name, Type* father);
73   static Type* containerNew(const char* name, Type* father);
74   static Type* eventNew(const char* name, Type* father);
75   static Type* variableNew(const char* name, const char* color, Type* father);
76   static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
77   static Type* stateNew(const char* name, Type* father);
78 };
79
80 //--------------------------------------------------
81 class Value {
82 public:
83   char* id_;
84   char* name_;
85   char* color_;
86
87   Type* father_;
88   Value(const char* name, const char* color, Type* father);
89   ~Value();
90   static Value* get_or_new(const char* name, const char* color, Type* father);
91   static Value* get(const char* name, Type* father);
92 };
93
94
95 //--------------------------------------------------
96 typedef enum {
97   INSTR_HOST,
98   INSTR_LINK,
99   INSTR_ROUTER,
100   INSTR_AS,
101   INSTR_SMPI,
102   INSTR_MSG_VM,
103   INSTR_MSG_PROCESS,
104   INSTR_MSG_TASK
105 } e_container_types;
106
107 //--------------------------------------------------
108
109 class Container {
110 public:
111   Container(const char* name, simgrid::instr::e_container_types kind, Container* father);
112   virtual ~Container();
113
114   sg_netpoint_t netpoint_;
115   char* name_;             /* Unique name of this container */
116   char* id_;               /* Unique id of this container */
117   Type* type_;             /* Type of this container */
118   int level_ = 0;          /* Level in the hierarchy, root level is 0 */
119   e_container_types kind_; /* This container is of what kind */
120   Container* father_;
121   xbt_dict_t children_;
122 };
123
124 //--------------------------------------------------
125 class PajeEvent {
126   public:
127     double timestamp_;
128     e_event_type eventType_;
129     virtual void print() = 0;
130     virtual ~PajeEvent();
131 };
132
133 //--------------------------------------------------
134 class SetVariableEvent : public PajeEvent  {
135   private:
136     Container* container;
137     Type* type;
138     double value;
139
140   public:
141     SetVariableEvent(double timestamp, Container* container, Type* type, double value);
142     void print() override;
143 };
144
145 class AddVariableEvent:public PajeEvent {
146   private:
147     Container* container;
148     Type* type;
149     double value;
150
151   public:
152     AddVariableEvent(double timestamp, Container* container, Type* type, double value);
153     void print() override;
154 };
155 //--------------------------------------------------
156
157
158 class SubVariableEvent : public PajeEvent  {
159   private:
160     Container* container;
161     Type* type;
162     double value;
163
164   public:
165     SubVariableEvent(double timestamp, Container* container, Type* type, double value);
166     void print() override;
167 };
168 //--------------------------------------------------
169
170 class SetStateEvent : public PajeEvent  {
171   private:
172     Container* container;
173     Type* type;
174     Value* val;
175     const char* filename;
176     int linenumber;
177
178   public:
179     SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
180     void print() override;
181 };
182
183
184 class PushStateEvent : public PajeEvent  {
185   public:
186     Container* container;
187     Type* type;
188     Value* val;
189     int size;
190     const char* filename;
191     int linenumber;
192     void* extra_;
193
194   public:
195     PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
196     PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
197     void print() override;
198 };
199
200 class PopStateEvent : public PajeEvent  {
201   Container* container;
202   Type* type;
203
204 public:
205   PopStateEvent(double timestamp, Container* container, Type* type);
206   void print() override;
207 };
208
209 class ResetStateEvent : public PajeEvent  {
210   Container* container;
211   Type* type;
212
213 public:
214   ResetStateEvent(double timestamp, Container* container, Type* type);
215   void print() override;
216 };
217
218 class StartLinkEvent : public PajeEvent  {
219   public:
220     Container* container;
221     Type* type;
222     Container* sourceContainer;
223     char* value;
224     char* key;
225     int size;
226
227   public:
228     ~StartLinkEvent();
229     StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
230                    const char* key);
231     StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
232                    const char* key, int size);
233     void print() override;
234 };
235
236 class EndLinkEvent : public PajeEvent  {
237   Container* container;
238   Type* type;
239   Container* destContainer;
240   char *value;
241   char *key;
242   public:
243     EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, const char* value,
244                  const char* key);
245     ~EndLinkEvent();
246     void print() override;
247 };
248
249
250 class NewEvent : public PajeEvent  {
251   public:
252     Container* container;
253     Type* type;
254     Value* val;
255
256   public:
257     NewEvent(double timestamp, Container* container, Type* type, Value* val);
258     void print() override;
259 };
260 }
261 } // namespace simgrid::instr
262 typedef simgrid::instr::Container* container_t;
263
264 SG_BEGIN_DECL()
265
266 extern XBT_PRIVATE std::set<std::string> created_categories;
267 extern XBT_PRIVATE std::set<std::string> declared_marks;
268 extern XBT_PRIVATE std::set<std::string> user_host_variables;
269 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
270 extern XBT_PRIVATE std::set<std::string> user_link_variables;
271 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
272
273 /* instr_paje_header.c */
274 XBT_PRIVATE void TRACE_header(int basic, int size);
275
276 /* from paje.c */
277 XBT_PRIVATE void TRACE_paje_start();
278 XBT_PRIVATE void TRACE_paje_end();
279 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
280
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 (const char *name);
329 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
330 XBT_PUBLIC(container_t) PJ_container_get_root ();
331 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
332 XBT_PUBLIC(void) PJ_container_free_all (void);
333 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
334
335 /* instr_paje_types.c */
336 XBT_PRIVATE void PJ_type_release ();
337 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
338 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get(const char* name, simgrid::instr::Type* father);
339 XBT_PRIVATE XBT_PRIVATE void PJ_type_free(simgrid::instr::Type* type);
340
341 /* instr_config.c */
342 XBT_PRIVATE void recursiveDestroyType(simgrid::instr::Type* type);
343
344 XBT_PRIVATE void TRACE_TI_start();
345 XBT_PRIVATE void TRACE_TI_end();
346
347 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
348 XBT_PRIVATE void dump_comment_file (const char *filename);
349 XBT_PRIVATE void dump_comment (const char *comment);
350
351 struct s_instr_extra_data;
352 typedef struct s_instr_extra_data *instr_extra_data;
353
354 typedef enum{
355   TRACING_INIT,
356   TRACING_FINALIZE,
357   TRACING_COMM_SIZE,
358   TRACING_COMM_SPLIT,
359   TRACING_COMM_DUP,
360   TRACING_SEND,
361   TRACING_ISEND,
362   TRACING_SSEND,
363   TRACING_ISSEND,
364   TRACING_RECV,
365   TRACING_IRECV,
366   TRACING_SENDRECV,
367   TRACING_TEST,
368   TRACING_WAIT,
369   TRACING_WAITALL,
370   TRACING_WAITANY,
371   TRACING_BARRIER,
372   TRACING_BCAST,
373   TRACING_REDUCE,
374   TRACING_ALLREDUCE,
375   TRACING_ALLTOALL,
376   TRACING_ALLTOALLV,
377   TRACING_GATHER,
378   TRACING_GATHERV,
379   TRACING_SCATTER,
380   TRACING_SCATTERV,
381   TRACING_ALLGATHER,
382   TRACING_ALLGATHERV,
383   TRACING_REDUCE_SCATTER,
384   TRACING_COMPUTING,
385   TRACING_SLEEPING,
386   TRACING_SCAN,
387   TRACING_EXSCAN
388 } e_caller_type ;
389
390 typedef struct s_instr_extra_data {
391   e_caller_type type;
392   int send_size;
393   int recv_size;
394   double comp_size;
395   double sleep_duration;
396   int src;
397   int dst;
398   int root;
399   const char* datatype1;
400   const char* datatype2;
401   int * sendcounts;
402   int * recvcounts;
403   int num_processes;
404 } s_instr_extra_data_t;
405
406 /* Format of TRACING output.
407  *   - paje is the regular format, that we all know
408  *   - 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.
409  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
410  */
411 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
412 extern instr_fmt_type_t instr_fmt_type;
413
414 SG_END_DECL()
415
416 void LogContainerTypeDefinition(simgrid::instr::Type* type);
417 void LogVariableTypeDefinition(simgrid::instr::Type* type);
418 void LogStateTypeDefinition(simgrid::instr::Type* type);
419 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
420 void LogEntityValue(simgrid::instr::Value* val);
421 void LogContainerCreation (container_t container);
422 void LogContainerDestruction (container_t container);
423 void LogDefineEventType(simgrid::instr::Type* type);
424
425 #endif