Logo AND Algorithmique Numérique Distribuée

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