Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4e6dee8ac478665e95762567ddf0578ae5593095
[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/instr/instr_paje_containers.hpp"
15 #include "src/instr/instr_paje_types.hpp"
16 #include "src/internal_config.h"
17 #include "xbt/graph.h"
18 #include <iomanip> /** std::setprecision **/
19 #include <map>
20 #include <set>
21 #include <sstream>
22 #include <string>
23 #include <sys/stat.h>
24 #ifdef WIN32
25 #include <direct.h> // _mkdir
26 /* Need to define function drand48 for Windows */
27 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
28 #define drand48() (rand() / (RAND_MAX + 1.0))
29 #endif
30
31 namespace simgrid {
32 namespace instr {
33
34 class Container;
35 class Type;
36 class EntityValue;
37 class ContainerType;
38 class EventType;
39 class LinkType;
40 class StateType;
41 class VariableType;
42
43 enum e_event_type : unsigned int {
44   PAJE_DefineContainerType,
45   PAJE_DefineVariableType,
46   PAJE_DefineStateType,
47   PAJE_DefineEventType,
48   PAJE_DefineLinkType,
49   PAJE_DefineEntityValue,
50   PAJE_CreateContainer,
51   PAJE_DestroyContainer,
52   PAJE_SetVariable,
53   PAJE_AddVariable,
54   PAJE_SubVariable,
55   PAJE_SetState,
56   PAJE_PushState,
57   PAJE_PopState,
58   PAJE_ResetState,
59   PAJE_StartLink,
60   PAJE_EndLink,
61   PAJE_NewEvent
62 };
63
64 class EntityValue {
65   long long int id_;
66   std::string name_;
67   std::string color_;
68   Type* father_;
69
70 public:
71   explicit EntityValue(std::string name, std::string color, Type* father);
72   ~EntityValue() = default;
73   const char* getCname() { return name_.c_str(); }
74   long long int getId() { return id_; }
75   void print();
76 };
77
78 class PajeEvent {
79 protected:
80   Container* container;
81   Type* type;
82
83 public:
84   double timestamp_;
85   e_event_type eventType_;
86   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
87       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
88   virtual void print() = 0;
89   virtual ~PajeEvent();
90   void insertIntoBuffer();
91 };
92
93 class SetVariableEvent : public PajeEvent {
94   double value;
95
96 public:
97   SetVariableEvent(double timestamp, Container* container, Type* type, double value);
98   void print() override;
99 };
100
101 class AddVariableEvent : public PajeEvent {
102   double value;
103
104 public:
105   AddVariableEvent(double timestamp, Container* container, Type* type, double value);
106   void print() override;
107 };
108
109 class SubVariableEvent : public PajeEvent {
110   double value;
111
112 public:
113   SubVariableEvent(double timestamp, Container* container, Type* type, double value);
114   void print() override;
115 };
116
117 class SetStateEvent : public PajeEvent {
118   EntityValue* value;
119   const char* filename;
120   int linenumber;
121
122 public:
123   SetStateEvent(double timestamp, Container* container, Type* type, EntityValue* val);
124   void print() override;
125 };
126
127 class PushStateEvent : public PajeEvent {
128   EntityValue* value;
129   const char* filename;
130   int linenumber;
131   void* extra_;
132
133 public:
134   PushStateEvent(double timestamp, Container* container, Type* type, EntityValue* val);
135   PushStateEvent(double timestamp, Container* container, Type* type, EntityValue* val, void* extra);
136   void print() override;
137 };
138
139 class PopStateEvent : public PajeEvent {
140 public:
141   PopStateEvent(double timestamp, Container* container, Type* type);
142   void print() override;
143 };
144
145 class ResetStateEvent : public PajeEvent {
146 public:
147   ResetStateEvent(double timestamp, Container* container, Type* type);
148   void print() override;
149 };
150
151 class StartLinkEvent : public PajeEvent {
152   Container* sourceContainer_;
153   std::string value_;
154   std::string key_;
155   int size_;
156
157 public:
158   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
159                  std::string key);
160   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
161                  std::string key, int size);
162   void print() override;
163 };
164
165 class EndLinkEvent : public PajeEvent {
166   Container* destContainer;
167   std::string value;
168   std::string key;
169
170 public:
171   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
172                std::string key);
173   ~EndLinkEvent() = default;
174   void print() override;
175 };
176
177 class NewEvent : public PajeEvent {
178   EntityValue* val;
179
180 public:
181   NewEvent(double timestamp, Container* container, Type* type, EntityValue* val);
182   void print() override;
183 };
184 }
185 } // namespace simgrid::instr
186 typedef simgrid::instr::Container* container_t;
187
188 extern "C" {
189
190 extern XBT_PRIVATE std::set<std::string> created_categories;
191 extern XBT_PRIVATE std::set<std::string> declared_marks;
192 extern XBT_PRIVATE std::set<std::string> user_host_variables;
193 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
194 extern XBT_PRIVATE std::set<std::string> user_link_variables;
195 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
196
197 /* instr_paje_header.c */
198 XBT_PRIVATE void TRACE_header(bool basic, int size);
199
200 /* from paje.c */
201 XBT_PRIVATE void TRACE_paje_start();
202 XBT_PRIVATE void TRACE_paje_end();
203
204 /* from instr_config.c */
205 XBT_PRIVATE bool TRACE_needs_platform();
206 XBT_PRIVATE bool TRACE_is_enabled();
207 XBT_PRIVATE bool TRACE_platform();
208 XBT_PRIVATE bool TRACE_platform_topology();
209 XBT_PRIVATE bool TRACE_is_configured();
210 XBT_PRIVATE bool TRACE_categorized();
211 XBT_PRIVATE bool TRACE_uncategorized();
212 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
213 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
214 XBT_PRIVATE bool TRACE_buffer();
215 XBT_PRIVATE bool TRACE_disable_link();
216 XBT_PRIVATE bool TRACE_disable_speed();
217 XBT_PRIVATE bool TRACE_onelink_only();
218 XBT_PRIVATE bool TRACE_disable_destroy();
219 XBT_PRIVATE bool TRACE_basic();
220 XBT_PRIVATE bool TRACE_display_sizes();
221 XBT_PRIVATE char* TRACE_get_comment();
222 XBT_PRIVATE char* TRACE_get_comment_file();
223 XBT_PRIVATE int TRACE_precision();
224 XBT_PRIVATE char* TRACE_get_filename();
225 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
226 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
227 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
228 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
229 XBT_PRIVATE void instr_pause_tracing();
230 XBT_PRIVATE void instr_resume_tracing();
231
232 /* Public functions used in SMPI */
233 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
234 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
235 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
236 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
237 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
238
239 /* from resource_utilization.c */
240 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
241                                                  double delta);
242 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
243                                                  double delta);
244 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
245
246 /* instr_paje.c */
247 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
248 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
249 XBT_PRIVATE long long int instr_new_paje_id();
250 void instr_new_variable_type(std::string new_typename, std::string color);
251 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
252 void instr_new_user_state_type(std::string father_type, std::string new_typename);
253 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
254
255 /* instr_config.c */
256 XBT_PRIVATE void TRACE_TI_start();
257 XBT_PRIVATE void TRACE_TI_end();
258
259 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
260 XBT_PRIVATE void dump_comment_file(std::string filename);
261 XBT_PRIVATE void dump_comment(std::string comment);
262
263 enum e_caller_type {
264   TRACING_INIT,
265   TRACING_FINALIZE,
266   TRACING_COMM_SIZE,
267   TRACING_COMM_SPLIT,
268   TRACING_COMM_DUP,
269   TRACING_SEND,
270   TRACING_ISEND,
271   TRACING_SSEND,
272   TRACING_ISSEND,
273   TRACING_RECV,
274   TRACING_IRECV,
275   TRACING_SENDRECV,
276   TRACING_TEST,
277   TRACING_WAIT,
278   TRACING_WAITALL,
279   TRACING_WAITANY,
280   TRACING_BARRIER,
281   TRACING_BCAST,
282   TRACING_REDUCE,
283   TRACING_ALLREDUCE,
284   TRACING_ALLTOALL,
285   TRACING_ALLTOALLV,
286   TRACING_GATHER,
287   TRACING_GATHERV,
288   TRACING_SCATTER,
289   TRACING_SCATTERV,
290   TRACING_ALLGATHER,
291   TRACING_ALLGATHERV,
292   TRACING_REDUCE_SCATTER,
293   TRACING_COMPUTING,
294   TRACING_SLEEPING,
295   TRACING_SCAN,
296   TRACING_EXSCAN
297 };
298
299 struct s_instr_extra_data_t {
300   e_caller_type type;
301   int send_size;
302   int recv_size;
303   double comp_size;
304   double sleep_duration;
305   int src;
306   int dst;
307   int root;
308   const char* datatype1;
309   const char* datatype2;
310   int* sendcounts;
311   int* recvcounts;
312   int num_processes;
313 };
314 typedef s_instr_extra_data_t* instr_extra_data;
315
316 /* Format of TRACING output.
317  *   - paje is the regular format, that we all know
318  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
319  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
320  *     using the signal that we will create to cleanup the TRACING
321  */
322 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
323 extern instr_fmt_type_t instr_fmt_type;
324 }
325
326 #endif