Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compare file prefix only.
[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 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   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     virtual ~PajeEvent();
129 };
130
131 //--------------------------------------------------
132 class SetVariableEvent : public PajeEvent  {
133   private:
134     Container* container;
135     Type* type;
136     double value;
137
138   public:
139     SetVariableEvent(double timestamp, Container* container, Type* type, double value);
140     void print() override;
141 };
142
143 class AddVariableEvent:public PajeEvent {
144   private:
145     Container* container;
146     Type* type;
147     double value;
148
149   public:
150     AddVariableEvent(double timestamp, Container* container, Type* type, double value);
151     void print() override;
152 };
153 //--------------------------------------------------
154
155
156 class SubVariableEvent : public PajeEvent  {
157   private:
158     Container* container;
159     Type* type;
160     double value;
161
162   public:
163     SubVariableEvent(double timestamp, Container* container, Type* type, double value);
164     void print() override;
165 };
166 //--------------------------------------------------
167
168 class SetStateEvent : public PajeEvent  {
169   private:
170     Container* container;
171     Type* type;
172     Value* val;
173     const char* filename;
174     int linenumber;
175
176   public:
177     SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
178     void print() override;
179 };
180
181
182 class PushStateEvent : public PajeEvent  {
183   public:
184     Container* container;
185     Type* type;
186     Value* val;
187     int size;
188     const char* filename;
189     int linenumber;
190     void* extra_;
191
192   public:
193     PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
194     PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
195     void print() override;
196 };
197
198 class PopStateEvent : public PajeEvent  {
199   Container* container;
200   Type* type;
201
202 public:
203   PopStateEvent(double timestamp, Container* container, Type* type);
204   void print() override;
205 };
206
207 class ResetStateEvent : public PajeEvent  {
208   Container* container;
209   Type* type;
210
211 public:
212   ResetStateEvent(double timestamp, Container* container, Type* type);
213   void print() override;
214 };
215
216 class StartLinkEvent : public PajeEvent  {
217   public:
218     Container* container;
219     Type* type;
220     Container* sourceContainer;
221     char* value;
222     char* key;
223     int size;
224
225   public:
226     ~StartLinkEvent();
227     StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
228                    const char* key);
229     StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
230                    const char* key, int size);
231     void print() override;
232 };
233
234 class EndLinkEvent : public PajeEvent  {
235   Container* container;
236   Type* type;
237   Container* destContainer;
238   char *value;
239   char *key;
240   public:
241     EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, const char* value,
242                  const char* key);
243     ~EndLinkEvent();
244     void print() override;
245 };
246
247
248 class NewEvent : public PajeEvent  {
249   public:
250     Container* container;
251     Type* type;
252     Value* val;
253
254   public:
255     NewEvent(double timestamp, Container* container, Type* type, Value* val);
256     void print() override;
257 };
258 }
259 } // namespace simgrid::instr
260 typedef simgrid::instr::Container* container_t;
261
262 SG_BEGIN_DECL()
263
264 extern XBT_PRIVATE std::set<std::string> created_categories;
265 extern XBT_PRIVATE std::set<std::string> declared_marks;
266 extern XBT_PRIVATE std::set<std::string> user_host_variables;
267 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
268 extern XBT_PRIVATE std::set<std::string> user_link_variables;
269 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
270
271 /* instr_paje_header.c */
272 XBT_PRIVATE void TRACE_header(int basic, int size);
273
274 /* from paje.c */
275 XBT_PRIVATE void TRACE_paje_start();
276 XBT_PRIVATE void TRACE_paje_end();
277 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
278
279
280 /* from instr_config.c */
281 XBT_PRIVATE bool TRACE_needs_platform ();
282 XBT_PRIVATE bool TRACE_is_enabled();
283 XBT_PRIVATE bool TRACE_platform();
284 XBT_PRIVATE bool TRACE_platform_topology();
285 XBT_PRIVATE bool TRACE_is_configured();
286 XBT_PRIVATE bool TRACE_categorized ();
287 XBT_PRIVATE bool TRACE_uncategorized ();
288 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
289 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
290 XBT_PRIVATE bool TRACE_buffer ();
291 XBT_PRIVATE bool TRACE_disable_link();
292 XBT_PRIVATE bool TRACE_disable_speed();
293 XBT_PRIVATE bool TRACE_onelink_only ();
294 XBT_PRIVATE bool TRACE_disable_destroy ();
295 XBT_PRIVATE bool TRACE_basic ();
296 XBT_PRIVATE bool TRACE_display_sizes ();
297 XBT_PRIVATE char *TRACE_get_comment ();
298 XBT_PRIVATE char *TRACE_get_comment_file ();
299 XBT_PRIVATE int TRACE_precision ();
300 XBT_PRIVATE char *TRACE_get_filename();
301 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
302 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
303 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
304 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
305 XBT_PRIVATE void instr_pause_tracing ();
306 XBT_PRIVATE void instr_resume_tracing ();
307
308 /* Public functions used in SMPI */
309 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
310 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
311 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
312 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
313 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
314
315 /* from resource_utilization.c */
316 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
317                                      double delta);
318 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
319                                      double delta);
320 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
321
322 /* instr_paje.c */
323 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
324 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
325 XBT_PRIVATE long long int instr_new_paje_id ();
326 XBT_PRIVATE void PJ_container_alloc ();
327 XBT_PRIVATE void PJ_container_release ();
328 XBT_PUBLIC(container_t) PJ_container_new(const char* name, simgrid::instr::e_container_types kind, container_t father);
329 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
330 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
331 XBT_PUBLIC(container_t) PJ_container_get_root ();
332 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
333 XBT_PUBLIC(void) PJ_container_free (container_t container);
334 XBT_PUBLIC(void) PJ_container_free_all (void);
335 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
336
337 /* instr_paje_types.c */
338 XBT_PRIVATE void PJ_type_release ();
339 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
340 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get(const char* name, simgrid::instr::Type* father);
341 XBT_PRIVATE XBT_PRIVATE void PJ_type_free(simgrid::instr::Type* type);
342
343 /* instr_config.c */
344 XBT_PRIVATE void recursiveDestroyType(simgrid::instr::Type* type);
345
346 XBT_PRIVATE void TRACE_TI_start();
347 XBT_PRIVATE void TRACE_TI_end();
348
349 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
350 XBT_PRIVATE void dump_comment_file (const char *filename);
351 XBT_PRIVATE void dump_comment (const char *comment);
352
353 struct s_instr_extra_data;
354 typedef struct s_instr_extra_data *instr_extra_data;
355
356 typedef enum{
357   TRACING_INIT,
358   TRACING_FINALIZE,
359   TRACING_COMM_SIZE,
360   TRACING_COMM_SPLIT,
361   TRACING_COMM_DUP,
362   TRACING_SEND,
363   TRACING_ISEND,
364   TRACING_SSEND,
365   TRACING_ISSEND,
366   TRACING_RECV,
367   TRACING_IRECV,
368   TRACING_SENDRECV,
369   TRACING_TEST,
370   TRACING_WAIT,
371   TRACING_WAITALL,
372   TRACING_WAITANY,
373   TRACING_BARRIER,
374   TRACING_BCAST,
375   TRACING_REDUCE,
376   TRACING_ALLREDUCE,
377   TRACING_ALLTOALL,
378   TRACING_ALLTOALLV,
379   TRACING_GATHER,
380   TRACING_GATHERV,
381   TRACING_SCATTER,
382   TRACING_SCATTERV,
383   TRACING_ALLGATHER,
384   TRACING_ALLGATHERV,
385   TRACING_REDUCE_SCATTER,
386   TRACING_COMPUTING,
387   TRACING_SLEEPING,
388   TRACING_SCAN,
389   TRACING_EXSCAN
390 } e_caller_type ;
391
392 typedef struct s_instr_extra_data {
393   e_caller_type type;
394   int send_size;
395   int recv_size;
396   double comp_size;
397   double sleep_duration;
398   int src;
399   int dst;
400   int root;
401   const char* datatype1;
402   const char* datatype2;
403   int * sendcounts;
404   int * recvcounts;
405   int num_processes;
406 } s_instr_extra_data_t;
407
408 /* Format of TRACING output.
409  *   - paje is the regular format, that we all know
410  *   - 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.
411  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
412  */
413 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
414 extern instr_fmt_type_t instr_fmt_type;
415
416 SG_END_DECL()
417
418 void LogContainerTypeDefinition(simgrid::instr::Type* type);
419 void LogVariableTypeDefinition(simgrid::instr::Type* type);
420 void LogStateTypeDefinition(simgrid::instr::Type* type);
421 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
422 void LogEntityValue(simgrid::instr::Value* val);
423 void LogContainerCreation (container_t container);
424 void LogContainerDestruction (container_t container);
425 void LogDefineEventType(simgrid::instr::Type* type);
426
427 #endif