Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / instr / instr_private.hpp
1 /* Copyright (c) 2010-2022. 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   explicit TIData(const std::string& name) : name_(name){};
62   explicit TIData(const std::string& name, double amount) : name_(name), amount_(amount){};
63
64   virtual ~TIData() = default;
65
66   const std::string& get_name() const { return name_; }
67   double get_amount() const { return amount_; }
68   virtual std::string print()        = 0;
69   virtual std::string display_size() = 0;
70 };
71
72 // NoOpTI: init, finalize, test, wait, barrier
73 class NoOpTIData : public TIData {
74   explicit NoOpTIData(const std::string&, double); // disallow this constructor inherited from TIData
75
76 public:
77   using TIData::TIData;
78   std::string print() override { return get_name(); }
79   std::string display_size() override { return "NA"; }
80 };
81
82 // CPuTI: compute, sleep (+ waitAny and waitall out of laziness)
83 class CpuTIData : public TIData {
84   explicit CpuTIData(const std::string&); // disallow this constructor inherited from TIData
85
86 public:
87   using TIData::TIData;
88   std::string print() override
89   {
90     std::stringstream stream;
91     stream << get_name() << " " << get_amount();
92     return stream.str();
93   }
94   std::string display_size() override { return std::to_string(get_amount()); }
95 };
96
97 // Pt2PtTI: send, isend, ssend, issend, recv, irecv
98 class Pt2PtTIData : public TIData {
99   int endpoint_;
100   size_t size_;
101   std::string type_;
102   int tag_ = 0;
103
104 public:
105   Pt2PtTIData(const std::string& name, int endpoint, size_t size, const std::string& datatype)
106       : TIData(name), endpoint_(endpoint), size_(size), type_(datatype){};
107   Pt2PtTIData(const std::string& name, int endpoint, size_t size, int tag, const std::string& datatype)
108       : TIData(name), endpoint_(endpoint), size_(size), type_(datatype), tag_(tag){};
109
110   std::string print() override
111   {
112     std::stringstream stream;
113     stream << get_name() << " " << endpoint_ << " " << tag_ << " " << size_ << " " << type_;
114     return stream.str();
115   }
116   std::string display_size() override { return std::to_string(size_); }
117 };
118
119 // CollTI: bcast, reduce, allreduce, gather, scatter, allgather, alltoall
120 class CollTIData : public TIData {
121   int root_;
122   size_t send_size_;
123   size_t recv_size_;
124   std::string send_type_;
125   std::string recv_type_;
126
127 public:
128   CollTIData(const std::string& name, int root, double amount, size_t send_size, size_t recv_size,
129              const std::string& send_type, const std::string& recv_type)
130       : TIData(name, amount)
131       , root_(root)
132       , send_size_(send_size)
133       , recv_size_(recv_size)
134       , send_type_(send_type)
135       , recv_type_(recv_type){};
136
137   std::string print() override
138   {
139     std::stringstream stream;
140     stream << get_name() << " " << send_size_ << " ";
141     if (recv_size_ > 0)
142       stream << recv_size_ << " ";
143     if (get_amount() >= 0.0)
144       stream << get_amount() << " ";
145     if (root_ > 0 || (root_ == 0 && not send_type_.empty()))
146       stream << root_ << " ";
147     stream << send_type_ << " " << recv_type_;
148
149     return stream.str();
150   }
151   std::string display_size() override { return std::to_string(send_size_); }
152 };
153
154 // VarCollTI: gatherv, scatterv, allgatherv, alltoallv (+ reducescatter out of laziness)
155 class VarCollTIData : public TIData {
156   int root_;
157   long int send_size_;
158   std::shared_ptr<std::vector<int>> sendcounts_;
159   long int recv_size_;
160   std::shared_ptr<std::vector<int>> recvcounts_;
161   std::string send_type_;
162   std::string recv_type_;
163
164 public:
165   VarCollTIData(const std::string& name, int root, long int send_size, std::shared_ptr<std::vector<int>> sendcounts,
166                 long int recv_size, std::shared_ptr<std::vector<int>> recvcounts, const std::string& send_type,
167                 const std::string& recv_type)
168       : TIData(name)
169       , root_(root)
170       , send_size_(send_size)
171       , sendcounts_(sendcounts)
172       , recv_size_(recv_size)
173       , recvcounts_(recvcounts)
174       , send_type_(send_type)
175       , recv_type_(recv_type){};
176
177   std::string print() override
178   {
179     std::stringstream stream;
180     stream << get_name() << " ";
181     if (send_size_ > -1)
182       stream << send_size_ << " ";
183     if (sendcounts_ != nullptr)
184       for (auto count : *sendcounts_)
185         stream << count << " ";
186     if (recv_size_ > -1)
187       stream << recv_size_ << " ";
188     if (recvcounts_ != nullptr)
189       for (auto count : *recvcounts_)
190         stream << count << " ";
191     if (root_ > 0 || (root_ == 0 && not send_type_.empty()))
192       stream << root_ << " ";
193     stream << send_type_ << " " << recv_type_;
194
195     return stream.str();
196   }
197   std::string display_size() override { return std::to_string(send_size_ > 0 ? send_size_ : recv_size_); }
198 };
199
200 /**
201  * If we want to wait for a request of asynchronous communication, we need to be able
202  * to identify this request. We do this by searching for a request identified by (src, dest, tag).
203  */
204 class WaitTIData : public TIData {
205   int src_;
206   int dest_;
207   int tag_;
208
209 public:
210   WaitTIData(int src, int dest, int tag) : TIData("wait"), src_(src), dest_(dest), tag_(tag){};
211
212   std::string print() override
213   {
214     std::stringstream stream;
215     stream << get_name() << " " << src_ << " " << dest_ << " " << tag_;
216     return stream.str();
217   }
218   std::string display_size() override { return "NA"; }
219 };
220
221 class AmpiMigrateTIData : public TIData {
222   size_t memory_consumption_;
223
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 << get_name() << " " << memory_consumption_;
231     return stream.str();
232   }
233   std::string display_size() override { return "NA"; }
234 };
235 } // namespace instr
236 } // namespace simgrid
237
238 XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc);
239
240 extern XBT_PRIVATE std::set<std::string, std::less<>> created_categories;
241 extern XBT_PRIVATE std::set<std::string, std::less<>> declared_marks;
242 extern XBT_PRIVATE std::set<std::string, std::less<>> user_host_variables;
243 extern XBT_PRIVATE std::set<std::string, std::less<>> user_vm_variables;
244 extern XBT_PRIVATE std::set<std::string, std::less<>> user_link_variables;
245
246 /* from instr_config.c */
247 XBT_PRIVATE bool TRACE_needs_platform();
248 XBT_PRIVATE bool TRACE_is_enabled();
249 XBT_PRIVATE bool TRACE_platform();
250 XBT_PRIVATE bool TRACE_platform_topology();
251 XBT_PRIVATE bool TRACE_categorized();
252 XBT_PRIVATE bool TRACE_uncategorized();
253 XBT_PRIVATE bool TRACE_actor_is_enabled();
254 XBT_PRIVATE bool TRACE_vm_is_enabled();
255 XBT_PRIVATE bool TRACE_disable_link();
256 XBT_PRIVATE bool TRACE_disable_speed();
257 XBT_PRIVATE bool TRACE_display_sizes();
258
259 /* Public functions used in SMPI */
260 XBT_PUBLIC bool TRACE_smpi_is_enabled();
261 XBT_PUBLIC bool TRACE_smpi_is_grouped();
262 XBT_PUBLIC bool TRACE_smpi_is_computing();
263 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
264 XBT_PUBLIC bool TRACE_smpi_view_internals();
265
266 /* instr_paje.c */
267 void instr_new_variable_type(const std::string& new_typename, const std::string& color);
268 void instr_new_user_variable_type(const std::string& parent_type, const std::string& new_typename,
269                                   const std::string& color);
270 void instr_new_user_state_type(const std::string& parent_type, const std::string& new_typename);
271 void instr_new_value_for_user_state_type(const std::string& new_typename, const char* value, const std::string& color);
272
273 XBT_PRIVATE void TRACE_help();
274
275 #endif