]> AND Public Git Repository - simgrid.git/blob - src/instr/instr_private.hpp
Logo AND Algorithmique Numérique Distribuée

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