Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use a proper destructor for the paje::value type
[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 "simgrid/instr.h"
12 #include "instr/instr_interface.h"
13 #include "src/internal_config.h"
14 #include "simgrid_config.h"
15
16 SG_BEGIN_DECL()
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 typedef enum {
30   PAJE_DefineContainerType,
31   PAJE_DefineVariableType,
32   PAJE_DefineStateType,
33   PAJE_DefineEventType,
34   PAJE_DefineLinkType,
35   PAJE_DefineEntityValue,
36   PAJE_CreateContainer,
37   PAJE_DestroyContainer,
38   PAJE_SetVariable,
39   PAJE_AddVariable,
40   PAJE_SubVariable,
41   PAJE_SetState,
42   PAJE_PushState,
43   PAJE_PopState,
44   PAJE_ResetState,
45   PAJE_StartLink,
46   PAJE_EndLink,
47   PAJE_NewEvent
48 } e_event_type;
49
50 typedef enum {
51   TYPE_VARIABLE,
52   TYPE_LINK,
53   TYPE_CONTAINER,
54   TYPE_STATE,
55   TYPE_EVENT
56 } e_entity_types;
57
58 //--------------------------------------------------
59 class s_type;
60 typedef s_type *type_t;
61 class s_type {
62   public:
63   char *id;
64   char *name;
65   char *color;
66   e_entity_types kind;
67   s_type *father;
68   xbt_dict_t children;
69   xbt_dict_t values; //valid for all types except variable and container
70 };
71
72 typedef s_type s_type_t;
73
74 //--------------------------------------------------
75 class value {
76 public:
77   char *id;
78   char *name;
79   char *color;
80   type_t father;
81   value* ret;
82   value(const char* name, const char* color, type_t father);
83   ~value();
84   static value* get_or_new(const char* name, const char* color, type_t father);
85   static value* get(const char* name, type_t father);
86 };
87
88
89 //--------------------------------------------------
90 typedef enum {
91   INSTR_HOST,
92   INSTR_LINK,
93   INSTR_ROUTER,
94   INSTR_AS,
95   INSTR_SMPI,
96   INSTR_MSG_VM,
97   INSTR_MSG_PROCESS,
98   INSTR_MSG_TASK
99 } e_container_types;
100
101 //--------------------------------------------------
102 class s_container;
103 typedef s_container *container_t;
104
105 class s_container {
106   public:
107   sg_netpoint_t netpoint;
108   char *name;     /* Unique name of this container */
109   char *id;       /* Unique id of this container */
110   type_t type;    /* Type of this container */
111   int level;      /* Level in the hierarchy, root level is 0 */
112   e_container_types kind; /* This container is of what kind */
113   s_container *father;
114   xbt_dict_t children;
115 };
116 typedef s_container s_container_t;
117
118 //--------------------------------------------------
119 class PajeEvent {
120   public:
121   double timestamp;
122   e_event_type event_type;
123   virtual void print() = 0;
124   void *data;
125   virtual ~PajeEvent();
126 };
127
128 //--------------------------------------------------
129
130 class DefineVariableTypeEvent : public PajeEvent
131 {
132   public:
133   type_t type;
134    DefineVariableTypeEvent(type_t type);
135    void print() override;
136 };
137 //--------------------------------------------------
138
139 class DefineStateTypeEvent : public PajeEvent  {
140   type_t type;
141   public:
142   DefineStateTypeEvent(type_t type);
143   void print() override;
144 };
145
146
147 class SetVariableEvent : public PajeEvent  {
148   private:
149   container_t container;
150   type_t type;
151   double value;
152   public:
153   SetVariableEvent (double timestamp, container_t container, type_t type, double value);
154   void print() override;
155 };
156
157
158 class AddVariableEvent:public PajeEvent {
159   private:
160   container_t container;
161   type_t type;
162   double value;
163   public:
164   AddVariableEvent (double timestamp, container_t container, type_t type, double value);
165   void print() override;
166 };
167
168 //--------------------------------------------------
169
170
171 class SubVariableEvent : public PajeEvent  {
172   private:
173   container_t container;
174   type_t type;
175   double value;
176   public:
177   SubVariableEvent(double timestamp, container_t container, type_t type, double value);
178   void print() override;
179 };
180 //--------------------------------------------------
181
182 class SetStateEvent : public PajeEvent  {
183   private:
184   container_t container;
185   type_t type;
186   value* val;
187   const char* filename;
188   int linenumber;
189   public:
190     SetStateEvent(double timestamp, container_t container, type_t type, value* val);
191     void print() override;
192 };
193
194
195 class PushStateEvent : public PajeEvent  {
196   public:
197   container_t container;
198   type_t type;
199   value* val;
200   int size;
201   const char* filename;
202   int linenumber;
203   void* extra_;
204   public:
205     PushStateEvent(double timestamp, container_t container, type_t type, value* val);
206     PushStateEvent(double timestamp, container_t container, type_t type, value* val, void* extra);
207     void print() override;
208 };
209
210 class PopStateEvent : public PajeEvent  {
211   container_t container;
212   type_t type;
213   public:
214   PopStateEvent (double timestamp, container_t container, type_t type);
215   void print() override;
216 };
217
218 class ResetStateEvent : public PajeEvent  {
219   container_t container;
220   type_t type;
221   public:
222   ResetStateEvent (double timestamp, container_t container, type_t type);
223   void print() override;
224 };
225
226 class StartLinkEvent : public PajeEvent  {
227   public:
228   container_t container;
229   type_t type;
230   container_t sourceContainer;
231   char *value;
232   char *key;
233   int size;
234   public:
235     ~StartLinkEvent();
236     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
237                    const char* key);
238     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
239                    const char* key, int size);
240     void print() override;
241 };
242
243 class EndLinkEvent : public PajeEvent  {
244   container_t container;
245   type_t type;
246   container_t destContainer;
247   char *value;
248   char *key;
249   public:
250   EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
251                                   const char *value, const char *key);
252   ~EndLinkEvent();
253   void print() override;
254 };
255
256
257 class NewEvent : public PajeEvent  {
258   public:
259   container_t container;
260   type_t type;
261   value* val;
262
263 public:
264   NewEvent(double timestamp, container_t container, type_t type, value* val);
265   void print() override;
266
267 };
268
269
270 extern XBT_PRIVATE xbt_dict_t created_categories;
271 extern XBT_PRIVATE xbt_dict_t declared_marks;
272 extern XBT_PRIVATE xbt_dict_t user_host_variables;
273 extern XBT_PRIVATE xbt_dict_t user_vm_variables;
274 extern XBT_PRIVATE xbt_dict_t 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 xbt_dict_t trivaNodeTypes;
330 extern XBT_PRIVATE xbt_dict_t trivaEdgeTypes;
331 XBT_PRIVATE long long int instr_new_paje_id ();
332 XBT_PRIVATE void PJ_container_alloc ();
333 XBT_PRIVATE void PJ_container_release ();
334 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
335 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
336 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
337 XBT_PUBLIC(container_t) PJ_container_get_root ();
338 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
339 XBT_PUBLIC(void) PJ_container_free (container_t container);
340 XBT_PUBLIC(void) PJ_container_free_all (void);
341 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
342
343 /* instr_paje_types.c */
344 XBT_PRIVATE void PJ_type_release ();
345 XBT_PUBLIC(type_t)  PJ_type_get_root ();
346 XBT_PRIVATE type_t PJ_type_container_new (const char *name, type_t father);
347 XBT_PRIVATE type_t PJ_type_event_new (const char *name, type_t father);
348 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest);
349 XBT_PRIVATE XBT_PRIVATE type_t PJ_type_variable_new (const char *name, const char *color, type_t father);
350 XBT_PRIVATE type_t PJ_type_state_new (const char *name, type_t father);
351 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
352 XBT_PUBLIC(type_t)  PJ_type_get_or_null (const char *name, type_t father);
353 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
354
355 /* instr_config.c */
356 XBT_PRIVATE void recursiveDestroyType (type_t type);
357
358 XBT_PRIVATE void TRACE_TI_start();
359 XBT_PRIVATE void TRACE_TI_end();
360
361 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
362 XBT_PRIVATE void dump_comment_file (const char *filename);
363 XBT_PRIVATE void dump_comment (const char *comment);
364
365 struct s_instr_extra_data;
366 typedef struct s_instr_extra_data *instr_extra_data;
367
368 typedef enum{
369   TRACING_INIT,
370   TRACING_FINALIZE,
371   TRACING_COMM_SIZE,
372   TRACING_COMM_SPLIT,
373   TRACING_COMM_DUP,
374   TRACING_SEND,
375   TRACING_ISEND,
376   TRACING_SSEND,
377   TRACING_ISSEND,
378   TRACING_RECV,
379   TRACING_IRECV,
380   TRACING_SENDRECV,
381   TRACING_TEST,
382   TRACING_WAIT,
383   TRACING_WAITALL,
384   TRACING_WAITANY,
385   TRACING_BARRIER,
386   TRACING_BCAST,
387   TRACING_REDUCE,
388   TRACING_ALLREDUCE,
389   TRACING_ALLTOALL,
390   TRACING_ALLTOALLV,
391   TRACING_GATHER,
392   TRACING_GATHERV,
393   TRACING_SCATTER,
394   TRACING_SCATTERV,
395   TRACING_ALLGATHER,
396   TRACING_ALLGATHERV,
397   TRACING_REDUCE_SCATTER,
398   TRACING_COMPUTING,
399   TRACING_SLEEPING,
400   TRACING_SCAN,
401   TRACING_EXSCAN
402 } e_caller_type ;
403
404 typedef struct s_instr_extra_data {
405   e_caller_type type;
406   int send_size;
407   int recv_size;
408   double comp_size;
409   double sleep_duration;
410   int src;
411   int dst;
412   int root;
413   const char* datatype1;
414   const char* datatype2;
415   int * sendcounts;
416   int * recvcounts;
417   int num_processes;
418 } s_instr_extra_data_t;
419
420 /* Format of TRACING output.
421  *   - paje is the regular format, that we all know
422  *   - 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.
423  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
424  */
425 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
426 extern instr_fmt_type_t instr_fmt_type;
427
428 SG_END_DECL()
429
430 void DefineContainerEvent(type_t type);
431 void LogVariableTypeDefinition(type_t type);
432 void LogStateTypeDefinition(type_t type);
433 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest);
434 void LogEntityValue(value* val);
435 void LogContainerCreation (container_t container);
436 void LogContainerDestruction (container_t container);
437 void LogDefineEventType(type_t type);
438
439 #endif