Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #202 from Takishipp/clear_fct
[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 s_val;
76 typedef s_val *val_t;
77
78 class s_val {
79   public:
80   char *id;
81   char *name;
82   char *color;
83   type_t father;
84   val_t ret;
85   s_val(const char *name, const char *color, type_t father);
86   static val_t PJ_value_get_or_new (const char *name, const char *color, type_t father);
87   static val_t PJ_value_get (const char *name, type_t father);
88 };
89
90
91 //--------------------------------------------------
92 typedef enum {
93   INSTR_HOST,
94   INSTR_LINK,
95   INSTR_ROUTER,
96   INSTR_AS,
97   INSTR_SMPI,
98   INSTR_MSG_VM,
99   INSTR_MSG_PROCESS,
100   INSTR_MSG_TASK
101 } e_container_types;
102
103 //--------------------------------------------------
104 class s_container;
105 typedef s_container *container_t;
106
107 class s_container {
108   public:
109   sg_netpoint_t netpoint;
110   char *name;     /* Unique name of this container */
111   char *id;       /* Unique id of this container */
112   type_t type;    /* Type of this container */
113   int level;      /* Level in the hierarchy, root level is 0 */
114   e_container_types kind; /* This container is of what kind */
115   s_container *father;
116   xbt_dict_t children;
117 };
118 typedef s_container s_container_t;
119
120 //--------------------------------------------------
121 class PajeEvent {
122   public:
123   double timestamp;
124   e_event_type event_type;
125   virtual void print() = 0;
126   void *data;
127   virtual ~PajeEvent();
128 };
129
130 //--------------------------------------------------
131
132 class DefineVariableTypeEvent : public PajeEvent
133 {
134   public:
135   type_t type;
136    DefineVariableTypeEvent(type_t type);
137    void print() override;
138 };
139 //--------------------------------------------------
140
141 class DefineStateTypeEvent : public PajeEvent  {
142   type_t type;
143   public:
144   DefineStateTypeEvent(type_t type);
145   void print() override;
146 };
147
148
149 class SetVariableEvent : public PajeEvent  {
150   private:
151   container_t container;
152   type_t type;
153   double value;
154   public:
155   SetVariableEvent (double timestamp, container_t container, type_t type, double value);
156   void print() override;
157 };
158
159
160 class AddVariableEvent:public PajeEvent {
161   private:
162   container_t container;
163   type_t type;
164   double value;
165   public:
166   AddVariableEvent (double timestamp, container_t container, type_t type, double value);
167   void print() override;
168 };
169
170 //--------------------------------------------------
171
172
173 class SubVariableEvent : public PajeEvent  {
174   private:
175   container_t container;
176   type_t type;
177   double value;
178   public:
179   SubVariableEvent(double timestamp, container_t container, type_t type, double value);
180   void print() override;
181 };
182 //--------------------------------------------------
183
184 class SetStateEvent : public PajeEvent  {
185   private:
186   container_t container;
187   type_t type;
188   val_t value;
189   const char* filename;
190   int linenumber;
191   public:
192   SetStateEvent (double timestamp, container_t container, type_t type, val_t value);
193   void print() override;
194 };
195
196
197 class PushStateEvent : public PajeEvent  {
198   public:
199   container_t container;
200   type_t type;
201   val_t value;
202   int size;
203   const char* filename;
204   int linenumber;
205   void* extra_;
206   public:
207   PushStateEvent (double timestamp, container_t container, type_t type, val_t value);
208   PushStateEvent (double timestamp, container_t container, type_t type, val_t value,
209                                              void* extra);
210   void print() override;
211 };
212
213 class PopStateEvent : public PajeEvent  {
214   container_t container;
215   type_t type;
216   public:
217   PopStateEvent (double timestamp, container_t container, type_t type);
218   void print() override;
219 };
220
221 class ResetStateEvent : public PajeEvent  {
222   container_t container;
223   type_t type;
224   public:
225   ResetStateEvent (double timestamp, container_t container, type_t type);
226   void print() override;
227 };
228
229 class StartLinkEvent : public PajeEvent  {
230   public:
231   container_t container;
232   type_t type;
233   container_t sourceContainer;
234   char *value;
235   char *key;
236   int size;
237   public:
238     ~StartLinkEvent();
239     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
240                    const char* key);
241     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
242                    const char* key, int size);
243     void print() override;
244 };
245
246 class EndLinkEvent : public PajeEvent  {
247   container_t container;
248   type_t type;
249   container_t destContainer;
250   char *value;
251   char *key;
252   public:
253   EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
254                                   const char *value, const char *key);
255   ~EndLinkEvent();
256   void print() override;
257 };
258
259
260 class NewEvent : public PajeEvent  {
261   public:
262   container_t container;
263   type_t type;
264   val_t value;
265   public:
266   NewEvent (double timestamp, container_t container, type_t type, val_t value);
267   void print() override;
268
269 };
270
271
272 extern XBT_PRIVATE xbt_dict_t created_categories;
273 extern XBT_PRIVATE xbt_dict_t declared_marks;
274 extern XBT_PRIVATE xbt_dict_t user_host_variables;
275 extern XBT_PRIVATE xbt_dict_t user_vm_variables;
276 extern XBT_PRIVATE xbt_dict_t user_link_variables;
277 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
278
279 /* instr_paje_header.c */
280 XBT_PRIVATE void TRACE_header(int basic, int size);
281
282 /* from paje.c */
283 XBT_PRIVATE void TRACE_paje_start();
284 XBT_PRIVATE void TRACE_paje_end();
285 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
286
287
288 /* from instr_config.c */
289 XBT_PRIVATE bool TRACE_needs_platform ();
290 XBT_PRIVATE bool TRACE_is_enabled();
291 XBT_PRIVATE bool TRACE_platform();
292 XBT_PRIVATE bool TRACE_platform_topology();
293 XBT_PRIVATE bool TRACE_is_configured();
294 XBT_PRIVATE bool TRACE_categorized ();
295 XBT_PRIVATE bool TRACE_uncategorized ();
296 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
297 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
298 XBT_PRIVATE bool TRACE_buffer ();
299 XBT_PRIVATE bool TRACE_disable_link();
300 XBT_PRIVATE bool TRACE_disable_speed();
301 XBT_PRIVATE bool TRACE_onelink_only ();
302 XBT_PRIVATE bool TRACE_disable_destroy ();
303 XBT_PRIVATE bool TRACE_basic ();
304 XBT_PRIVATE bool TRACE_display_sizes ();
305 XBT_PRIVATE char *TRACE_get_comment ();
306 XBT_PRIVATE char *TRACE_get_comment_file ();
307 XBT_PRIVATE int TRACE_precision ();
308 XBT_PRIVATE char *TRACE_get_filename();
309 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
310 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
311 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
312 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
313 XBT_PRIVATE void instr_pause_tracing ();
314 XBT_PRIVATE void instr_resume_tracing ();
315
316 /* Public functions used in SMPI */
317 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
318 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
319 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
320 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
321 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
322
323 /* from resource_utilization.c */
324 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
325                                      double delta);
326 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
327                                      double delta);
328 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
329
330 /* instr_paje.c */
331 extern XBT_PRIVATE xbt_dict_t trivaNodeTypes;
332 extern XBT_PRIVATE xbt_dict_t trivaEdgeTypes;
333 XBT_PRIVATE long long int instr_new_paje_id ();
334 XBT_PRIVATE void PJ_container_alloc ();
335 XBT_PRIVATE void PJ_container_release ();
336 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
337 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
338 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
339 XBT_PUBLIC(container_t) PJ_container_get_root ();
340 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
341 XBT_PUBLIC(void) PJ_container_free (container_t container);
342 XBT_PUBLIC(void) PJ_container_free_all (void);
343 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
344
345 /* instr_paje_types.c */
346 XBT_PRIVATE void PJ_type_release ();
347 XBT_PUBLIC(type_t)  PJ_type_get_root ();
348 XBT_PRIVATE type_t PJ_type_container_new (const char *name, type_t father);
349 XBT_PRIVATE type_t PJ_type_event_new (const char *name, type_t father);
350 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest);
351 XBT_PRIVATE XBT_PRIVATE type_t PJ_type_variable_new (const char *name, const char *color, type_t father);
352 XBT_PRIVATE type_t PJ_type_state_new (const char *name, type_t father);
353 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
354 XBT_PUBLIC(type_t)  PJ_type_get_or_null (const char *name, type_t father);
355 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
356
357 /* instr_config.c */
358 XBT_PRIVATE void recursiveDestroyType (type_t type);
359
360 XBT_PRIVATE void TRACE_TI_start();
361 XBT_PRIVATE void TRACE_TI_end();
362
363 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
364 XBT_PRIVATE void dump_comment_file (const char *filename);
365 XBT_PRIVATE void dump_comment (const char *comment);
366
367 struct s_instr_extra_data;
368 typedef struct s_instr_extra_data *instr_extra_data;
369
370 typedef enum{
371   TRACING_INIT,
372   TRACING_FINALIZE,
373   TRACING_COMM_SIZE,
374   TRACING_COMM_SPLIT,
375   TRACING_COMM_DUP,
376   TRACING_SEND,
377   TRACING_ISEND,
378   TRACING_SSEND,
379   TRACING_ISSEND,
380   TRACING_RECV,
381   TRACING_IRECV,
382   TRACING_SENDRECV,
383   TRACING_TEST,
384   TRACING_WAIT,
385   TRACING_WAITALL,
386   TRACING_WAITANY,
387   TRACING_BARRIER,
388   TRACING_BCAST,
389   TRACING_REDUCE,
390   TRACING_ALLREDUCE,
391   TRACING_ALLTOALL,
392   TRACING_ALLTOALLV,
393   TRACING_GATHER,
394   TRACING_GATHERV,
395   TRACING_SCATTER,
396   TRACING_SCATTERV,
397   TRACING_ALLGATHER,
398   TRACING_ALLGATHERV,
399   TRACING_REDUCE_SCATTER,
400   TRACING_COMPUTING,
401   TRACING_SLEEPING,
402   TRACING_SCAN,
403   TRACING_EXSCAN
404 } e_caller_type ;
405
406 typedef struct s_instr_extra_data {
407   e_caller_type type;
408   int send_size;
409   int recv_size;
410   double comp_size;
411   double sleep_duration;
412   int src;
413   int dst;
414   int root;
415   const char* datatype1;
416   const char* datatype2;
417   int * sendcounts;
418   int * recvcounts;
419   int num_processes;
420 } s_instr_extra_data_t;
421
422 /* Format of TRACING output.
423  *   - paje is the regular format, that we all know
424  *   - 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.
425  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
426  */
427 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
428 extern instr_fmt_type_t instr_fmt_type;
429
430 SG_END_DECL()
431
432 void DefineContainerEvent(type_t type);
433 void LogVariableTypeDefinition(type_t type);
434 void LogStateTypeDefinition(type_t type);
435 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest);
436 void LogEntityValue (val_t value);
437 void LogContainerCreation (container_t container);
438 void LogContainerDestruction (container_t container);
439 void LogDefineEventType(type_t type);
440
441 #endif