Logo AND Algorithmique Numérique Distribuée

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