Logo AND Algorithmique Numérique Distribuée

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