Logo AND Algorithmique Numérique Distribuée

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