Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
instr: please sonar
[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 /* Need to define function drand48 for Windows */
18 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
19 #ifdef _WIN32
20 #  define drand48() (rand()/(RAND_MAX + 1.0))
21 #endif
22
23 #define INSTR_DEFAULT_STR_SIZE 500
24
25 #include "xbt/graph.h"
26 #include "xbt/dict.h"
27
28 namespace simgrid {
29 namespace instr {
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
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* 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 eventType_;
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* type;
138     DefineVariableTypeEvent(Type* type);
139     void print() override;
140 };
141 //--------------------------------------------------
142
143 class DefineStateTypeEvent : public PajeEvent  {
144   Type* type;
145
146 public:
147   DefineStateTypeEvent(Type* type);
148   void print() override;
149 };
150
151
152 class SetVariableEvent : public PajeEvent  {
153   private:
154     s_container* container;
155     Type* type;
156     double value;
157
158   public:
159     SetVariableEvent(double timestamp, s_container* container, Type* type, double value);
160     void print() override;
161 };
162
163
164 class AddVariableEvent:public PajeEvent {
165   private:
166     s_container* container;
167     Type* type;
168     double value;
169
170   public:
171     AddVariableEvent(double timestamp, s_container* container, Type* type, double value);
172     void print() override;
173 };
174
175 //--------------------------------------------------
176
177
178 class SubVariableEvent : public PajeEvent  {
179   private:
180     s_container* container;
181     Type* type;
182     double value;
183
184   public:
185     SubVariableEvent(double timestamp, s_container* container, Type* type, double value);
186     void print() override;
187 };
188 //--------------------------------------------------
189
190 class SetStateEvent : public PajeEvent  {
191   private:
192     s_container* container;
193     Type* type;
194     Value* val;
195     const char* filename;
196     int linenumber;
197
198   public:
199     SetStateEvent(double timestamp, s_container* container, Type* type, Value* val);
200     void print() override;
201 };
202
203
204 class PushStateEvent : public PajeEvent  {
205   public:
206     s_container* container;
207     Type* type;
208     Value* val;
209     int size;
210     const char* filename;
211     int linenumber;
212     void* extra_;
213
214   public:
215     PushStateEvent(double timestamp, s_container* container, Type* type, Value* val);
216     PushStateEvent(double timestamp, s_container* container, Type* type, Value* val, void* extra);
217     void print() override;
218 };
219
220 class PopStateEvent : public PajeEvent  {
221   s_container* container;
222   Type* type;
223
224 public:
225   PopStateEvent(double timestamp, s_container* container, Type* type);
226   void print() override;
227 };
228
229 class ResetStateEvent : public PajeEvent  {
230   s_container* container;
231   Type* type;
232
233 public:
234   ResetStateEvent(double timestamp, s_container* container, Type* type);
235   void print() override;
236 };
237
238 class StartLinkEvent : public PajeEvent  {
239   public:
240     s_container* container;
241     Type* type;
242     s_container* sourceContainer;
243     char* value;
244     char* key;
245     int size;
246
247   public:
248     ~StartLinkEvent();
249     StartLinkEvent(double timestamp, s_container* container, Type* type, s_container* sourceContainer,
250                    const char* value, const char* key);
251     StartLinkEvent(double timestamp, s_container* container, Type* type, s_container* sourceContainer,
252                    const char* value, const char* key, int size);
253     void print() override;
254 };
255
256 class EndLinkEvent : public PajeEvent  {
257   s_container* container;
258   Type* type;
259   s_container* destContainer;
260   char *value;
261   char *key;
262   public:
263     EndLinkEvent(double timestamp, s_container* container, Type* type, s_container* destContainer, const char* value,
264                  const char* key);
265     ~EndLinkEvent();
266     void print() override;
267 };
268
269
270 class NewEvent : public PajeEvent  {
271   public:
272     s_container* container;
273     Type* type;
274     Value* val;
275
276   public:
277     NewEvent(double timestamp, s_container* container, Type* type, Value* val);
278     void print() override;
279 };
280 }
281 } // namespace simgrid::instr
282 typedef simgrid::instr::s_container* container_t;
283
284 SG_BEGIN_DECL()
285
286 extern XBT_PRIVATE std::set<std::string> created_categories;
287 extern XBT_PRIVATE std::set<std::string> declared_marks;
288 extern XBT_PRIVATE std::set<std::string> user_host_variables;
289 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
290 extern XBT_PRIVATE std::set<std::string> user_link_variables;
291 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
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