Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use kernelImmediate for simcall cond_init.
[simgrid.git] / src / instr / instr_private.hpp
1 /* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef INSTR_PRIVATE_HPP
7 #define INSTR_PRIVATE_HPP
8
9 #include <xbt/base.h>
10
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"
19
20 #include <iomanip> /** std::setprecision **/
21 #include <map>
22 #include <memory>
23 #include <set>
24 #include <sstream>
25 #include <string>
26 #include <sys/stat.h>
27 #ifdef WIN32
28 #include <direct.h> // _mkdir
29 /* Need to define function drand48 for Windows */
30 #define drand48() (rand() / (RAND_MAX + 1.0))
31 #endif
32
33 typedef simgrid::instr::Container* container_t;
34
35 namespace simgrid {
36 namespace instr {
37
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
43  */
44 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
45 extern TraceFormat trace_format;
46
47 class TIData {
48   std::string name_;
49   double amount_ = 0;
50
51 public:
52   int endpoint                 = 0;
53   int send_size                = 0;
54   std::shared_ptr<std::vector<int>> sendcounts = nullptr;
55   int recv_size                = 0;
56   std::shared_ptr<std::vector<int>> recvcounts = nullptr;
57   std::string send_type        = "";
58   std::string recv_type        = "";
59
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)
70       : name_(name)
71       , amount_(amount)
72       , endpoint(root)
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){};
82
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)
86       : name_(name)
87       , endpoint(root)
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){};
94
95   virtual ~TIData() {}
96
97   std::string getName() { return name_; }
98   double getAmount() { return amount_; }
99   virtual std::string print()        = 0;
100   virtual std::string display_size() = 0;
101 };
102
103 class NoOpTIData : public TIData {
104 public:
105   explicit NoOpTIData(std::string name) : TIData(name){};
106   std::string print() override { return getName(); }
107   std::string display_size() override { return ""; }
108 };
109
110 class CpuTIData : public TIData {
111 public:
112   explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
113   std::string print() override
114   {
115     std::stringstream stream;
116     stream << getName() << " " << getAmount();
117     return stream.str();
118   }
119   std::string display_size() override { return std::to_string(getAmount()); }
120 };
121
122 class Pt2PtTIData : public TIData {
123   int tag;
124 public:
125   explicit Pt2PtTIData(std::string name, int endpoint, int size, int tag, std::string datatype)
126       : TIData(name, endpoint, size, datatype), tag(tag) {};
127
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
131   {
132     std::stringstream stream;
133     stream << getName() << " ";
134     if (endpoint >= 0)
135       stream << endpoint << " ";
136     stream << tag << " " << send_size << " " << send_type;
137     return stream.str();
138   }
139   std::string display_size() override { return std::to_string(send_size); }
140 };
141
142 class CollTIData : public TIData {
143 public:
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
148   {
149     std::stringstream stream;
150     stream << getName() << " " << send_size << " ";
151     if (recv_size >= 0)
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;
158
159     return stream.str();
160   }
161   std::string display_size() override { return std::to_string(send_size); }
162 };
163
164 class VarCollTIData : public TIData {
165 public:
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){};
169
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){};
174
175   std::string print() override
176   {
177     std::stringstream stream;
178     stream << getName() << " ";
179     if (send_size >= 0)
180       stream << send_size << " ";
181     if (sendcounts != nullptr)
182       for (auto count : *sendcounts)
183         stream << count << " ";
184     if (recv_size >= 0)
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;
192
193     return stream.str();
194   }
195   std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
196 };
197 }
198 }
199
200 XBT_PRIVATE std::string instr_pid(s4u_Actor* proc);
201
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;
208
209 /* instr_paje_header.c */
210 XBT_PRIVATE void TRACE_header(bool basic, int size);
211
212 /* from paje.c */
213 XBT_PRIVATE void TRACE_paje_start();
214 XBT_PRIVATE void TRACE_paje_end();
215
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();
232
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();
239
240 /* from resource_utilization.c */
241 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
242                                                  double delta);
243 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
244                                                  double delta);
245
246 /* instr_paje.c */
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);
255
256 /* instr_config.c */
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);
261
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);
265
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();
269
270 #endif