Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
consistency in host/storage/netpoint registering
[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 "instr/instr_interface.hpp"
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
21 #include <iomanip> /** std::setprecision **/
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <sstream>
26 #include <string>
27 #include <sys/stat.h>
28 #ifdef WIN32
29 #include <direct.h> // _mkdir
30 /* Need to define function drand48 for Windows */
31 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
32 #define drand48() (rand() / (RAND_MAX + 1.0))
33 #endif
34
35 typedef simgrid::instr::Container* container_t;
36
37 namespace simgrid {
38 namespace instr {
39
40 /* Format of TRACING output.
41  *   - paje is the regular format, that we all know
42  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
43  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
44  *     using the signal that we will create to cleanup the TRACING
45  */
46 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
47 extern TraceFormat trace_format;
48
49 class TIData {
50   std::string name_;
51   double amount_ = 0;
52
53 public:
54   int endpoint                 = 0;
55   int send_size                = 0;
56   std::shared_ptr<std::vector<int>> sendcounts = nullptr;
57   int recv_size                = 0;
58   std::shared_ptr<std::vector<int>> recvcounts = nullptr;
59   std::string send_type        = "";
60   std::string recv_type        = "";
61
62   // NoOpTI: init, finalize, test, wait, barrier
63   explicit TIData(std::string name) : name_(name){};
64   // CPuTI: compute, sleep (+ waitAny and waitAll out of laziness)
65   explicit TIData(std::string name, double amount) : name_(name), amount_(amount){};
66   // Pt2PtTI: send, isend, sssend, issend, recv, irecv
67   explicit TIData(std::string name, int endpoint, int size, std::string datatype)
68       : name_(name), endpoint(endpoint), send_size(size), send_type(datatype){};
69   // CollTI: bcast, reduce, allReduce, gather, scatter, allGather, allToAll
70   explicit TIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
71                   std::string recv_type)
72       : name_(name)
73       , amount_(amount)
74       , endpoint(root)
75       , send_size(send_size)
76       , recv_size(recv_size)
77       , send_type(send_type)
78       , recv_type(recv_type){};
79   // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
80   explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
81                   std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
82       : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
83                std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
84
85   explicit TIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
86                   int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
87                   std::string recv_type)
88       : name_(name)
89       , endpoint(root)
90       , send_size(send_size)
91       , sendcounts(sendcounts)
92       , recv_size(recv_size)
93       , recvcounts(recvcounts)
94       , send_type(send_type)
95       , recv_type(recv_type){};
96
97   virtual ~TIData() {}
98
99   std::string getName() { return name_; }
100   double getAmount() { return amount_; }
101   virtual std::string print()        = 0;
102   virtual std::string display_size() = 0;
103 };
104
105 class NoOpTIData : public TIData {
106 public:
107   explicit NoOpTIData(std::string name) : TIData(name){};
108   std::string print() override { return getName(); }
109   std::string display_size() override { return ""; }
110 };
111
112 class CpuTIData : public TIData {
113 public:
114   explicit CpuTIData(std::string name, double amount) : TIData(name, amount){};
115   std::string print() override
116   {
117     std::stringstream stream;
118     stream << getName() << " " << getAmount();
119     return stream.str();
120   }
121   std::string display_size() override { return std::to_string(getAmount()); }
122 };
123
124 class Pt2PtTIData : public TIData {
125   int tag;
126 public:
127   explicit Pt2PtTIData(std::string name, int endpoint, int size, int tag, std::string datatype)
128       : TIData(name, endpoint, size, datatype), tag(tag) {};
129
130   explicit Pt2PtTIData(std::string name, int endpoint, int size, std::string datatype)
131       : TIData(name, endpoint, size, datatype), tag(0) {};
132   std::string print() override
133   {
134     std::stringstream stream;
135     stream << getName() << " ";
136     if (endpoint >= 0)
137       stream << endpoint << " ";
138     stream << tag << " " << send_size << " " << send_type;
139     return stream.str();
140   }
141   std::string display_size() override { return std::to_string(send_size); }
142 };
143
144 class CollTIData : public TIData {
145 public:
146   explicit CollTIData(std::string name, int root, double amount, int send_size, int recv_size, std::string send_type,
147                       std::string recv_type)
148       : TIData(name, root, amount, send_size, recv_size, send_type, recv_type){};
149   std::string print() override
150   {
151     std::stringstream stream;
152     stream << getName() << " " << send_size << " ";
153     if (recv_size >= 0)
154       stream << recv_size << " ";
155     if (getAmount() >= 0.0)
156       stream << getAmount() << " ";
157     if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
158       stream << endpoint << " ";
159     stream << send_type << " " << recv_type;
160
161     return stream.str();
162   }
163   std::string display_size() override { return std::to_string(send_size); }
164 };
165
166 class VarCollTIData : public TIData {
167 public:
168   explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
169                          std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
170       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
171
172   explicit VarCollTIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
173                          int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
174                          std::string recv_type)
175       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
176
177   std::string print() override
178   {
179     std::stringstream stream;
180     stream << getName() << " ";
181     if (send_size >= 0)
182       stream << send_size << " ";
183     if (sendcounts != nullptr)
184       for (auto count : *sendcounts)
185         stream << count << " ";
186     if (recv_size >= 0)
187       stream << recv_size << " ";
188     if (recvcounts != nullptr)
189       for (auto count : *recvcounts)
190         stream << count << " ";
191     if (endpoint > 0 || (endpoint == 0 && not send_type.empty()))
192       stream << endpoint << " ";
193     stream << send_type << " " << recv_type;
194
195     return stream.str();
196   }
197   std::string display_size() override { return std::to_string(send_size > 0 ? send_size : recv_size); }
198 };
199 }
200 }
201
202 XBT_PRIVATE std::string instr_pid(s4u_Actor* proc);
203
204 extern XBT_PRIVATE std::set<std::string> created_categories;
205 extern XBT_PRIVATE std::set<std::string> declared_marks;
206 extern XBT_PRIVATE std::set<std::string> user_host_variables;
207 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
208 extern XBT_PRIVATE std::set<std::string> user_link_variables;
209 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
210
211 /* instr_paje_header.c */
212 XBT_PRIVATE void TRACE_header(bool basic, int size);
213
214 /* from paje.c */
215 XBT_PRIVATE void TRACE_paje_start();
216 XBT_PRIVATE void TRACE_paje_end();
217
218 /* from instr_config.c */
219 XBT_PRIVATE bool TRACE_needs_platform();
220 XBT_PRIVATE bool TRACE_is_enabled();
221 XBT_PRIVATE bool TRACE_platform();
222 XBT_PRIVATE bool TRACE_platform_topology();
223 XBT_PRIVATE bool TRACE_categorized();
224 XBT_PRIVATE bool TRACE_uncategorized();
225 XBT_PRIVATE bool TRACE_actor_is_enabled();
226 XBT_PRIVATE bool TRACE_vm_is_enabled();
227 XBT_PRIVATE bool TRACE_buffer();
228 XBT_PRIVATE bool TRACE_disable_link();
229 XBT_PRIVATE bool TRACE_disable_speed();
230 XBT_PRIVATE bool TRACE_disable_destroy();
231 XBT_PRIVATE bool TRACE_basic();
232 XBT_PRIVATE bool TRACE_display_sizes();
233 XBT_PRIVATE int TRACE_precision();
234
235 /* Public functions used in SMPI */
236 XBT_PUBLIC bool TRACE_smpi_is_enabled();
237 XBT_PUBLIC bool TRACE_smpi_is_grouped();
238 XBT_PUBLIC bool TRACE_smpi_is_computing();
239 XBT_PUBLIC bool TRACE_smpi_is_sleeping();
240 XBT_PUBLIC bool TRACE_smpi_view_internals();
241
242 /* from resource_utilization.c */
243 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
244                                                  double delta);
245 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
246                                                  double delta);
247
248 /* instr_paje.c */
249 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
250 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
251 XBT_PRIVATE long long int instr_new_paje_id();
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);
256
257 /* instr_config.c */
258 XBT_PRIVATE void TRACE_TI_start();
259 XBT_PRIVATE void TRACE_TI_end();
260
261 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
262 XBT_PRIVATE void dump_comment_file(std::string filename);
263 XBT_PRIVATE void dump_comment(std::string comment);
264
265 XBT_PRIVATE std::string TRACE_get_comment();
266 XBT_PRIVATE std::string TRACE_get_comment_file();
267 XBT_PRIVATE std::string TRACE_get_filename();
268
269 #endif