Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
drand48 is not used anymore; stop using srand48.
[simgrid.git] / src / instr / instr_private.hpp
1 /* Copyright (c) 2010-2019. 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 "simgrid/instr.h"
12 #include "simgrid/s4u/Actor.hpp"
13 #include "src/instr/instr_paje_containers.hpp"
14 #include "src/instr/instr_paje_events.hpp"
15 #include "src/instr/instr_paje_types.hpp"
16 #include "src/instr/instr_paje_values.hpp"
17 #include "xbt/graph.h"
18
19 #include <fstream>
20 #include <iomanip> /** std::setprecision **/
21 #include <iostream>
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <sstream>
26 #include <string>
27 #include <sys/stat.h>
28 #ifdef WIN32
29 #include <direct.h> // _mkdir
30 #endif
31
32 typedef simgrid::instr::Container* container_t;
33
34 namespace simgrid {
35 namespace instr {
36
37 /* Format of TRACING output.
38  *   - paje is the regular format, that we all know
39  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
40  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
41  *     using the signal that we will create to cleanup the TRACING
42  */
43 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
44 extern TraceFormat trace_format;
45
46 class TIData {
47   std::string name_;
48   double amount_ = 0;
49
50 public:
51   int endpoint                 = 0;
52   int send_size                = 0;
53   std::shared_ptr<std::vector<int>> sendcounts = nullptr;
54   int recv_size                = 0;
55   std::shared_ptr<std::vector<int>> recvcounts = nullptr;
56   std::string send_type        = "";
57   std::string recv_type        = "";
58
59   // NoOpTI: init, finalize, test, wait, barrier
60   explicit TIData(const std::string& name) : name_(name){};
61   // CPuTI: compute, sleep (+ waitAny and waitall out of laziness)
62   explicit TIData(const std::string& name, double amount) : name_(name), amount_(amount){};
63   // Pt2PtTI: send, isend, sssend, issend, recv, irecv
64   explicit TIData(const std::string& name, int endpoint, int size, const std::string& datatype)
65       : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
66   // CollTI: bcast, reduce, allreduce, gather, scatter, allgather, alltoall
67   explicit TIData(const std::string& name, int root, double amount, int send_size, int recv_size,
68                   const std::string& send_type, const std::string& recv_type)
69       : name_(name)
70       , amount_(amount)
71       , endpoint(root)
72       , send_size(send_size)
73       , recv_size(recv_size)
74       , send_type(send_type)
75       , recv_type(recv_type){};
76   // VarCollTI: gatherv, scatterv, allgatherv, alltoallv (+ reducescatter out of laziness)
77   explicit TIData(const std::string& name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
78                   std::vector<int>* recvcounts, const std::string& send_type, const std::string& recv_type)
79       : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
80                std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
81
82   explicit TIData(const std::string& name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
83                   int recv_size, std::shared_ptr<std::vector<int>> recvcounts, const std::string& send_type,
84                   const std::string& recv_type)
85       : name_(name)
86       , endpoint(root)
87       , send_size(send_size)
88       , sendcounts(sendcounts)
89       , recv_size(recv_size)
90       , recvcounts(recvcounts)
91       , send_type(send_type)
92       , recv_type(recv_type){};
93
94   virtual ~TIData() {}
95
96   const std::string& getName() const { return name_; }
97   double getAmount() { return amount_; }
98   virtual std::string print()        = 0;
99   virtual std::string display_size() = 0;
100 };
101
102 class NoOpTIData : public TIData {
103 public:
104   explicit NoOpTIData(const std::string& name) : TIData(name){};
105   std::string print() override { return getName(); }
106   std::string display_size() override { return "NA"; }
107 };
108
109 class CpuTIData : public TIData {
110 public:
111   explicit CpuTIData(const std::string& name, double amount) : TIData(name, amount){};
112   std::string print() override
113   {
114     std::stringstream stream;
115     stream << getName() << " " << getAmount();
116     return stream.str();
117   }
118   std::string display_size() override { return std::to_string(getAmount()); }
119 };
120
121 class Pt2PtTIData : public TIData {
122   int tag;
123 public:
124   explicit Pt2PtTIData(const std::string& name, int endpoint, int size, int tag, const std::string& datatype)
125       : TIData(name, endpoint, size, datatype), tag(tag){};
126
127   explicit Pt2PtTIData(const std::string& name, int endpoint, int size, const std::string& datatype)
128       : TIData(name, endpoint, size, datatype), tag(0){};
129   std::string print() override
130   {
131     std::stringstream stream;
132     stream << getName() << " " << endpoint << " ";
133     stream << tag << " " << send_size << " " << send_type;
134     return stream.str();
135   }
136   std::string display_size() override { return std::to_string(send_size); }
137 };
138
139 class CollTIData : public TIData {
140 public:
141   explicit CollTIData(const std::string& name, int root, double amount, int send_size, int recv_size,
142                       const std::string& send_type, const std::string& recv_type)
143       : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
144   std::string print() override
145   {
146     std::stringstream stream;
147     stream << getName() << " " << send_size << " ";
148     if (recv_size >= 0)
149       stream << recv_size << " ";
150     if (getAmount() >= 0.0)
151       stream << getAmount() << " ";
152     if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
153       stream << endpoint << " ";
154     stream << send_type << " " << recv_type;
155
156     return stream.str();
157   }
158   std::string display_size() override { return std::to_string(send_size); }
159 };
160
161 class VarCollTIData : public TIData {
162 public:
163   explicit VarCollTIData(const std::string& name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
164                          std::vector<int>* recvcounts, const std::string& send_type, const std::string& recv_type)
165       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
166
167   explicit VarCollTIData(const std::string& name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
168                          int recv_size, std::shared_ptr<std::vector<int>> recvcounts, const std::string& send_type,
169                          const std::string& recv_type)
170       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
171
172   std::string print() override
173   {
174     std::stringstream stream;
175     stream << getName() << " ";
176     if (send_size >= 0)
177       stream << send_size << " ";
178     if (sendcounts != nullptr)
179       for (auto count : *sendcounts)
180         stream << count << " ";
181     if (recv_size >= 0)
182       stream << recv_size << " ";
183     if (recvcounts != nullptr)
184       for (auto count : *recvcounts)
185         stream << count << " ";
186     if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
187       stream << endpoint << " ";
188     stream << send_type << " " << recv_type;
189
190     return stream.str();
191   }
192   std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
193 };
194
195 /**
196  * If we want to wait for a request of asynchronous communication, we need to be able
197  * to identify this request. We do this by searching for a request identified by (src, dest, tag).
198  */
199 class WaitTIData : public TIData {
200   int src;
201   int dest;
202   int tag;
203
204 public:
205   explicit WaitTIData(int src, int dest, int tag) : TIData("wait"), src(src), dest(dest), tag(tag){};
206
207   std::string print() override
208   {
209     std::stringstream stream;
210     stream << getName() << " " << src << " " << dest << " " << tag;
211
212     return stream.str();
213   }
214
215   std::string display_size() override { return "NA"; }
216 };
217
218 class AmpiMigrateTIData : public TIData {
219   size_t memory_consumption;
220 public:
221   explicit AmpiMigrateTIData(size_t memory_conso) : TIData("migrate"), memory_consumption(memory_conso) { };
222
223   std::string print() override
224   {
225     std::stringstream stream;
226     stream << getName() << " " << memory_consumption;
227
228     return stream.str();
229   }
230
231   std::string display_size() override { return "NA"; }
232 };
233 }
234 }
235
236 XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc);
237
238 extern XBT_PRIVATE std::set<std::string> created_categories;
239 extern XBT_PRIVATE std::set<std::string> declared_marks;
240 extern XBT_PRIVATE std::set<std::string> user_host_variables;
241 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
242 extern XBT_PRIVATE std::set<std::string> user_link_variables;
243 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
244
245 /* instr_paje_header.c */
246 XBT_PRIVATE void TRACE_header(bool basic, bool size);
247
248 /* from instr_config.c */
249 XBT_PRIVATE bool TRACE_needs_platform();
250 XBT_PRIVATE bool TRACE_is_enabled();
251 XBT_PRIVATE bool TRACE_platform();
252 XBT_PRIVATE bool TRACE_platform_topology();
253 XBT_PRIVATE bool TRACE_categorized();
254 XBT_PRIVATE bool TRACE_uncategorized();
255 XBT_PRIVATE bool TRACE_actor_is_enabled();
256 XBT_PRIVATE bool TRACE_vm_is_enabled();
257 XBT_PRIVATE bool TRACE_disable_link();
258 XBT_PRIVATE bool TRACE_disable_speed();
259 XBT_PRIVATE bool TRACE_disable_destroy();
260 XBT_PRIVATE bool TRACE_basic();
261 XBT_PRIVATE bool TRACE_display_sizes();
262 XBT_PRIVATE int TRACE_precision();
263
264 /* Public functions used in SMPI */
265 XBT_PUBLIC bool TRACE_smpi_is_enabled();
266 XBT_PUBLIC bool TRACE_smpi_is_grouped();
267 XBT_PUBLIC bool TRACE_smpi_is_computing();
268 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
269 XBT_PUBLIC bool TRACE_smpi_view_internals();
270
271 XBT_PRIVATE void TRACE_surf_resource_set_utilization(const char* type, const char* name, const char* resource,
272                                                      const std::string& category, double value, double now,
273                                                      double delta);
274
275 /* instr_paje.c */
276 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
277 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
278 XBT_PRIVATE long long int instr_new_paje_id();
279 XBT_PRIVATE void instr_define_callbacks();
280 void instr_new_variable_type(const std::string& new_typename, const std::string& color);
281 void instr_new_user_variable_type(const std::string& father_type, const std::string& new_typename,
282                                   const std::string& color);
283 void instr_new_user_state_type(const std::string& father_type, const std::string& new_typename);
284 void instr_new_value_for_user_state_type(const std::string& new_typename, const char* value, const std::string& color);
285
286 XBT_PRIVATE void TRACE_global_init();
287 XBT_PRIVATE void TRACE_help();
288
289 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
290 XBT_PRIVATE void dump_comment_file(const std::string& filename);
291 XBT_PRIVATE void dump_comment(const std::string& comment);
292
293 XBT_PRIVATE std::string TRACE_get_filename();
294
295 /* instr_platform */
296 xbt_graph_t instr_routing_platform_graph();
297 void instr_routing_platform_graph_export_graphviz(xbt_graph_t g, const char* filename);
298
299 #endif