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 #define drand48() (rand() / (RAND_MAX + 1.0))
33 typedef simgrid::instr::Container* container_t;
38 /* Format of TRACING output.
39 * - paje is the regular format, that we all know
40 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
41 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
42 * using the signal that we will create to cleanup the TRACING
44 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
45 extern TraceFormat trace_format;
54 std::shared_ptr<std::vector<int>> sendcounts = nullptr;
56 std::shared_ptr<std::vector<int>> recvcounts = nullptr;
57 std::string send_type = "";
58 std::string recv_type = "";
60 // NoOpTI: init, finalize, test, wait, barrier
61 explicit TIData(std::string name) : name_(name){};
62 // CPuTI: compute, sleep (+ waitAny and waitAll out of laziness)
63 explicit TIData(std::string name, double amount) : name_(name), amount_(amount){};
64 // Pt2PtTI: send, isend, sssend, issend, recv, irecv
65 explicit TIData(std::string name, int endpoint, int size, std::string datatype)
66 : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
67 // CollTI: bcast, reduce, allReduce, gather, scatter, allGather, allToAll
68 explicit TIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
69 std::string recv_type)
73 , send_size(send_size)
74 , recv_size(recv_size)
75 , send_type(send_type)
76 , recv_type(recv_type){};
77 // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
78 explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
79 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
80 : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
81 std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
83 explicit TIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
84 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
85 std::string recv_type)
88 , send_size(send_size)
89 , sendcounts(sendcounts)
90 , recv_size(recv_size)
91 , recvcounts(recvcounts)
92 , send_type(send_type)
93 , recv_type(recv_type){};
97 std::string getName() { return name_; }
98 double getAmount() { return amount_; }
99 virtual std::string print() = 0;
100 virtual std::string display_size() = 0;
103 class NoOpTIData : public TIData {
105 explicit NoOpTIData(std::string name) : TIData(name){};
106 std::string print() override { return getName(); }
107 std::string display_size() override { return ""; }
110 class CpuTIData : public TIData {
112 explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
113 std::string print() override
115 std::stringstream stream;
116 stream << getName() << " " << getAmount();
119 std::string display_size() override { return std::to_string(getAmount()); }
122 class Pt2PtTIData : public TIData {
125 explicit Pt2PtTIData(std::string name, int endpoint, int size, int tag, std::string datatype)
126 : TIData(name, endpoint, size, datatype), tag(tag) {};
128 explicit Pt2PtTIData(std::string name, int endpoint, int size, std::string datatype)
129 : TIData(name, endpoint, size, datatype), tag(0) {};
130 std::string print() override
132 std::stringstream stream;
133 stream << getName() << " ";
135 stream << endpoint << " ";
136 stream << tag << " " << send_size << " " << send_type;
139 std::string display_size() override { return std::to_string(send_size); }
142 class CollTIData : public TIData {
144 explicit CollTIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
145 std::string recv_type)
146 : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
147 std::string print() override
149 std::stringstream stream;
150 stream << getName() << " " << send_size << " ";
152 stream << recv_size << " ";
153 if (getAmount() >= 0.0)
154 stream << getAmount() << " ";
155 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
156 stream << endpoint << " ";
157 stream << send_type << " " << recv_type;
161 std::string display_size() override { return std::to_string(send_size); }
164 class VarCollTIData : public TIData {
166 explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
167 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
168 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
170 explicit VarCollTIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
171 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
172 std::string recv_type)
173 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
175 std::string print() override
177 std::stringstream stream;
178 stream << getName() << " ";
180 stream << send_size << " ";
181 if (sendcounts != nullptr)
182 for (auto count : *sendcounts)
183 stream << count << " ";
185 stream << recv_size << " ";
186 if (recvcounts != nullptr)
187 for (auto count : *recvcounts)
188 stream << count << " ";
189 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
190 stream << endpoint << " ";
191 stream << send_type << " " << recv_type;
195 std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
200 XBT_PRIVATE std::string instr_pid(s4u_Actor* proc);
202 extern XBT_PRIVATE std::set<std::string> created_categories;
203 extern XBT_PRIVATE std::set<std::string> declared_marks;
204 extern XBT_PRIVATE std::set<std::string> user_host_variables;
205 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
206 extern XBT_PRIVATE std::set<std::string> user_link_variables;
207 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
209 /* instr_paje_header.c */
210 XBT_PRIVATE void TRACE_header(bool basic, int size);
213 XBT_PRIVATE void TRACE_paje_start();
214 XBT_PRIVATE void TRACE_paje_end();
216 /* from instr_config.c */
217 XBT_PRIVATE bool TRACE_needs_platform();
218 XBT_PRIVATE bool TRACE_is_enabled();
219 XBT_PRIVATE bool TRACE_platform();
220 XBT_PRIVATE bool TRACE_platform_topology();
221 XBT_PRIVATE bool TRACE_categorized();
222 XBT_PRIVATE bool TRACE_uncategorized();
223 XBT_PRIVATE bool TRACE_actor_is_enabled();
224 XBT_PRIVATE bool TRACE_vm_is_enabled();
225 XBT_PRIVATE bool TRACE_buffer();
226 XBT_PRIVATE bool TRACE_disable_link();
227 XBT_PRIVATE bool TRACE_disable_speed();
228 XBT_PRIVATE bool TRACE_disable_destroy();
229 XBT_PRIVATE bool TRACE_basic();
230 XBT_PRIVATE bool TRACE_display_sizes();
231 XBT_PRIVATE int TRACE_precision();
233 /* Public functions used in SMPI */
234 XBT_PUBLIC bool TRACE_smpi_is_enabled();
235 XBT_PUBLIC bool TRACE_smpi_is_grouped();
236 XBT_PUBLIC bool TRACE_smpi_is_computing();
237 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
238 XBT_PUBLIC bool TRACE_smpi_view_internals();
240 /* from resource_utilization.c */
241 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
243 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
247 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
248 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
249 XBT_PRIVATE long long int instr_new_paje_id();
250 XBT_PRIVATE void instr_define_callbacks();
251 void instr_new_variable_type(std::string new_typename, std::string color);
252 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
253 void instr_new_user_state_type(std::string father_type, std::string new_typename);
254 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
257 XBT_PRIVATE void TRACE_TI_start();
258 XBT_PRIVATE void TRACE_TI_end();
259 XBT_PRIVATE void TRACE_global_init();
260 XBT_PRIVATE void TRACE_help(int detailed);
262 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
263 XBT_PRIVATE void dump_comment_file(std::string filename);
264 XBT_PRIVATE void dump_comment(std::string comment);
266 XBT_PRIVATE std::string TRACE_get_comment();
267 XBT_PRIVATE std::string TRACE_get_comment_file();
268 XBT_PRIVATE std::string TRACE_get_filename();