1 /* Copyright (c) 2010-2018. 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_config.h"
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 "src/internal_config.h"
18 #include "xbt/graph.h"
20 #include <iomanip> /** std::setprecision **/
28 #include <direct.h> // _mkdir
29 /* Need to define function drand48 for Windows */
30 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
31 #define drand48() (rand() / (RAND_MAX + 1.0))
34 typedef simgrid::instr::Container* container_t;
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
45 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
46 extern TraceFormat trace_format;
55 std::shared_ptr<std::vector<int>> sendcounts = nullptr;
57 std::shared_ptr<std::vector<int>> recvcounts = nullptr;
58 std::string send_type = "";
59 std::string recv_type = "";
61 // NoOpTI: init, finalize, test, wait, barrier
62 explicit TIData(std::string name) : name_(name){};
63 // CPuTI: compute, sleep (+ waitAny and waitAll out of laziness)
64 explicit TIData(std::string name, double amount) : name_(name), amount_(amount){};
65 // Pt2PtTI: send, isend, sssend, issend, recv, irecv
66 explicit TIData(std::string name, int endpoint, int size, std::string datatype)
67 : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
68 // CollTI: bcast, reduce, allReduce, gather, scatter, allGather, allToAll
69 explicit TIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
70 std::string recv_type)
74 , send_size(send_size)
75 , recv_size(recv_size)
76 , send_type(send_type)
77 , recv_type(recv_type){};
78 // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
79 explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
80 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
81 : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
82 std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
84 explicit TIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
85 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
86 std::string recv_type)
89 , send_size(send_size)
90 , sendcounts(sendcounts)
91 , recv_size(recv_size)
92 , recvcounts(recvcounts)
93 , send_type(send_type)
94 , recv_type(recv_type){};
98 std::string getName() { return name_; }
99 double getAmount() { return amount_; }
100 virtual std::string print() = 0;
101 virtual std::string display_size() = 0;
104 class NoOpTIData : public TIData {
106 explicit NoOpTIData(std::string name) : TIData(name){};
107 std::string print() override { return getName(); }
108 std::string display_size() override { return ""; }
111 class CpuTIData : public TIData {
113 explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
114 std::string print() override
116 std::stringstream stream;
117 stream << getName() << " " << getAmount();
120 std::string display_size() override { return std::to_string(getAmount()); }
123 class Pt2PtTIData : public TIData {
126 explicit Pt2PtTIData(std::string name, int endpoint, int size, int tag, std::string datatype)
127 : TIData(name, endpoint, size, datatype), tag(tag) {};
129 explicit Pt2PtTIData(std::string name, int endpoint, int size, std::string datatype)
130 : TIData(name, endpoint, size, datatype), tag(0) {};
131 std::string print() override
133 std::stringstream stream;
134 stream << getName() << " ";
136 stream << endpoint << " ";
137 stream << tag << " " << send_size << " " << send_type;
140 std::string display_size() override { return std::to_string(send_size); }
143 class CollTIData : public TIData {
145 explicit CollTIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
146 std::string recv_type)
147 : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
148 std::string print() override
150 std::stringstream stream;
151 stream << getName() << " " << send_size << " ";
153 stream << recv_size << " ";
154 if (getAmount() >= 0.0)
155 stream << getAmount() << " ";
156 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
157 stream << endpoint << " ";
158 stream << send_type << " " << recv_type;
162 std::string display_size() override { return std::to_string(send_size); }
165 class VarCollTIData : public TIData {
167 explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
168 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
169 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
171 explicit VarCollTIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
172 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
173 std::string recv_type)
174 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
176 std::string print() override
178 std::stringstream stream;
179 stream << getName() << " ";
181 stream << send_size << " ";
182 if (sendcounts != nullptr)
183 for (auto count : *sendcounts)
184 stream << count << " ";
186 stream << recv_size << " ";
187 if (recvcounts != nullptr)
188 for (auto count : *recvcounts)
189 stream << count << " ";
190 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
191 stream << endpoint << " ";
192 stream << send_type << " " << recv_type;
196 std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
201 XBT_PRIVATE std::string instr_pid(s4u_Actor* proc);
203 extern XBT_PRIVATE std::set<std::string> created_categories;
204 extern XBT_PRIVATE std::set<std::string> declared_marks;
205 extern XBT_PRIVATE std::set<std::string> user_host_variables;
206 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
207 extern XBT_PRIVATE std::set<std::string> user_link_variables;
208 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
210 /* instr_paje_header.c */
211 XBT_PRIVATE void TRACE_header(bool basic, int size);
214 XBT_PRIVATE void TRACE_paje_start();
215 XBT_PRIVATE void TRACE_paje_end();
217 /* from instr_config.c */
218 XBT_PRIVATE bool TRACE_needs_platform();
219 XBT_PRIVATE bool TRACE_is_enabled();
220 XBT_PRIVATE bool TRACE_platform();
221 XBT_PRIVATE bool TRACE_platform_topology();
222 XBT_PRIVATE bool TRACE_categorized();
223 XBT_PRIVATE bool TRACE_uncategorized();
224 XBT_PRIVATE bool TRACE_actor_is_enabled();
225 XBT_PRIVATE bool TRACE_vm_is_enabled();
226 XBT_PRIVATE bool TRACE_buffer();
227 XBT_PRIVATE bool TRACE_disable_link();
228 XBT_PRIVATE bool TRACE_disable_speed();
229 XBT_PRIVATE bool TRACE_disable_destroy();
230 XBT_PRIVATE bool TRACE_basic();
231 XBT_PRIVATE bool TRACE_display_sizes();
232 XBT_PRIVATE int TRACE_precision();
234 /* Public functions used in SMPI */
235 XBT_PUBLIC bool TRACE_smpi_is_enabled();
236 XBT_PUBLIC bool TRACE_smpi_is_grouped();
237 XBT_PUBLIC bool TRACE_smpi_is_computing();
238 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
239 XBT_PUBLIC bool TRACE_smpi_view_internals();
241 /* from resource_utilization.c */
242 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
244 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
248 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
249 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
250 XBT_PRIVATE long long int instr_new_paje_id();
251 XBT_PRIVATE void instr_define_callbacks();
252 void instr_new_variable_type(std::string new_typename, std::string color);
253 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
254 void instr_new_user_state_type(std::string father_type, std::string new_typename);
255 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
258 XBT_PRIVATE void TRACE_start();
259 XBT_PRIVATE void TRACE_TI_start();
260 XBT_PRIVATE void TRACE_TI_end();
261 XBT_PRIVATE void TRACE_end();
262 XBT_PRIVATE void TRACE_global_init();
263 XBT_PRIVATE void TRACE_help(int detailed);
265 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
266 XBT_PRIVATE void dump_comment_file(std::string filename);
267 XBT_PRIVATE void dump_comment(std::string comment);
269 XBT_PRIVATE std::string TRACE_get_comment();
270 XBT_PRIVATE std::string TRACE_get_comment_file();
271 XBT_PRIVATE std::string TRACE_get_filename();