Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4a9433bab02e9d52c3d4635b8971fa6dc35b4158
[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 StateEvent : public PajeEvent {
118   EntityValue* value;
119   std::string filename;
120   int linenumber;
121   void* extra_ = nullptr;
122
123 public:
124   StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value);
125   StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value,
126              void* extra);
127   void print() override;
128 };
129
130 class StartLinkEvent : public PajeEvent {
131   Container* sourceContainer_;
132   std::string value_;
133   std::string key_;
134   int size_;
135
136 public:
137   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
138                  std::string key);
139   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
140                  std::string key, int size);
141   void print() override;
142 };
143
144 class EndLinkEvent : public PajeEvent {
145   Container* destContainer;
146   std::string value;
147   std::string key;
148
149 public:
150   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
151                std::string key);
152   ~EndLinkEvent() = default;
153   void print() override;
154 };
155
156 class NewEvent : public PajeEvent {
157   EntityValue* val;
158
159 public:
160   NewEvent(double timestamp, Container* container, Type* type, EntityValue* val);
161   void print() override;
162 };
163 }
164 } // namespace simgrid::instr
165 typedef simgrid::instr::Container* container_t;
166
167 extern "C" {
168
169 extern XBT_PRIVATE std::set<std::string> created_categories;
170 extern XBT_PRIVATE std::set<std::string> declared_marks;
171 extern XBT_PRIVATE std::set<std::string> user_host_variables;
172 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
173 extern XBT_PRIVATE std::set<std::string> user_link_variables;
174 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
175
176 /* instr_paje_header.c */
177 XBT_PRIVATE void TRACE_header(bool basic, int size);
178
179 /* from paje.c */
180 XBT_PRIVATE void TRACE_paje_start();
181 XBT_PRIVATE void TRACE_paje_end();
182
183 /* from instr_config.c */
184 XBT_PRIVATE bool TRACE_needs_platform();
185 XBT_PRIVATE bool TRACE_is_enabled();
186 XBT_PRIVATE bool TRACE_platform();
187 XBT_PRIVATE bool TRACE_platform_topology();
188 XBT_PRIVATE bool TRACE_is_configured();
189 XBT_PRIVATE bool TRACE_categorized();
190 XBT_PRIVATE bool TRACE_uncategorized();
191 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
192 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
193 XBT_PRIVATE bool TRACE_buffer();
194 XBT_PRIVATE bool TRACE_disable_link();
195 XBT_PRIVATE bool TRACE_disable_speed();
196 XBT_PRIVATE bool TRACE_onelink_only();
197 XBT_PRIVATE bool TRACE_disable_destroy();
198 XBT_PRIVATE bool TRACE_basic();
199 XBT_PRIVATE bool TRACE_display_sizes();
200 XBT_PRIVATE char* TRACE_get_comment();
201 XBT_PRIVATE char* TRACE_get_comment_file();
202 XBT_PRIVATE int TRACE_precision();
203 XBT_PRIVATE char* TRACE_get_filename();
204 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
205 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
206 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
207 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
208 XBT_PRIVATE void instr_pause_tracing();
209 XBT_PRIVATE void instr_resume_tracing();
210
211 /* Public functions used in SMPI */
212 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
213 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
214 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
215 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
216 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
217
218 /* from resource_utilization.c */
219 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
220                                                  double delta);
221 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
222                                                  double delta);
223 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
224
225 /* instr_paje.c */
226 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
227 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
228 XBT_PRIVATE long long int instr_new_paje_id();
229 void instr_new_variable_type(std::string new_typename, std::string color);
230 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
231 void instr_new_user_state_type(std::string father_type, std::string new_typename);
232 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
233
234 /* instr_config.c */
235 XBT_PRIVATE void TRACE_TI_start();
236 XBT_PRIVATE void TRACE_TI_end();
237
238 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
239 XBT_PRIVATE void dump_comment_file(std::string filename);
240 XBT_PRIVATE void dump_comment(std::string comment);
241
242 enum e_caller_type {
243   TRACING_INIT,
244   TRACING_FINALIZE,
245   TRACING_COMM_SIZE,
246   TRACING_COMM_SPLIT,
247   TRACING_COMM_DUP,
248   TRACING_SEND,
249   TRACING_ISEND,
250   TRACING_SSEND,
251   TRACING_ISSEND,
252   TRACING_RECV,
253   TRACING_IRECV,
254   TRACING_SENDRECV,
255   TRACING_TEST,
256   TRACING_WAIT,
257   TRACING_WAITALL,
258   TRACING_WAITANY,
259   TRACING_BARRIER,
260   TRACING_BCAST,
261   TRACING_REDUCE,
262   TRACING_ALLREDUCE,
263   TRACING_ALLTOALL,
264   TRACING_ALLTOALLV,
265   TRACING_GATHER,
266   TRACING_GATHERV,
267   TRACING_SCATTER,
268   TRACING_SCATTERV,
269   TRACING_ALLGATHER,
270   TRACING_ALLGATHERV,
271   TRACING_REDUCE_SCATTER,
272   TRACING_COMPUTING,
273   TRACING_SLEEPING,
274   TRACING_SCAN,
275   TRACING_EXSCAN
276 };
277
278 struct s_instr_extra_data_t {
279   e_caller_type type;
280   int send_size;
281   int recv_size;
282   double comp_size;
283   double sleep_duration;
284   int src;
285   int dst;
286   int root;
287   const char* datatype1;
288   const char* datatype2;
289   int* sendcounts;
290   int* recvcounts;
291   int num_processes;
292 };
293 typedef s_instr_extra_data_t* instr_extra_data;
294
295 /* Format of TRACING output.
296  *   - paje is the regular format, that we all know
297  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
298  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
299  *     using the signal that we will create to cleanup the TRACING
300  */
301 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
302 extern instr_fmt_type_t instr_fmt_type;
303 }
304
305 #endif