Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
turn paje_value to a class
[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 class paje_value{
266   public:
267   paje_value(){};
268   ~paje_value(){};
269   val_t PJ_value_new (const char *name, const char *color, type_t father);
270   val_t PJ_value_get (const char *name, type_t father);
271   val_t PJ_value_get_or_new (const char *name, const char *color, type_t father);
272 };
273
274 extern XBT_PRIVATE xbt_dict_t created_categories;
275 extern XBT_PRIVATE xbt_dict_t declared_marks;
276 extern XBT_PRIVATE xbt_dict_t user_host_variables;
277 extern XBT_PRIVATE xbt_dict_t user_vm_variables;
278 extern XBT_PRIVATE xbt_dict_t user_link_variables;
279 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
280
281 /* instr_paje_header.c */
282 XBT_PRIVATE void TRACE_header(int basic, int size);
283
284 /* from paje.c */
285 XBT_PRIVATE void TRACE_paje_start();
286 XBT_PRIVATE void TRACE_paje_end();
287 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
288
289
290 /* from instr_config.c */
291 XBT_PRIVATE bool TRACE_needs_platform ();
292 XBT_PRIVATE bool TRACE_is_enabled();
293 XBT_PRIVATE bool TRACE_platform();
294 XBT_PRIVATE bool TRACE_platform_topology();
295 XBT_PRIVATE bool TRACE_is_configured();
296 XBT_PRIVATE bool TRACE_categorized ();
297 XBT_PRIVATE bool TRACE_uncategorized ();
298 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
299 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
300 XBT_PRIVATE bool TRACE_buffer ();
301 XBT_PRIVATE bool TRACE_disable_link();
302 XBT_PRIVATE bool TRACE_disable_speed();
303 XBT_PRIVATE bool TRACE_onelink_only ();
304 XBT_PRIVATE bool TRACE_disable_destroy ();
305 XBT_PRIVATE bool TRACE_basic ();
306 XBT_PRIVATE bool TRACE_display_sizes ();
307 XBT_PRIVATE char *TRACE_get_comment ();
308 XBT_PRIVATE char *TRACE_get_comment_file ();
309 XBT_PRIVATE int TRACE_precision ();
310 XBT_PRIVATE char *TRACE_get_filename();
311 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
312 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
313 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
314 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
315 XBT_PRIVATE void instr_pause_tracing ();
316 XBT_PRIVATE void instr_resume_tracing ();
317
318 /* Public functions used in SMPI */
319 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
320 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
321 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
322 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
323 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
324
325 /* from resource_utilization.c */
326 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
327                                      double delta);
328 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
329                                      double delta);
330 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
331
332 /* instr_paje.c */
333 extern XBT_PRIVATE xbt_dict_t trivaNodeTypes;
334 extern XBT_PRIVATE xbt_dict_t trivaEdgeTypes;
335 XBT_PRIVATE long long int instr_new_paje_id ();
336 XBT_PRIVATE void PJ_container_alloc ();
337 XBT_PRIVATE void PJ_container_release ();
338 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
339 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
340 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
341 XBT_PUBLIC(container_t) PJ_container_get_root ();
342 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
343 XBT_PUBLIC(void) PJ_container_free (container_t container);
344 XBT_PUBLIC(void) PJ_container_free_all (void);
345 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
346
347 /* instr_paje_types.c */
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 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
358
359 /* instr_config.c */
360 XBT_PRIVATE void recursiveDestroyType (type_t type);
361
362 XBT_PRIVATE void TRACE_TI_start();
363 XBT_PRIVATE void TRACE_TI_end();
364
365 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
366 XBT_PRIVATE void dump_comment_file (const char *filename);
367 XBT_PRIVATE void dump_comment (const char *comment);
368
369 struct s_instr_extra_data;
370 typedef struct s_instr_extra_data *instr_extra_data;
371
372 typedef enum{
373   TRACING_INIT,
374   TRACING_FINALIZE,
375   TRACING_COMM_SIZE,
376   TRACING_COMM_SPLIT,
377   TRACING_COMM_DUP,
378   TRACING_SEND,
379   TRACING_ISEND,
380   TRACING_SSEND,
381   TRACING_ISSEND,
382   TRACING_RECV,
383   TRACING_IRECV,
384   TRACING_SENDRECV,
385   TRACING_TEST,
386   TRACING_WAIT,
387   TRACING_WAITALL,
388   TRACING_WAITANY,
389   TRACING_BARRIER,
390   TRACING_BCAST,
391   TRACING_REDUCE,
392   TRACING_ALLREDUCE,
393   TRACING_ALLTOALL,
394   TRACING_ALLTOALLV,
395   TRACING_GATHER,
396   TRACING_GATHERV,
397   TRACING_SCATTER,
398   TRACING_SCATTERV,
399   TRACING_ALLGATHER,
400   TRACING_ALLGATHERV,
401   TRACING_REDUCE_SCATTER,
402   TRACING_COMPUTING,
403   TRACING_SLEEPING,
404   TRACING_SCAN,
405   TRACING_EXSCAN
406 } e_caller_type ;
407
408 typedef struct s_instr_extra_data {
409   e_caller_type type;
410   int send_size;
411   int recv_size;
412   double comp_size;
413   double sleep_duration;
414   int src;
415   int dst;
416   int root;
417   const char* datatype1;
418   const char* datatype2;
419   int * sendcounts;
420   int * recvcounts;
421   int num_processes;
422 } s_instr_extra_data_t;
423
424 /* Format of TRACING output.
425  *   - paje is the regular format, that we all know
426  *   - 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.
427  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
428  */
429 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
430 extern instr_fmt_type_t instr_fmt_type;
431
432 SG_END_DECL()
433
434 void DefineContainerEvent(type_t type);
435 void LogVariableTypeDefinition(type_t type);
436 void LogStateTypeDefinition(type_t type);
437 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest);
438 void LogEntityValue (val_t value);
439 void LogContainerCreation (container_t container);
440 void LogContainerDestruction (container_t container);
441 void LogDefineEventType(type_t type);
442
443 #endif