1 /* Copyright (c) 2010-2017. 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 "instr/instr_interface.h"
12 #include "simgrid/instr.h"
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"
20 #include <iomanip> /** std::setprecision **/
27 #include <direct.h> // _mkdir
28 /* Need to define function drand48 for Windows */
29 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
30 #define drand48() (rand() / (RAND_MAX + 1.0))
33 typedef simgrid::instr::Container* container_t;
45 std::vector<int>* sendcounts = nullptr;
47 std::vector<int>* recvcounts = nullptr;
48 std::string send_type = "";
49 std::string recv_type = "";
52 // NoOpTI: init, finalize, test, wait, barrier
53 explicit TIData(std::string name) : name_(name){};
54 // CPuTI: compute, sleep (+ waitAny and waitAll out of laziness)
55 explicit TIData(std::string name, double amount) : name_(name), amount_(amount){};
56 // Pt2PtTI: send, isend, sssend, issend, recv, irecv
57 explicit TIData(std::string name, int endpoint, int size, std::string datatype)
58 : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
59 // CollTI: bcast, reduce, allReduce, gather, scatter, allGather, allToAll
60 explicit TIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
61 std::string recv_type)
65 , send_size(send_size)
66 , recv_size(recv_size)
67 , send_type(send_type)
68 , recv_type(recv_type){};
69 // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
70 explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
71 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
74 , send_size(send_size)
75 , sendcounts(sendcounts)
76 , recv_size(recv_size)
77 , recvcounts(recvcounts)
78 , send_type(send_type)
79 , recv_type(recv_type){};
87 std::string getName() { return name_; }
88 double getAmount() { return amount_; }
89 virtual std::string print() = 0;
90 virtual std::string display_size() = 0;
93 class NoOpTIData : public TIData {
95 explicit NoOpTIData(std::string name) : TIData(name){};
96 std::string print() override { return getName(); }
97 std::string display_size() override { return ""; }
100 class CpuTIData : public TIData {
102 explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
103 std::string print() override
105 std::stringstream stream;
106 stream << getName() << " " << getAmount();
109 std::string display_size() override { return std::to_string(getAmount()); }
112 class Pt2PtTIData : public TIData {
114 explicit Pt2PtTIData(std::string name, int endpoint, int size, std::string datatype)
115 : TIData(name, endpoint, size, datatype){};
116 std::string print() override
118 std::stringstream stream;
119 stream << getName() << " ";
121 stream << endpoint << " ";
122 stream << send_size << " " << send_type;
125 std::string display_size() override { return std::to_string(send_size); }
128 class CollTIData : public TIData {
130 explicit CollTIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
131 std::string recv_type)
132 : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
133 std::string print() override
135 std::stringstream stream;
136 stream << getName() << " " << send_size << " ";
138 stream << recv_size << " ";
139 if (getAmount() >= 0.0)
140 stream << getAmount() << " ";
141 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
142 stream << endpoint << " ";
143 stream << send_type << " " << recv_type;
147 std::string display_size() override { return std::to_string(send_size); }
150 class VarCollTIData : public TIData {
152 explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
153 std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
154 : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
155 std::string print() override
157 std::stringstream stream;
158 stream << getName() << " ";
160 stream << send_size << " ";
161 if (sendcounts != nullptr)
162 for (auto count : *sendcounts)
163 stream << count << " ";
165 stream << recv_size << " ";
166 if (recvcounts != nullptr)
167 for (auto count : *recvcounts)
168 stream << count << " ";
169 if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
170 stream << endpoint << " ";
171 stream << send_type << " " << recv_type;
175 std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
182 extern XBT_PRIVATE std::set<std::string> created_categories;
183 extern XBT_PRIVATE std::set<std::string> declared_marks;
184 extern XBT_PRIVATE std::set<std::string> user_host_variables;
185 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
186 extern XBT_PRIVATE std::set<std::string> user_link_variables;
187 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
189 /* instr_paje_header.c */
190 XBT_PRIVATE void TRACE_header(bool basic, int size);
193 XBT_PRIVATE void TRACE_paje_start();
194 XBT_PRIVATE void TRACE_paje_end();
196 /* from instr_config.c */
197 XBT_PRIVATE bool TRACE_needs_platform();
198 XBT_PRIVATE bool TRACE_is_enabled();
199 XBT_PRIVATE bool TRACE_platform();
200 XBT_PRIVATE bool TRACE_platform_topology();
201 XBT_PRIVATE bool TRACE_is_configured();
202 XBT_PRIVATE bool TRACE_categorized();
203 XBT_PRIVATE bool TRACE_uncategorized();
204 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
205 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
206 XBT_PRIVATE bool TRACE_buffer();
207 XBT_PRIVATE bool TRACE_disable_link();
208 XBT_PRIVATE bool TRACE_disable_speed();
209 XBT_PRIVATE bool TRACE_onelink_only();
210 XBT_PRIVATE bool TRACE_disable_destroy();
211 XBT_PRIVATE bool TRACE_basic();
212 XBT_PRIVATE bool TRACE_display_sizes();
213 XBT_PRIVATE int TRACE_precision();
214 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
215 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
216 XBT_PRIVATE void instr_pause_tracing();
217 XBT_PRIVATE void instr_resume_tracing();
219 /* Public functions used in SMPI */
220 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
221 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
222 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
223 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
224 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
226 /* from resource_utilization.c */
227 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
229 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
231 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
234 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
235 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
236 XBT_PRIVATE long long int instr_new_paje_id();
237 void instr_new_variable_type(std::string new_typename, std::string color);
238 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
239 void instr_new_user_state_type(std::string father_type, std::string new_typename);
240 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
243 XBT_PRIVATE void TRACE_TI_start();
244 XBT_PRIVATE void TRACE_TI_end();
246 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
247 XBT_PRIVATE void dump_comment_file(std::string filename);
248 XBT_PRIVATE void dump_comment(std::string comment);
250 /* Format of TRACING output.
251 * - paje is the regular format, that we all know
252 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
253 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
254 * using the signal that we will create to cleanup the TRACING
256 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
257 extern instr_fmt_type_t instr_fmt_type;
259 XBT_PRIVATE std::string TRACE_get_comment();
260 XBT_PRIVATE std::string TRACE_get_comment_file();
261 XBT_PRIVATE std::string TRACE_get_filename();
262 XBT_PRIVATE std::string TRACE_get_viva_uncat_conf();
263 XBT_PRIVATE std::string TRACE_get_viva_cat_conf();