Logo AND Algorithmique Numérique Distribuée

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