1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef INSTR_PRIVATE_HPP
7 #define INSTR_PRIVATE_HPP
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"
19 #include <iomanip> /** std::setprecision **/
31 void dump_generator_version();
32 void dump_comment_file(const std::string& filename);
33 void dump_header(bool basic, bool display_sizes);
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
42 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
43 extern TraceFormat trace_format;
44 extern int trace_precision;
45 extern double last_timestamp_to_dump;
48 void define_callbacks();
50 void platform_graph_export_graphviz(const std::string& output_filename);
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);
63 std::shared_ptr<std::vector<int>> sendcounts = nullptr;
65 std::shared_ptr<std::vector<int>> recvcounts = nullptr;
66 std::string send_type = "";
67 std::string recv_type = "";
69 // NoOpTI: init, finalize, test, wait, barrier
70 explicit TIData(const std::string& name) : name_(name){};
71 // CPuTI: compute, sleep (+ waitAny and waitall out of laziness)
72 explicit TIData(const std::string& name, double amount) : name_(name), amount_(amount){};
73 // Pt2PtTI: send, isend, ssend, issend, recv, irecv
74 explicit TIData(const std::string& name, int endpoint, int size, const std::string& datatype)
75 : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
76 // CollTI: bcast, reduce, allreduce, gather, scatter, allgather, alltoall
77 explicit TIData(const std::string& name, int root, double amount, int send_size, int recv_size,
78 const std::string& send_type, const std::string& recv_type)
82 , send_size(send_size)
83 , recv_size(recv_size)
84 , send_type(send_type)
85 , recv_type(recv_type){};
86 // VarCollTI: gatherv, scatterv, allgatherv, alltoallv (+ reducescatter out of laziness)
87 explicit TIData(const std::string& name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
88 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, const std::string& send_type,
89 const std::string& recv_type)
92 , send_size(send_size)
93 , sendcounts(sendcounts)
94 , recv_size(recv_size)
95 , recvcounts(recvcounts)
96 , send_type(send_type)
97 , recv_type(recv_type){};
99 virtual ~TIData() = default;
101 const std::string& get_name() const { return name_; }
102 double get_amount() const { return amount_; }
103 virtual std::string print() = 0;
104 virtual std::string display_size() = 0;
107 class NoOpTIData : public TIData {
109 explicit NoOpTIData(const std::string& name) : TIData(name){};
110 std::string print() override { return get_name(); }
111 std::string display_size() override { return "NA"; }
114 class CpuTIData : public TIData {
116 explicit CpuTIData(const std::string& name, double amount) : TIData(name, amount){};
117 std::string print() override
119 std::stringstream stream;
120 stream << get_name() << " " << get_amount();
123 std::string display_size() override { return std::to_string(get_amount()); }
126 class Pt2PtTIData : public TIData {
130 explicit Pt2PtTIData(const std::string& name, int endpoint, int size, int tag, const std::string& datatype)
131 : TIData(name, endpoint, size, datatype), tag(tag){};
133 explicit Pt2PtTIData(const std::string& name, int endpoint, int size, const std::string& datatype)
134 : TIData(name, endpoint, size, datatype){};
135 std::string print() override
137 std::stringstream stream;
138 stream << get_name() << " " << endpoint << " ";
139 stream << tag << " " << send_size << " " << send_type;
142 std::string display_size() override { return std::to_string(send_size); }
145 class CollTIData : public TIData {
147 explicit CollTIData(const std::string& name, int root, double amount, int send_size, int recv_size,
148 const std::string& send_type, const std::string& recv_type)
149 : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
150 std::string print() override
152 std::stringstream stream;
153 stream << get_name() << " " << send_size << " ";
155 stream << recv_size << " ";
156 if (get_amount() >= 0.0)
157 stream << get_amount() << " ";
158 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
159 stream << endpoint << " ";
160 stream << send_type << " " << recv_type;
164 std::string display_size() override { return std::to_string(send_size); }
167 class VarCollTIData : public TIData {
169 explicit VarCollTIData(const std::string& name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
170 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, const std::string& send_type,
171 const std::string& recv_type)
172 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
174 std::string print() override
176 std::stringstream stream;
177 stream << get_name() << " ";
179 stream << send_size << " ";
180 if (sendcounts != nullptr)
181 for (auto count : *sendcounts)
182 stream << count << " ";
184 stream << recv_size << " ";
185 if (recvcounts != nullptr)
186 for (auto count : *recvcounts)
187 stream << count << " ";
188 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
189 stream << endpoint << " ";
190 stream << send_type << " " << recv_type;
194 std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
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).
201 class WaitTIData : public TIData {
207 explicit WaitTIData(int src, int dest, int tag) : TIData("wait"), src(src), dest(dest), tag(tag){};
209 std::string print() override
211 std::stringstream stream;
212 stream << get_name() << " " << src << " " << dest << " " << tag;
217 std::string display_size() override { return "NA"; }
220 class AmpiMigrateTIData : public TIData {
221 size_t memory_consumption;
223 explicit AmpiMigrateTIData(size_t memory_conso) : TIData("migrate"), memory_consumption(memory_conso) { };
225 std::string print() override
227 std::stringstream stream;
228 stream << get_name() << " " << memory_consumption;
233 std::string display_size() override { return "NA"; }
236 } // namespace simgrid
238 XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc);
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;
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();
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();
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& father_type, const std::string& new_typename,
269 const std::string& color);
270 void instr_new_user_state_type(const std::string& father_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);
273 XBT_PRIVATE void TRACE_help();