Logo AND Algorithmique Numérique Distribuée

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