Logo AND Algorithmique Numérique Distribuée

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