Logo AND Algorithmique Numérique Distribuée

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