Logo AND Algorithmique Numérique Distribuée

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