Logo AND Algorithmique Numérique Distribuée

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