Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
01e0e10c78e950c0085675611d7993176b9c8e54
[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 namespace simgrid {
31 namespace instr {
32 typedef enum {
33   PAJE_DefineContainerType,
34   PAJE_DefineVariableType,
35   PAJE_DefineStateType,
36   PAJE_DefineEventType,
37   PAJE_DefineLinkType,
38   PAJE_DefineEntityValue,
39   PAJE_CreateContainer,
40   PAJE_DestroyContainer,
41   PAJE_SetVariable,
42   PAJE_AddVariable,
43   PAJE_SubVariable,
44   PAJE_SetState,
45   PAJE_PushState,
46   PAJE_PopState,
47   PAJE_ResetState,
48   PAJE_StartLink,
49   PAJE_EndLink,
50   PAJE_NewEvent
51 } e_event_type;
52
53 typedef enum {
54   TYPE_VARIABLE,
55   TYPE_LINK,
56   TYPE_CONTAINER,
57   TYPE_STATE,
58   TYPE_EVENT
59 } e_entity_types;
60
61 //--------------------------------------------------
62
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* father);
74   static Type* getOrNull(const char* name, Type* father);
75   static Type* containerNew(const char* name, Type* father);
76   static Type* eventNew(const char* name, Type* father);
77   static Type* variableNew(const char* name, const char* color, Type* father);
78   static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
79   static Type* stateNew(const char* name, Type* father);
80 };
81
82 //--------------------------------------------------
83 class Value {
84 public:
85   char* id;
86   char* name;
87   char* color;
88
89   Type* father;
90   Value* ret;
91   Value(const char* name, const char* color, Type* father);
92   ~Value();
93   static Value* get_or_new(const char* name, const char* color, Type* father);
94   static Value* get(const char* name, Type* 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
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     s_container* container;
157     Type* type;
158     double value;
159
160   public:
161     SetVariableEvent(double timestamp, s_container* container, Type* type, double value);
162     void print() override;
163 };
164
165
166 class AddVariableEvent:public PajeEvent {
167   private:
168     s_container* container;
169     Type* type;
170     double value;
171
172   public:
173     AddVariableEvent(double timestamp, s_container* container, Type* type, double value);
174     void print() override;
175 };
176
177 //--------------------------------------------------
178
179
180 class SubVariableEvent : public PajeEvent  {
181   private:
182     s_container* container;
183     Type* type;
184     double value;
185
186   public:
187     SubVariableEvent(double timestamp, s_container* container, Type* type, double value);
188     void print() override;
189 };
190 //--------------------------------------------------
191
192 class SetStateEvent : public PajeEvent  {
193   private:
194     s_container* container;
195     Type* type;
196     Value* val;
197     const char* filename;
198     int linenumber;
199
200   public:
201     SetStateEvent(double timestamp, s_container* container, Type* type, Value* val);
202     void print() override;
203 };
204
205
206 class PushStateEvent : public PajeEvent  {
207   public:
208     s_container* container;
209     Type* type;
210     Value* val;
211     int size;
212     const char* filename;
213     int linenumber;
214     void* extra_;
215
216   public:
217     PushStateEvent(double timestamp, s_container* container, Type* type, Value* val);
218     PushStateEvent(double timestamp, s_container* container, Type* type, Value* val, void* extra);
219     void print() override;
220 };
221
222 class PopStateEvent : public PajeEvent  {
223   s_container* container;
224   Type* type;
225
226 public:
227   PopStateEvent(double timestamp, s_container* container, Type* type);
228   void print() override;
229 };
230
231 class ResetStateEvent : public PajeEvent  {
232   s_container* container;
233   Type* type;
234
235 public:
236   ResetStateEvent(double timestamp, s_container* container, Type* type);
237   void print() override;
238 };
239
240 class StartLinkEvent : public PajeEvent  {
241   public:
242     s_container* container;
243     Type* type;
244     s_container* sourceContainer;
245     char* value;
246     char* key;
247     int size;
248
249   public:
250     ~StartLinkEvent();
251     StartLinkEvent(double timestamp, s_container* container, Type* type, s_container* sourceContainer,
252                    const char* value, const char* key);
253     StartLinkEvent(double timestamp, s_container* container, Type* type, s_container* sourceContainer,
254                    const char* value, const char* key, int size);
255     void print() override;
256 };
257
258 class EndLinkEvent : public PajeEvent  {
259   s_container* container;
260   Type* type;
261   s_container* destContainer;
262   char *value;
263   char *key;
264   public:
265     EndLinkEvent(double timestamp, s_container* container, Type* type, s_container* destContainer, const char* value,
266                  const char* key);
267     ~EndLinkEvent();
268     void print() override;
269 };
270
271
272 class NewEvent : public PajeEvent  {
273   public:
274     s_container* container;
275     Type* type;
276     Value* val;
277
278   public:
279     NewEvent(double timestamp, s_container* container, Type* type, Value* val);
280     void print() override;
281 };
282
283 extern XBT_PRIVATE std::set<std::string> created_categories;
284 extern XBT_PRIVATE std::set<std::string> declared_marks;
285 extern XBT_PRIVATE std::set<std::string> user_host_variables;
286 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
287 extern XBT_PRIVATE std::set<std::string> user_link_variables;
288 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
289 }
290 } // namespace simgrid::instr
291 typedef simgrid::instr::s_container* container_t;
292
293 /* instr_paje_header.c */
294 XBT_PRIVATE void TRACE_header(int basic, int size);
295
296 /* from paje.c */
297 XBT_PRIVATE void TRACE_paje_start();
298 XBT_PRIVATE void TRACE_paje_end();
299 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
300
301
302 /* from instr_config.c */
303 XBT_PRIVATE bool TRACE_needs_platform ();
304 XBT_PRIVATE bool TRACE_is_enabled();
305 XBT_PRIVATE bool TRACE_platform();
306 XBT_PRIVATE bool TRACE_platform_topology();
307 XBT_PRIVATE bool TRACE_is_configured();
308 XBT_PRIVATE bool TRACE_categorized ();
309 XBT_PRIVATE bool TRACE_uncategorized ();
310 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
311 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
312 XBT_PRIVATE bool TRACE_buffer ();
313 XBT_PRIVATE bool TRACE_disable_link();
314 XBT_PRIVATE bool TRACE_disable_speed();
315 XBT_PRIVATE bool TRACE_onelink_only ();
316 XBT_PRIVATE bool TRACE_disable_destroy ();
317 XBT_PRIVATE bool TRACE_basic ();
318 XBT_PRIVATE bool TRACE_display_sizes ();
319 XBT_PRIVATE char *TRACE_get_comment ();
320 XBT_PRIVATE char *TRACE_get_comment_file ();
321 XBT_PRIVATE int TRACE_precision ();
322 XBT_PRIVATE char *TRACE_get_filename();
323 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
324 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
325 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
326 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
327 XBT_PRIVATE void instr_pause_tracing ();
328 XBT_PRIVATE void instr_resume_tracing ();
329
330 /* Public functions used in SMPI */
331 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
332 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
333 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
334 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
335 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
336
337 /* from resource_utilization.c */
338 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
339                                      double delta);
340 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
341                                      double delta);
342 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
343
344 /* instr_paje.c */
345 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
346 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
347 XBT_PRIVATE long long int instr_new_paje_id ();
348 XBT_PRIVATE void PJ_container_alloc ();
349 XBT_PRIVATE void PJ_container_release ();
350 XBT_PUBLIC(container_t) PJ_container_new(const char* name, simgrid::instr::e_container_types kind, container_t father);
351 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
352 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
353 XBT_PUBLIC(container_t) PJ_container_get_root ();
354 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
355 XBT_PUBLIC(void) PJ_container_free (container_t container);
356 XBT_PUBLIC(void) PJ_container_free_all (void);
357 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
358
359 /* instr_paje_types.c */
360 XBT_PRIVATE void PJ_type_release ();
361 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
362 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get(const char* name, simgrid::instr::Type* father);
363 XBT_PRIVATE XBT_PRIVATE void PJ_type_free(simgrid::instr::Type* type);
364
365 /* instr_config.c */
366 XBT_PRIVATE void recursiveDestroyType(simgrid::instr::Type* type);
367
368 XBT_PRIVATE void TRACE_TI_start();
369 XBT_PRIVATE void TRACE_TI_end();
370
371 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
372 XBT_PRIVATE void dump_comment_file (const char *filename);
373 XBT_PRIVATE void dump_comment (const char *comment);
374
375 struct s_instr_extra_data;
376 typedef struct s_instr_extra_data *instr_extra_data;
377
378 typedef enum{
379   TRACING_INIT,
380   TRACING_FINALIZE,
381   TRACING_COMM_SIZE,
382   TRACING_COMM_SPLIT,
383   TRACING_COMM_DUP,
384   TRACING_SEND,
385   TRACING_ISEND,
386   TRACING_SSEND,
387   TRACING_ISSEND,
388   TRACING_RECV,
389   TRACING_IRECV,
390   TRACING_SENDRECV,
391   TRACING_TEST,
392   TRACING_WAIT,
393   TRACING_WAITALL,
394   TRACING_WAITANY,
395   TRACING_BARRIER,
396   TRACING_BCAST,
397   TRACING_REDUCE,
398   TRACING_ALLREDUCE,
399   TRACING_ALLTOALL,
400   TRACING_ALLTOALLV,
401   TRACING_GATHER,
402   TRACING_GATHERV,
403   TRACING_SCATTER,
404   TRACING_SCATTERV,
405   TRACING_ALLGATHER,
406   TRACING_ALLGATHERV,
407   TRACING_REDUCE_SCATTER,
408   TRACING_COMPUTING,
409   TRACING_SLEEPING,
410   TRACING_SCAN,
411   TRACING_EXSCAN
412 } e_caller_type ;
413
414 typedef struct s_instr_extra_data {
415   e_caller_type type;
416   int send_size;
417   int recv_size;
418   double comp_size;
419   double sleep_duration;
420   int src;
421   int dst;
422   int root;
423   const char* datatype1;
424   const char* datatype2;
425   int * sendcounts;
426   int * recvcounts;
427   int num_processes;
428 } s_instr_extra_data_t;
429
430 /* Format of TRACING output.
431  *   - paje is the regular format, that we all know
432  *   - 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.
433  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
434  */
435 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
436 extern instr_fmt_type_t instr_fmt_type;
437
438 SG_END_DECL()
439
440 void DefineContainerEvent(simgrid::instr::Type* type);
441 void LogVariableTypeDefinition(simgrid::instr::Type* type);
442 void LogStateTypeDefinition(simgrid::instr::Type* type);
443 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
444 void LogEntityValue(simgrid::instr::Value* val);
445 void LogContainerCreation (container_t container);
446 void LogContainerDestruction (container_t container);
447 void LogDefineEventType(simgrid::instr::Type* type);
448
449 #endif