Logo AND Algorithmique Numérique Distribuée

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