Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
satisfy travis by removing some useless lines
[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 #include <string>
17
18 /* Need to define function drand48 for Windows */
19 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
20 #ifdef _WIN32
21 #  define drand48() (rand()/(RAND_MAX + 1.0))
22 #endif
23
24 #define INSTR_DEFAULT_STR_SIZE 500
25
26 #include "xbt/graph.h"
27 #include "xbt/dict.h"
28
29 namespace simgrid {
30 namespace instr {
31 typedef enum {
32   PAJE_DefineContainerType,
33   PAJE_DefineVariableType,
34   PAJE_DefineStateType,
35   PAJE_DefineEventType,
36   PAJE_DefineLinkType,
37   PAJE_DefineEntityValue,
38   PAJE_CreateContainer,
39   PAJE_DestroyContainer,
40   PAJE_SetVariable,
41   PAJE_AddVariable,
42   PAJE_SubVariable,
43   PAJE_SetState,
44   PAJE_PushState,
45   PAJE_PopState,
46   PAJE_ResetState,
47   PAJE_StartLink,
48   PAJE_EndLink,
49   PAJE_NewEvent
50 } e_event_type;
51
52 typedef enum {
53   TYPE_VARIABLE,
54   TYPE_LINK,
55   TYPE_CONTAINER,
56   TYPE_STATE,
57   TYPE_EVENT
58 } e_entity_types;
59
60 //--------------------------------------------------
61
62 class Type {
63 public:
64   char* id_;
65   char* name_;
66   char* color_;
67
68   e_entity_types kind_;
69   Type* father_;
70   xbt_dict_t children_;
71   xbt_dict_t values_; // valid for all types except variable and container
72   Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind, Type* father);
73   ~Type();
74   Type* getChild(const char* name);
75   Type* getChildOrNull(const char* name);
76
77   static Type* containerNew(const char* name, Type* father);
78   static Type* eventNew(const char* name, Type* father);
79   static Type* variableNew(const char* name, const char* color, Type* father);
80   static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
81   static Type* stateNew(const char* name, Type* father);
82 };
83
84 //--------------------------------------------------
85 class Value {
86 public:
87   char* id_;
88   char* name_;
89   char* color_;
90
91   Type* father_;
92   Value(const char* name, const char* color, Type* father);
93   ~Value();
94   static Value* get_or_new(const char* name, const char* color, Type* father);
95   static Value* get(const char* name, Type* father);
96 };
97
98
99 //--------------------------------------------------
100 typedef enum {
101   INSTR_HOST,
102   INSTR_LINK,
103   INSTR_ROUTER,
104   INSTR_AS,
105   INSTR_SMPI,
106   INSTR_MSG_VM,
107   INSTR_MSG_PROCESS,
108   INSTR_MSG_TASK
109 } e_container_types;
110
111 //--------------------------------------------------
112
113 class Container {
114 public:
115   Container(const char* name, simgrid::instr::e_container_types kind, Container* father);
116   virtual ~Container();
117
118   sg_netpoint_t netpoint_;
119   char* name_;             /* Unique name of this container */
120   char* id_;               /* Unique id of this container */
121   Type* type_;             /* Type of this container */
122   int level_ = 0;          /* Level in the hierarchy, root level is 0 */
123   e_container_types kind_; /* This container is of what kind */
124   Container* father_;
125   xbt_dict_t children_;
126 };
127
128 //--------------------------------------------------
129 class PajeEvent {
130   public:
131     double timestamp_;
132     e_event_type eventType_;
133     virtual void print() = 0;
134     virtual ~PajeEvent();
135 };
136
137 //--------------------------------------------------
138 class SetVariableEvent : public PajeEvent  {
139   private:
140     Container* container;
141     Type* type;
142     double value;
143
144   public:
145     SetVariableEvent(double timestamp, Container* container, Type* type, double value);
146     void print() override;
147 };
148
149 class AddVariableEvent:public PajeEvent {
150   private:
151     Container* container;
152     Type* type;
153     double value;
154
155   public:
156     AddVariableEvent(double timestamp, Container* container, Type* type, double value);
157     void print() override;
158 };
159 //--------------------------------------------------
160
161
162 class SubVariableEvent : public PajeEvent  {
163   private:
164     Container* container;
165     Type* type;
166     double value;
167
168   public:
169     SubVariableEvent(double timestamp, Container* container, Type* type, double value);
170     void print() override;
171 };
172 //--------------------------------------------------
173
174 class SetStateEvent : public PajeEvent  {
175   private:
176     Container* container;
177     Type* type;
178     Value* val;
179     const char* filename;
180     int linenumber;
181
182   public:
183     SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
184     void print() override;
185 };
186
187
188 class PushStateEvent : public PajeEvent  {
189   public:
190     Container* container;
191     Type* type;
192     Value* val;
193     int size;
194     const char* filename;
195     int linenumber;
196     void* extra_;
197
198   public:
199     PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
200     PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
201     void print() override;
202 };
203
204 class PopStateEvent : public PajeEvent  {
205   Container* container;
206   Type* type;
207
208 public:
209   PopStateEvent(double timestamp, Container* container, Type* type);
210   void print() override;
211 };
212
213 class ResetStateEvent : public PajeEvent  {
214   Container* container;
215   Type* type;
216
217 public:
218   ResetStateEvent(double timestamp, Container* container, Type* type);
219   void print() override;
220 };
221
222 class StartLinkEvent : public PajeEvent  {
223   Container* container_;
224   Type* type_;
225   Container* sourceContainer_;
226   std::string value_;
227   std::string key_;
228   int size_;
229
230 public:
231   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
232                  const char* key);
233   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
234                  const char* key, int size);
235   void print() override;
236 };
237
238 class EndLinkEvent : public PajeEvent  {
239   Container* container;
240   Type* type;
241   Container* destContainer;
242   char *value;
243   char *key;
244   public:
245     EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, const char* value,
246                  const char* key);
247     ~EndLinkEvent();
248     void print() override;
249 };
250
251
252 class NewEvent : public PajeEvent  {
253   public:
254     Container* container;
255     Type* type;
256     Value* val;
257
258   public:
259     NewEvent(double timestamp, Container* container, Type* type, Value* val);
260     void print() override;
261 };
262 }
263 } // namespace simgrid::instr
264 typedef simgrid::instr::Container* container_t;
265
266 SG_BEGIN_DECL()
267
268 extern XBT_PRIVATE std::set<std::string> created_categories;
269 extern XBT_PRIVATE std::set<std::string> declared_marks;
270 extern XBT_PRIVATE std::set<std::string> user_host_variables;
271 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
272 extern XBT_PRIVATE std::set<std::string> user_link_variables;
273 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
274
275 /* instr_paje_header.c */
276 XBT_PRIVATE void TRACE_header(int basic, int size);
277
278 /* from paje.c */
279 XBT_PRIVATE void TRACE_paje_start();
280 XBT_PRIVATE void TRACE_paje_end();
281 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
282
283
284 /* from instr_config.c */
285 XBT_PRIVATE bool TRACE_needs_platform ();
286 XBT_PRIVATE bool TRACE_is_enabled();
287 XBT_PRIVATE bool TRACE_platform();
288 XBT_PRIVATE bool TRACE_platform_topology();
289 XBT_PRIVATE bool TRACE_is_configured();
290 XBT_PRIVATE bool TRACE_categorized ();
291 XBT_PRIVATE bool TRACE_uncategorized ();
292 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
293 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
294 XBT_PRIVATE bool TRACE_buffer ();
295 XBT_PRIVATE bool TRACE_disable_link();
296 XBT_PRIVATE bool TRACE_disable_speed();
297 XBT_PRIVATE bool TRACE_onelink_only ();
298 XBT_PRIVATE bool TRACE_disable_destroy ();
299 XBT_PRIVATE bool TRACE_basic ();
300 XBT_PRIVATE bool TRACE_display_sizes ();
301 XBT_PRIVATE char *TRACE_get_comment ();
302 XBT_PRIVATE char *TRACE_get_comment_file ();
303 XBT_PRIVATE int TRACE_precision ();
304 XBT_PRIVATE char *TRACE_get_filename();
305 XBT_PRIVATE char *TRACE_get_viva_uncat_conf ();
306 XBT_PRIVATE char *TRACE_get_viva_cat_conf ();
307 XBT_PRIVATE void TRACE_generate_viva_uncat_conf ();
308 XBT_PRIVATE void TRACE_generate_viva_cat_conf ();
309 XBT_PRIVATE void instr_pause_tracing ();
310 XBT_PRIVATE void instr_resume_tracing ();
311
312 /* Public functions used in SMPI */
313 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
314 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
315 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
316 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
317 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
318
319 /* from resource_utilization.c */
320 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now,
321                                      double delta);
322 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char *resource,const char *category, double value, double now,
323                                      double delta);
324 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
325
326 /* instr_paje.c */
327 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
328 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
329 XBT_PRIVATE long long int instr_new_paje_id ();
330 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
331 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
332 XBT_PUBLIC(container_t) PJ_container_get_root ();
333 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
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_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
339
340 /* instr_config.c */
341 XBT_PRIVATE void TRACE_TI_start();
342 XBT_PRIVATE void TRACE_TI_end();
343
344 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
345 XBT_PRIVATE void dump_comment_file (const char *filename);
346 XBT_PRIVATE void dump_comment (const char *comment);
347
348 struct s_instr_extra_data;
349 typedef struct s_instr_extra_data *instr_extra_data;
350
351 typedef enum{
352   TRACING_INIT,
353   TRACING_FINALIZE,
354   TRACING_COMM_SIZE,
355   TRACING_COMM_SPLIT,
356   TRACING_COMM_DUP,
357   TRACING_SEND,
358   TRACING_ISEND,
359   TRACING_SSEND,
360   TRACING_ISSEND,
361   TRACING_RECV,
362   TRACING_IRECV,
363   TRACING_SENDRECV,
364   TRACING_TEST,
365   TRACING_WAIT,
366   TRACING_WAITALL,
367   TRACING_WAITANY,
368   TRACING_BARRIER,
369   TRACING_BCAST,
370   TRACING_REDUCE,
371   TRACING_ALLREDUCE,
372   TRACING_ALLTOALL,
373   TRACING_ALLTOALLV,
374   TRACING_GATHER,
375   TRACING_GATHERV,
376   TRACING_SCATTER,
377   TRACING_SCATTERV,
378   TRACING_ALLGATHER,
379   TRACING_ALLGATHERV,
380   TRACING_REDUCE_SCATTER,
381   TRACING_COMPUTING,
382   TRACING_SLEEPING,
383   TRACING_SCAN,
384   TRACING_EXSCAN
385 } e_caller_type ;
386
387 typedef struct s_instr_extra_data {
388   e_caller_type type;
389   int send_size;
390   int recv_size;
391   double comp_size;
392   double sleep_duration;
393   int src;
394   int dst;
395   int root;
396   const char* datatype1;
397   const char* datatype2;
398   int * sendcounts;
399   int * recvcounts;
400   int num_processes;
401 } s_instr_extra_data_t;
402
403 /* Format of TRACING output.
404  *   - paje is the regular format, that we all know
405  *   - 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.
406  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
407  */
408 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
409 extern instr_fmt_type_t instr_fmt_type;
410
411 SG_END_DECL()
412
413 void LogContainerTypeDefinition(simgrid::instr::Type* type);
414 void LogVariableTypeDefinition(simgrid::instr::Type* type);
415 void LogStateTypeDefinition(simgrid::instr::Type* type);
416 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
417 void LogEntityValue(simgrid::instr::Value* val);
418 void LogContainerCreation (container_t container);
419 void LogContainerDestruction (container_t container);
420 void LogDefineEventType(simgrid::instr::Type* type);
421
422 #endif