Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix smpi_execute_benched.
[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
145 class SetVariableEvent : public PajeEvent  {
146   container_t container;
147   type_t type;
148   double value;
149   public:
150   SetVariableEvent (double timestamp, container_t container, type_t type, double value);
151   void print() override;
152 };
153
154
155 class AddVariableEvent:public PajeEvent {
156   container_t container;
157   type_t type;
158   double value;
159   public:
160   AddVariableEvent (double timestamp, container_t container, type_t type, double value);
161   void print() override;
162 };
163
164 //--------------------------------------------------
165
166
167 class SubVariableEvent : public PajeEvent  {
168   public:
169   container_t container;
170   type_t type;
171   double value;
172   public:
173   SubVariableEvent(double timestamp, container_t container, type_t type, double value);
174   void print() override;
175 };
176 //--------------------------------------------------
177
178 class SetStateEvent : public PajeEvent  {
179   public:
180   container_t container;
181   type_t type;
182   val_t value;
183   const char* filename;
184   int linenumber;
185   public:
186   SetStateEvent (double timestamp, container_t container, type_t type, val_t value);
187   void print() override;
188 };
189
190
191 class PushStateEvent : public PajeEvent  {
192   public:
193   container_t container;
194   type_t type;
195   val_t value;
196   int size;
197   const char* filename;
198   int linenumber;
199   void* extra_;
200   public:
201   PushStateEvent (double timestamp, container_t container, type_t type, val_t value);
202   PushStateEvent (double timestamp, container_t container, type_t type, val_t value,
203                                              void* extra);
204   void print() override;
205 };
206
207 class PopStateEvent : public PajeEvent  {
208   container_t container;
209   type_t type;
210   public:
211   PopStateEvent (double timestamp, container_t container, type_t type);
212   void print() override;
213 };
214
215 class ResetStateEvent : public PajeEvent  {
216   container_t container;
217   type_t type;
218   public:
219   ResetStateEvent (double timestamp, container_t container, type_t type);
220   void print() override;
221 };
222
223 class StartLinkEvent : public PajeEvent  {
224   public:
225   container_t container;
226   type_t type;
227   container_t sourceContainer;
228   char *value;
229   char *key;
230   int size;
231   public:
232     ~StartLinkEvent();
233     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
234                    const char* key);
235     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
236                    const char* key, int size);
237     void print() override;
238 };
239
240 class EndLinkEvent : public PajeEvent  {
241   container_t container;
242   type_t type;
243   container_t destContainer;
244   char *value;
245   char *key;
246   public:
247   EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
248                                   const char *value, const char *key);
249   ~EndLinkEvent();
250   void print() override;
251 };
252
253
254 class NewEvent : public PajeEvent  {
255   public:
256   container_t container;
257   type_t type;
258   val_t value;
259   public:
260   NewEvent (double timestamp, container_t container, type_t type, val_t value);
261   void print() override;
262
263 };
264
265
266 extern XBT_PRIVATE xbt_dict_t created_categories;
267 extern XBT_PRIVATE xbt_dict_t declared_marks;
268 extern XBT_PRIVATE xbt_dict_t user_host_variables;
269 extern XBT_PRIVATE xbt_dict_t user_vm_variables;
270 extern XBT_PRIVATE xbt_dict_t 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 xbt_dict_t trivaNodeTypes;
326 extern XBT_PRIVATE xbt_dict_t trivaEdgeTypes;
327 XBT_PRIVATE long long int instr_new_paje_id ();
328 XBT_PRIVATE void PJ_container_alloc ();
329 XBT_PRIVATE void PJ_container_release ();
330 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
331 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
332 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
333 XBT_PUBLIC(container_t) PJ_container_get_root ();
334 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
335 XBT_PUBLIC(void) PJ_container_free (container_t container);
336 XBT_PUBLIC(void) PJ_container_free_all (void);
337 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
338
339 /* instr_paje_types.c */
340 XBT_PRIVATE void PJ_type_release ();
341 XBT_PUBLIC(type_t)  PJ_type_get_root ();
342 XBT_PRIVATE type_t PJ_type_container_new (const char *name, type_t father);
343 XBT_PRIVATE type_t PJ_type_event_new (const char *name, type_t father);
344 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest);
345 XBT_PRIVATE XBT_PRIVATE type_t PJ_type_variable_new (const char *name, const char *color, type_t father);
346 XBT_PRIVATE type_t PJ_type_state_new (const char *name, type_t father);
347 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
348 XBT_PUBLIC(type_t)  PJ_type_get_or_null (const char *name, type_t father);
349 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
350
351 /* instr_config.c */
352 XBT_PRIVATE void recursiveDestroyType (type_t type);
353
354 /* instr_paje_values.c */
355 XBT_PUBLIC(val_t)  PJ_value_new (const char *name, const char *color, type_t father);
356 XBT_PUBLIC(val_t)  PJ_value_get_or_new (const char *name, const char *color, type_t father);
357 XBT_PUBLIC(val_t)  PJ_value_get (const char *name, const type_t father);
358
359 XBT_PRIVATE void TRACE_TI_start();
360 XBT_PRIVATE void TRACE_TI_end();
361
362 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
363 XBT_PRIVATE void dump_comment_file (const char *filename);
364 XBT_PRIVATE void dump_comment (const char *comment);
365
366 struct s_instr_extra_data;
367 typedef struct s_instr_extra_data *instr_extra_data;
368
369 typedef enum{
370   TRACING_INIT,
371   TRACING_FINALIZE,
372   TRACING_COMM_SIZE,
373   TRACING_COMM_SPLIT,
374   TRACING_COMM_DUP,
375   TRACING_SEND,
376   TRACING_ISEND,
377   TRACING_SSEND,
378   TRACING_ISSEND,
379   TRACING_RECV,
380   TRACING_IRECV,
381   TRACING_SENDRECV,
382   TRACING_TEST,
383   TRACING_WAIT,
384   TRACING_WAITALL,
385   TRACING_WAITANY,
386   TRACING_BARRIER,
387   TRACING_BCAST,
388   TRACING_REDUCE,
389   TRACING_ALLREDUCE,
390   TRACING_ALLTOALL,
391   TRACING_ALLTOALLV,
392   TRACING_GATHER,
393   TRACING_GATHERV,
394   TRACING_SCATTER,
395   TRACING_SCATTERV,
396   TRACING_ALLGATHER,
397   TRACING_ALLGATHERV,
398   TRACING_REDUCE_SCATTER,
399   TRACING_COMPUTING,
400   TRACING_SLEEPING,
401   TRACING_SCAN,
402   TRACING_EXSCAN
403 } e_caller_type ;
404
405 typedef struct s_instr_extra_data {
406   e_caller_type type;
407   int send_size;
408   int recv_size;
409   double comp_size;
410   double sleep_duration;
411   int src;
412   int dst;
413   int root;
414   const char* datatype1;
415   const char* datatype2;
416   int * sendcounts;
417   int * recvcounts;
418   int num_processes;
419 } s_instr_extra_data_t;
420
421 /* Format of TRACING output.
422  *   - paje is the regular format, that we all know
423  *   - 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.
424  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
425  */
426 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
427 extern instr_fmt_type_t instr_fmt_type;
428
429 SG_END_DECL()
430
431 void DefineContainerEvent(type_t type);
432 void LogVariableTypeDefinition(type_t type);
433 void LogStateTypeDefinition(type_t type);
434 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest);
435 void LogEntityValue (val_t value);
436 void LogContainerCreation (container_t container);
437 void LogContainerDestruction (container_t container);
438 void LogDefineEventType(type_t type);
439
440 #endif