Logo AND Algorithmique Numérique Distribuée

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