Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In C++ files, replace SG_{BEGIN,END}+_DECL() by extern "C" { }.
[simgrid.git] / src / instr / instr_private.hpp
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_HPP
7 #define INSTR_PRIVATE_HPP
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 <map>
16 #include <set>
17 #include <string>
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   ~Type();
75   Type* getChild(const char* name);
76   Type* getChildOrNull(const char* name);
77
78   static Type* containerNew(const char* name, Type* father);
79   static Type* eventNew(const char* name, Type* father);
80   static Type* variableNew(const char* name, const char* color, Type* father);
81   static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
82   static Type* stateNew(const char* name, Type* father);
83 };
84
85 //--------------------------------------------------
86 class Value {
87 public:
88   char* id_;
89   char* name_;
90   char* color_;
91
92   Type* father_;
93   Value(const char* name, const char* color, Type* father);
94   ~Value();
95   static Value* get_or_new(const char* name, const char* color, Type* father);
96   static Value* get(const char* name, Type* father);
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(std::string name, simgrid::instr::e_container_types kind, Container* father);
116   virtual ~Container();
117
118   sg_netpoint_t netpoint_;
119   std::string name_;       /* Unique name of this container */
120   std::string 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   std::map<std::string, Container*> 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   public:
168     SubVariableEvent(double timestamp, Container* container, Type* type, double value);
169     void print() override;
170 };
171 //--------------------------------------------------
172
173 class SetStateEvent : public PajeEvent  {
174   private:
175     Container* container;
176     Type* type;
177     Value* value;
178     const char* filename;
179     int linenumber;
180
181   public:
182     SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
183     void print() override;
184 };
185
186
187 class PushStateEvent : public PajeEvent  {
188   public:
189     Container* container;
190     Type* type;
191     Value* value;
192     int size;
193     const char* filename;
194     int linenumber;
195     void* extra_;
196
197   public:
198     PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
199     PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
200     void print() override;
201 };
202
203 class PopStateEvent : public PajeEvent  {
204   Container* container;
205   Type* type;
206
207 public:
208   PopStateEvent(double timestamp, Container* container, Type* type);
209   void print() override;
210 };
211
212 class ResetStateEvent : public PajeEvent  {
213   Container* container;
214   Type* type;
215
216 public:
217   ResetStateEvent(double timestamp, Container* container, Type* type);
218   void print() override;
219 };
220
221 class StartLinkEvent : public PajeEvent  {
222   Container* container_;
223   Type* type_;
224   Container* sourceContainer_;
225   std::string value_;
226   std::string key_;
227   int size_;
228
229 public:
230   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
231                  const char* key);
232   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
233                  const char* key, int size);
234   void print() override;
235 };
236
237 class EndLinkEvent : public PajeEvent  {
238   Container* container;
239   Type* type;
240   Container* destContainer;
241   std::string value;
242   std::string key;
243
244 public:
245   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
246                std::string key);
247   ~EndLinkEvent() = default;
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 extern "C" {
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_remove_from_parent (container_t container);
335
336 /* instr_paje_types.c */
337 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
338
339 /* instr_config.c */
340 XBT_PRIVATE void TRACE_TI_start();
341 XBT_PRIVATE void TRACE_TI_end();
342
343 XBT_PRIVATE void TRACE_paje_dump_buffer (int force);
344 XBT_PRIVATE void dump_comment_file (const char *filename);
345 XBT_PRIVATE void dump_comment (const char *comment);
346
347 struct s_instr_extra_data;
348 typedef struct s_instr_extra_data *instr_extra_data;
349
350 typedef enum{
351   TRACING_INIT,
352   TRACING_FINALIZE,
353   TRACING_COMM_SIZE,
354   TRACING_COMM_SPLIT,
355   TRACING_COMM_DUP,
356   TRACING_SEND,
357   TRACING_ISEND,
358   TRACING_SSEND,
359   TRACING_ISSEND,
360   TRACING_RECV,
361   TRACING_IRECV,
362   TRACING_SENDRECV,
363   TRACING_TEST,
364   TRACING_WAIT,
365   TRACING_WAITALL,
366   TRACING_WAITANY,
367   TRACING_BARRIER,
368   TRACING_BCAST,
369   TRACING_REDUCE,
370   TRACING_ALLREDUCE,
371   TRACING_ALLTOALL,
372   TRACING_ALLTOALLV,
373   TRACING_GATHER,
374   TRACING_GATHERV,
375   TRACING_SCATTER,
376   TRACING_SCATTERV,
377   TRACING_ALLGATHER,
378   TRACING_ALLGATHERV,
379   TRACING_REDUCE_SCATTER,
380   TRACING_COMPUTING,
381   TRACING_SLEEPING,
382   TRACING_SCAN,
383   TRACING_EXSCAN
384 } e_caller_type ;
385
386 typedef struct s_instr_extra_data {
387   e_caller_type type;
388   int send_size;
389   int recv_size;
390   double comp_size;
391   double sleep_duration;
392   int src;
393   int dst;
394   int root;
395   const char* datatype1;
396   const char* datatype2;
397   int * sendcounts;
398   int * recvcounts;
399   int num_processes;
400 } s_instr_extra_data_t;
401
402 /* Format of TRACING output.
403  *   - paje is the regular format, that we all know
404  *   - 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.
405  *     This trick should be removed and replaced by some code using the signal that we will create to cleanup the TRACING
406  */
407 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
408 extern instr_fmt_type_t instr_fmt_type;
409 }
410
411 void LogContainerTypeDefinition(simgrid::instr::Type* type);
412 void LogVariableTypeDefinition(simgrid::instr::Type* type);
413 void LogStateTypeDefinition(simgrid::instr::Type* type);
414 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
415 void LogEntityValue(simgrid::instr::Value* val);
416 void LogContainerCreation (container_t container);
417 void LogContainerDestruction (container_t container);
418 void LogDefineEventType(simgrid::instr::Type* type);
419
420 #endif