Logo AND Algorithmique Numérique Distribuée

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