Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a class with no method is not 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 "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 Type;
62 typedef Type* type_t;
63 class Type {
64 public:
65   char *id;
66   char *name;
67   char *color;
68
69   e_entity_types kind;
70   Type *father;
71   xbt_dict_t children;
72   xbt_dict_t values; //valid for all types except variable and container
73   Type (const char *typeNameBuff, const char *key, const char *color, e_entity_types kind, type_t father);
74   static type_t getOrNull (const char *name, type_t father);
75   static type_t containerNew (const char *name, type_t father);
76   static type_t eventNew (const char *name, type_t father);
77   static type_t variableNew (const char *name, const char *color, type_t father);
78   static type_t linkNew (const char *name, type_t father, type_t source, type_t dest);
79   static type_t stateNew (const char *name, type_t father);
80 };
81
82 //--------------------------------------------------
83 class value {
84 public:
85   char* id;
86   char* name;
87   char* color;
88
89   type_t father;
90   value* ret;
91   value(const char* name, const char* color, type_t father);
92   ~value();
93   static value* get_or_new(const char* name, const char* color, type_t father);
94   static value* get(const char* name, type_t father);
95 };
96
97
98 //--------------------------------------------------
99 typedef enum {
100   INSTR_HOST,
101   INSTR_LINK,
102   INSTR_ROUTER,
103   INSTR_AS,
104   INSTR_SMPI,
105   INSTR_MSG_VM,
106   INSTR_MSG_PROCESS,
107   INSTR_MSG_TASK
108 } e_container_types;
109
110 //--------------------------------------------------
111 class s_container;
112 typedef s_container *container_t;
113
114 class s_container {
115   public:
116   sg_netpoint_t netpoint;
117   char *name;     /* Unique name of this container */
118   char *id;       /* Unique id of this container */
119   type_t type;    /* Type of this container */
120   int level;      /* Level in the hierarchy, root level is 0 */
121   e_container_types kind; /* This container is of what kind */
122   s_container *father;
123   xbt_dict_t children;
124 };
125
126 //--------------------------------------------------
127 class PajeEvent {
128   public:
129   double timestamp;
130   e_event_type event_type;
131   virtual void print() = 0;
132   void *data;
133   virtual ~PajeEvent();
134 };
135
136 //--------------------------------------------------
137
138 class DefineVariableTypeEvent : public PajeEvent
139 {
140   public:
141   type_t type;
142    DefineVariableTypeEvent(type_t type);
143    void print() override;
144 };
145 //--------------------------------------------------
146
147 class DefineStateTypeEvent : public PajeEvent  {
148   type_t type;
149   public:
150   DefineStateTypeEvent(type_t type);
151   void print() override;
152 };
153
154
155 class SetVariableEvent : public PajeEvent  {
156   private:
157   container_t container;
158   type_t type;
159   double value;
160   public:
161   SetVariableEvent (double timestamp, container_t container, type_t type, double value);
162   void print() override;
163 };
164
165
166 class AddVariableEvent:public PajeEvent {
167   private:
168   container_t container;
169   type_t type;
170   double value;
171   public:
172   AddVariableEvent (double timestamp, container_t container, type_t type, double value);
173   void print() override;
174 };
175
176 //--------------------------------------------------
177
178
179 class SubVariableEvent : public PajeEvent  {
180   private:
181   container_t container;
182   type_t type;
183   double value;
184   public:
185   SubVariableEvent(double timestamp, container_t container, type_t type, double value);
186   void print() override;
187 };
188 //--------------------------------------------------
189
190 class SetStateEvent : public PajeEvent  {
191   private:
192   container_t container;
193   type_t type;
194   value* val;
195   const char* filename;
196   int linenumber;
197   public:
198     SetStateEvent(double timestamp, container_t container, type_t type, value* val);
199     void print() override;
200 };
201
202
203 class PushStateEvent : public PajeEvent  {
204   public:
205   container_t container;
206   type_t type;
207   value* val;
208   int size;
209   const char* filename;
210   int linenumber;
211   void* extra_;
212   public:
213     PushStateEvent(double timestamp, container_t container, type_t type, value* val);
214     PushStateEvent(double timestamp, container_t container, type_t type, value* val, void* extra);
215     void print() override;
216 };
217
218 class PopStateEvent : public PajeEvent  {
219   container_t container;
220   type_t type;
221   public:
222   PopStateEvent (double timestamp, container_t container, type_t type);
223   void print() override;
224 };
225
226 class ResetStateEvent : public PajeEvent  {
227   container_t container;
228   type_t type;
229   public:
230   ResetStateEvent (double timestamp, container_t container, type_t type);
231   void print() override;
232 };
233
234 class StartLinkEvent : public PajeEvent  {
235   public:
236   container_t container;
237   type_t type;
238   container_t sourceContainer;
239   char *value;
240   char *key;
241   int size;
242   public:
243     ~StartLinkEvent();
244     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
245                    const char* key);
246     StartLinkEvent(double timestamp, container_t container, type_t type, container_t sourceContainer, const char* value,
247                    const char* key, int size);
248     void print() override;
249 };
250
251 class EndLinkEvent : public PajeEvent  {
252   container_t container;
253   type_t type;
254   container_t destContainer;
255   char *value;
256   char *key;
257   public:
258   EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
259                                   const char *value, const char *key);
260   ~EndLinkEvent();
261   void print() override;
262 };
263
264
265 class NewEvent : public PajeEvent  {
266   public:
267   container_t container;
268   type_t type;
269   value* val;
270
271 public:
272   NewEvent(double timestamp, container_t container, type_t type, value* val);
273   void print() override;
274
275 };
276
277 extern XBT_PRIVATE std::set<std::string> created_categories;
278 extern XBT_PRIVATE std::set<std::string> declared_marks;
279 extern XBT_PRIVATE std::set<std::string> user_host_variables;
280 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
281 extern XBT_PRIVATE std::set<std::string> user_link_variables;
282 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
283
284 /* instr_paje_header.c */
285 XBT_PRIVATE void TRACE_header(int basic, int size);
286
287 /* from paje.c */
288 XBT_PRIVATE void TRACE_paje_start();
289 XBT_PRIVATE void TRACE_paje_end();
290 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
291
292
293 /* from instr_config.c */
294 XBT_PRIVATE bool TRACE_needs_platform ();
295 XBT_PRIVATE bool TRACE_is_enabled();
296 XBT_PRIVATE bool TRACE_platform();
297 XBT_PRIVATE bool TRACE_platform_topology();
298 XBT_PRIVATE bool TRACE_is_configured();
299 XBT_PRIVATE bool TRACE_categorized ();
300 XBT_PRIVATE bool TRACE_uncategorized ();
301 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
302 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
303 XBT_PRIVATE bool TRACE_buffer ();
304 XBT_PRIVATE bool TRACE_disable_link();
305 XBT_PRIVATE bool TRACE_disable_speed();
306 XBT_PRIVATE bool TRACE_onelink_only ();
307 XBT_PRIVATE bool TRACE_disable_destroy ();
308 XBT_PRIVATE bool TRACE_basic ();
309 XBT_PRIVATE bool TRACE_display_sizes ();
310 XBT_PRIVATE char *TRACE_get_comment ();
311 XBT_PRIVATE char *TRACE_get_comment_file ();
312 XBT_PRIVATE int TRACE_precision ();
313 XBT_PRIVATE char *TRACE_get_filename();
314 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
315 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
316 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
317 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
318 XBT_PRIVATE void instr_pause_tracing ();
319 XBT_PRIVATE void instr_resume_tracing ();
320
321 /* Public functions used in SMPI */
322 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
323 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
324 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
325 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
326 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
327
328 /* from resource_utilization.c */
329 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
330                                      double delta);
331 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
332                                      double delta);
333 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
334
335 /* instr_paje.c */
336 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
337 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
338 XBT_PRIVATE long long int instr_new_paje_id ();
339 XBT_PRIVATE void PJ_container_alloc ();
340 XBT_PRIVATE void PJ_container_release ();
341 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
342 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
343 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
344 XBT_PUBLIC(container_t) PJ_container_get_root ();
345 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
346 XBT_PUBLIC(void) PJ_container_free (container_t container);
347 XBT_PUBLIC(void) PJ_container_free_all (void);
348 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
349
350 /* instr_paje_types.c */
351 XBT_PRIVATE void PJ_type_release ();
352 XBT_PUBLIC(type_t)  PJ_type_get_root ();
353 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
354 XBT_PRIVATE XBT_PRIVATE void PJ_type_free (type_t type); 
355
356 /* instr_config.c */
357 XBT_PRIVATE void recursiveDestroyType (type_t type);
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(value* val);
436 void LogContainerCreation (container_t container);
437 void LogContainerDestruction (container_t container);
438 void LogDefineEventType(type_t type);
439
440 #endif