Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refactoring 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   static simgrid::instr::Container* byNameOrNull(std::string name);
131   static simgrid::instr::Container* byName(std::string name);
132 };
133
134 //--------------------------------------------------
135 class PajeEvent {
136 protected:
137   Container* container;
138   Type* type;
139
140 public:
141   double timestamp_;
142   e_event_type eventType_;
143   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
144       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
145   virtual void print() = 0;
146   virtual ~PajeEvent();
147   void insertIntoBuffer();
148 };
149
150 //--------------------------------------------------
151 class SetVariableEvent : public PajeEvent {
152   double value;
153
154 public:
155   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
156   void print() override;
157 };
158
159 class AddVariableEvent : public PajeEvent {
160   double value;
161
162 public:
163   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
164   void print() override;
165 };
166 //--------------------------------------------------
167
168 class SubVariableEvent : public PajeEvent {
169   double value;
170
171 public:
172   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
173   void print() override;
174 };
175 //--------------------------------------------------
176
177 class SetStateEvent : public PajeEvent {
178   Value* value;
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 class PushStateEvent : public PajeEvent {
188   Value* value;
189   const char* filename;
190   int linenumber;
191   void* extra_;
192
193 public:
194   PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
195   PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
196   void print() override;
197 };
198
199 class PopStateEvent : public PajeEvent {
200 public:
201   PopStateEvent(double timestamp, Container* container, Type* type);
202   void print() override;
203 };
204
205 class ResetStateEvent : public PajeEvent {
206 public:
207   ResetStateEvent(double timestamp, Container* container, Type* type);
208   void print() override;
209 };
210
211 class StartLinkEvent : public PajeEvent {
212   Container* sourceContainer_;
213   std::string value_;
214   std::string key_;
215   int size_;
216
217 public:
218   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
219                  std::string key);
220   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
221                  std::string key, int size);
222   void print() override;
223 };
224
225 class EndLinkEvent : public PajeEvent {
226   Container* destContainer;
227   std::string value;
228   std::string key;
229
230 public:
231   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
232                std::string key);
233   ~EndLinkEvent() = default;
234   void print() override;
235 };
236
237 class NewEvent : public PajeEvent {
238   Value* val;
239
240 public:
241   NewEvent(double timestamp, Container* container, Type* type, Value* val);
242   void print() override;
243 };
244 }
245 } // namespace simgrid::instr
246 typedef simgrid::instr::Container* container_t;
247
248 extern "C" {
249
250 extern XBT_PRIVATE std::set<std::string> created_categories;
251 extern XBT_PRIVATE std::set<std::string> declared_marks;
252 extern XBT_PRIVATE std::set<std::string> user_host_variables;
253 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
254 extern XBT_PRIVATE std::set<std::string> user_link_variables;
255 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
256
257 /* instr_paje_header.c */
258 XBT_PRIVATE void TRACE_header(int basic, int size);
259
260 /* from paje.c */
261 XBT_PRIVATE void TRACE_paje_start();
262 XBT_PRIVATE void TRACE_paje_end();
263 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
264
265 /* from instr_config.c */
266 XBT_PRIVATE bool TRACE_needs_platform();
267 XBT_PRIVATE bool TRACE_is_enabled();
268 XBT_PRIVATE bool TRACE_platform();
269 XBT_PRIVATE bool TRACE_platform_topology();
270 XBT_PRIVATE bool TRACE_is_configured();
271 XBT_PRIVATE bool TRACE_categorized();
272 XBT_PRIVATE bool TRACE_uncategorized();
273 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
274 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
275 XBT_PRIVATE bool TRACE_buffer();
276 XBT_PRIVATE bool TRACE_disable_link();
277 XBT_PRIVATE bool TRACE_disable_speed();
278 XBT_PRIVATE bool TRACE_onelink_only();
279 XBT_PRIVATE bool TRACE_disable_destroy();
280 XBT_PRIVATE bool TRACE_basic();
281 XBT_PRIVATE bool TRACE_display_sizes();
282 XBT_PRIVATE char* TRACE_get_comment();
283 XBT_PRIVATE char* TRACE_get_comment_file();
284 XBT_PRIVATE int TRACE_precision();
285 XBT_PRIVATE char* TRACE_get_filename();
286 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
287 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
288 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
289 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
290 XBT_PRIVATE void instr_pause_tracing();
291 XBT_PRIVATE void instr_resume_tracing();
292
293 /* Public functions used in SMPI */
294 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
295 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
296 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
297 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
298 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
299
300 /* from resource_utilization.c */
301 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
302                                                  double delta);
303 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
304                                                  double delta);
305 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
306
307 /* instr_paje.c */
308 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
309 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
310 XBT_PRIVATE long long int instr_new_paje_id();
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