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/s4u/Actor.hpp"
13 #include "simgrid_config.h"
14 #include "src/instr/instr_paje_containers.hpp"
15 #include "src/instr/instr_paje_events.hpp"
16 #include "src/instr/instr_paje_types.hpp"
17 #include "src/instr/instr_paje_values.hpp"
18 #include "src/internal_config.h"
19 #include "xbt/graph.h"
22 #include <iomanip> /** std::setprecision **/
31 #include <direct.h> // _mkdir
32 /* Need to define function drand48 for Windows */
33 #define drand48() (rand() / (RAND_MAX + 1.0))
36 typedef simgrid::instr::Container* container_t;
41 /* Format of TRACING output.
42 * - paje is the regular format, that we all know
43 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
44 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
45 * using the signal that we will create to cleanup the TRACING
47 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
48 extern TraceFormat trace_format;
57 std::shared_ptr<std::vector<int>> sendcounts = nullptr;
59 std::shared_ptr<std::vector<int>> recvcounts = nullptr;
60 std::string send_type = "";
61 std::string recv_type = "";
63 // NoOpTI: init, finalize, test, wait, barrier
64 explicit TIData(std::string name) : name_(name){};
65 // CPuTI: compute, sleep (+ waitAny and waitAll out of laziness)
66 explicit TIData(std::string name, double amount) : name_(name), amount_(amount){};
67 // Pt2PtTI: send, isend, sssend, issend, recv, irecv
68 explicit TIData(std::string name, int endpoint, int size, std::string datatype)
69 : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
70 // CollTI: bcast, reduce, allReduce, gather, scatter, allGather, allToAll
71 explicit TIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
72 std::string recv_type)
76 , send_size(send_size)
77 , recv_size(recv_size)
78 , send_type(send_type)
79 , recv_type(recv_type){};
80 // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
81 explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
82 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
83 : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
84 std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
86 explicit TIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
87 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
88 std::string recv_type)
91 , send_size(send_size)
92 , sendcounts(sendcounts)
93 , recv_size(recv_size)
94 , recvcounts(recvcounts)
95 , send_type(send_type)
96 , recv_type(recv_type){};
100 std::string getName() { return name_; }
101 double getAmount() { return amount_; }
102 virtual std::string print() = 0;
103 virtual std::string display_size() = 0;
106 class NoOpTIData : public TIData {
108 explicit NoOpTIData(std::string name) : TIData(name){};
109 std::string print() override { return getName(); }
110 std::string display_size() override { return ""; }
113 class CpuTIData : public TIData {
115 explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
116 std::string print() override
118 std::stringstream stream;
119 stream << getName() << " " << getAmount();
122 std::string display_size() override { return std::to_string(getAmount()); }
125 class Pt2PtTIData : public TIData {
128 explicit Pt2PtTIData(std::string name, int endpoint, int size, int tag, std::string datatype)
129 : TIData(name, endpoint, size, datatype), tag(tag) {};
131 explicit Pt2PtTIData(std::string name, int endpoint, int size, std::string datatype)
132 : TIData(name, endpoint, size, datatype), tag(0) {};
133 std::string print() override
135 std::stringstream stream;
136 stream << getName() << " ";
138 stream << 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(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
148 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 << getName() << " " << send_size << " ";
155 stream << recv_size << " ";
156 if (getAmount() >= 0.0)
157 stream << getAmount() << " ";
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(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
170 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
171 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
173 explicit VarCollTIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
174 int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
175 std::string recv_type)
176 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
178 std::string print() override
180 std::stringstream stream;
181 stream << getName() << " ";
183 stream << send_size << " ";
184 if (sendcounts != nullptr)
185 for (auto count : *sendcounts)
186 stream << count << " ";
188 stream << recv_size << " ";
189 if (recvcounts != nullptr)
190 for (auto count : *recvcounts)
191 stream << count << " ";
192 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
193 stream << endpoint << " ";
194 stream << send_type << " " << recv_type;
198 std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
203 XBT_PRIVATE std::string instr_pid(s4u_Actor* proc);
205 extern XBT_PRIVATE std::set<std::string> created_categories;
206 extern XBT_PRIVATE std::set<std::string> declared_marks;
207 extern XBT_PRIVATE std::set<std::string> user_host_variables;
208 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
209 extern XBT_PRIVATE std::set<std::string> user_link_variables;
210 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
212 /* instr_paje_header.c */
213 XBT_PRIVATE void TRACE_header(bool basic, bool size);
215 /* from instr_config.c */
216 XBT_PRIVATE bool TRACE_needs_platform();
217 XBT_PRIVATE bool TRACE_is_enabled();
218 XBT_PRIVATE bool TRACE_platform();
219 XBT_PRIVATE bool TRACE_platform_topology();
220 XBT_PRIVATE bool TRACE_categorized();
221 XBT_PRIVATE bool TRACE_uncategorized();
222 XBT_PRIVATE bool TRACE_actor_is_enabled();
223 XBT_PRIVATE bool TRACE_vm_is_enabled();
224 XBT_PRIVATE bool TRACE_disable_link();
225 XBT_PRIVATE bool TRACE_disable_speed();
226 XBT_PRIVATE bool TRACE_disable_destroy();
227 XBT_PRIVATE bool TRACE_basic();
228 XBT_PRIVATE bool TRACE_display_sizes();
229 XBT_PRIVATE int TRACE_precision();
231 /* Public functions used in SMPI */
232 XBT_PUBLIC bool TRACE_smpi_is_enabled();
233 XBT_PUBLIC bool TRACE_smpi_is_grouped();
234 XBT_PUBLIC bool TRACE_smpi_is_computing();
235 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
236 XBT_PUBLIC bool TRACE_smpi_view_internals();
238 XBT_PRIVATE void TRACE_surf_resource_set_utilization(const char* type, const char* name, const char* resource,
239 const char* category, double value, double now, double delta);
242 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
243 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
244 XBT_PRIVATE long long int instr_new_paje_id();
245 XBT_PRIVATE void instr_define_callbacks();
246 void instr_new_variable_type(std::string new_typename, std::string color);
247 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
248 void instr_new_user_state_type(std::string father_type, std::string new_typename);
249 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
251 XBT_PRIVATE void TRACE_global_init();
252 XBT_PRIVATE void TRACE_help();
254 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
255 XBT_PRIVATE void dump_comment_file(std::string filename);
256 XBT_PRIVATE void dump_comment(std::string comment);
258 XBT_PRIVATE std::string TRACE_get_filename();