Logo AND Algorithmique Numérique Distribuée

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