Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add event_new to s_type class as a method
[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 "instr/instr_interface.h"
12 #include "simgrid/instr.h"
13 #include "simgrid_config.h"
14 #include "src/internal_config.h"
15 #include <set>
16
17 SG_BEGIN_DECL()
18
19 /* Need to define function drand48 for Windows */
20 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
21 #ifdef _WIN32
22 #  define drand48() (rand()/(RAND_MAX + 1.0))
23 #endif
24
25 #define INSTR_DEFAULT_STR_SIZE 500
26
27 #include "xbt/graph.h"
28 #include "xbt/dict.h"
29
30 typedef enum {
31   PAJE_DefineContainerType,
32   PAJE_DefineVariableType,
33   PAJE_DefineStateType,
34   PAJE_DefineEventType,
35   PAJE_DefineLinkType,
36   PAJE_DefineEntityValue,
37   PAJE_CreateContainer,
38   PAJE_DestroyContainer,
39   PAJE_SetVariable,
40   PAJE_AddVariable,
41   PAJE_SubVariable,
42   PAJE_SetState,
43   PAJE_PushState,
44   PAJE_PopState,
45   PAJE_ResetState,
46   PAJE_StartLink,
47   PAJE_EndLink,
48   PAJE_NewEvent
49 } e_event_type;
50
51 typedef enum {
52   TYPE_VARIABLE,
53   TYPE_LINK,
54   TYPE_CONTAINER,
55   TYPE_STATE,
56   TYPE_EVENT
57 } e_entity_types;
58
59 //--------------------------------------------------
60
61 class ess_type {
62   public:
63   char *id;
64   char *name;
65   char *color;
66 };
67
68 class s_type;
69 typedef s_type *type_t;
70 class s_type : public ess_type {
71   public:
72   e_entity_types kind;
73   s_type *father;
74   xbt_dict_t children;
75   xbt_dict_t values; //valid for all types except variable and container
76   s_type (const char *typeNameBuff, const char *key, const char *color, e_entity_types kind, type_t father);
77   static type_t s_type_get_or_null (const char *name, type_t father);
78   static type_t s_type_container_new (const char *name, type_t father);
79   static type_t s_type_event_new (const char *name, type_t father);
80 };
81
82 //--------------------------------------------------
83 class value : public ess_type{
84 public:
85   type_t father;
86   value* ret;
87   value(const char* name, const char* color, type_t father);
88   ~value();
89   static value* get_or_new(const char* name, const char* color, type_t father);
90   static value* get(const char* name, type_t father);
91 };
92
93
94 //--------------------------------------------------
95 typedef enum {
96   INSTR_HOST,
97   INSTR_LINK,
98   INSTR_ROUTER,
99   INSTR_AS,
100   INSTR_SMPI,
101   INSTR_MSG_VM,
102   INSTR_MSG_PROCESS,
103   INSTR_MSG_TASK
104 } e_container_types;
105
106 //--------------------------------------------------
107 class s_container;
108 typedef s_container *container_t;
109
110 class s_container {
111   public:
112   sg_netpoint_t netpoint;
113   char *name;     /* Unique name of this container */
114   char *id;       /* Unique id of this container */
115   type_t type;    /* Type of this container */
116   int level;      /* Level in the hierarchy, root level is 0 */
117   e_container_types kind; /* This container is of what kind */
118   s_container *father;
119   xbt_dict_t children;
120 };
121
122 //--------------------------------------------------
123 class PajeEvent {
124   public:
125   double timestamp;
126   e_event_type event_type;
127   virtual void print() = 0;
128   void *data;
129   virtual ~PajeEvent();
130 };
131
132 //--------------------------------------------------
133
134 class DefineVariableTypeEvent : public PajeEvent
135 {
136   public:
137   type_t type;
138    DefineVariableTypeEvent(type_t type);
139    void print() override;
140 };
141 //--------------------------------------------------
142
143 class DefineStateTypeEvent : public PajeEvent  {
144   type_t type;
145   public:
146   DefineStateTypeEvent(type_t type);
147   void print() override;
148 };
149
150
151 class SetVariableEvent : public PajeEvent  {
152   private:
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   private:
164   container_t container;
165   type_t type;
166   double value;
167   public:
168   AddVariableEvent (double timestamp, container_t container, type_t type, double value);
169   void print() override;
170 };
171
172 //--------------------------------------------------
173
174
175 class SubVariableEvent : public PajeEvent  {
176   private:
177   container_t container;
178   type_t type;
179   double value;
180   public:
181   SubVariableEvent(double timestamp, container_t container, type_t type, double value);
182   void print() override;
183 };
184 //--------------------------------------------------
185
186 class SetStateEvent : public PajeEvent  {
187   private:
188   container_t container;
189   type_t type;
190   value* val;
191   const char* filename;
192   int linenumber;
193   public:
194     SetStateEvent(double timestamp, container_t container, type_t type, value* val);
195     void print() override;
196 };
197
198
199 class PushStateEvent : public PajeEvent  {
200   public:
201   container_t container;
202   type_t type;
203   value* val;
204   int size;
205   const char* filename;
206   int linenumber;
207   void* extra_;
208   public:
209     PushStateEvent(double timestamp, container_t container, type_t type, value* val);
210     PushStateEvent(double timestamp, container_t container, type_t type, value* val, 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   value* val;
266
267 public:
268   NewEvent(double timestamp, container_t container, type_t type, value* val);
269   void print() override;
270
271 };
272
273 extern XBT_PRIVATE std::set<std::string> created_categories;
274 extern XBT_PRIVATE std::set<std::string> declared_marks;
275 extern XBT_PRIVATE std::set<std::string> user_host_variables;
276 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
277 extern XBT_PRIVATE std::set<std::string> 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 std::set<std::string> trivaNodeTypes;
333 extern XBT_PRIVATE std::set<std::string> 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_release ();
348 XBT_PUBLIC(type_t)  PJ_type_get_root ();
349 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest);
350 XBT_PRIVATE XBT_PRIVATE type_t PJ_type_variable_new (const char *name, const char *color, type_t father);
351 XBT_PRIVATE type_t PJ_type_state_new (const char *name, type_t father);
352 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
353 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
354
355 /* instr_config.c */
356 XBT_PRIVATE void recursiveDestroyType (type_t type);
357
358 XBT_PRIVATE void TRACE_TI_start();
359 XBT_PRIVATE void TRACE_TI_end();
360
361 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
362 XBT_PRIVATE void dump_comment_file (const char *filename);
363 XBT_PRIVATE void dump_comment (const char *comment);
364
365 struct s_instr_extra_data;
366 typedef struct s_instr_extra_data *instr_extra_data;
367
368 typedef enum{
369   TRACING_INIT,
370   TRACING_FINALIZE,
371   TRACING_COMM_SIZE,
372   TRACING_COMM_SPLIT,
373   TRACING_COMM_DUP,
374   TRACING_SEND,
375   TRACING_ISEND,
376   TRACING_SSEND,
377   TRACING_ISSEND,
378   TRACING_RECV,
379   TRACING_IRECV,
380   TRACING_SENDRECV,
381   TRACING_TEST,
382   TRACING_WAIT,
383   TRACING_WAITALL,
384   TRACING_WAITANY,
385   TRACING_BARRIER,
386   TRACING_BCAST,
387   TRACING_REDUCE,
388   TRACING_ALLREDUCE,
389   TRACING_ALLTOALL,
390   TRACING_ALLTOALLV,
391   TRACING_GATHER,
392   TRACING_GATHERV,
393   TRACING_SCATTER,
394   TRACING_SCATTERV,
395   TRACING_ALLGATHER,
396   TRACING_ALLGATHERV,
397   TRACING_REDUCE_SCATTER,
398   TRACING_COMPUTING,
399   TRACING_SLEEPING,
400   TRACING_SCAN,
401   TRACING_EXSCAN
402 } e_caller_type ;
403
404 typedef struct s_instr_extra_data {
405   e_caller_type type;
406   int send_size;
407   int recv_size;
408   double comp_size;
409   double sleep_duration;
410   int src;
411   int dst;
412   int root;
413   const char* datatype1;
414   const char* datatype2;
415   int * sendcounts;
416   int * recvcounts;
417   int num_processes;
418 } s_instr_extra_data_t;
419
420 /* Format of TRACING output.
421  *   - paje is the regular format, that we all know
422  *   - 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.
423  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
424  */
425 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
426 extern instr_fmt_type_t instr_fmt_type;
427
428 SG_END_DECL()
429
430 void DefineContainerEvent(type_t type);
431 void LogVariableTypeDefinition(type_t type);
432 void LogStateTypeDefinition(type_t type);
433 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest);
434 void LogEntityValue(value* val);
435 void LogContainerCreation (container_t container);
436 void LogContainerDestruction (container_t container);
437 void LogDefineEventType(type_t type);
438
439 #endif