Logo AND Algorithmique Numérique Distribuée

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