Logo AND Algorithmique Numérique Distribuée

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