Logo AND Algorithmique Numérique Distribuée

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