Logo AND Algorithmique Numérique Distribuée

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