Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
97b9e9b78ad5f50c461e17425151527adcd7869b
[simgrid.git] / src / instr / instr_private.hpp
1 /* Copyright (c) 2010-2017. 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_types.hpp"
16 #include "src/internal_config.h"
17 #include "xbt/graph.h"
18 #include <iomanip> /** std::setprecision **/
19 #include <map>
20 #include <set>
21 #include <sstream>
22 #include <string>
23 #include <sys/stat.h>
24 #ifdef WIN32
25 #include <direct.h> // _mkdir
26 /* Need to define function drand48 for Windows */
27 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
28 #define drand48() (rand() / (RAND_MAX + 1.0))
29 #endif
30
31 namespace simgrid {
32 namespace instr {
33
34 class Container;
35 class Type;
36 class EntityValue;
37 class ContainerType;
38 class EventType;
39 class LinkType;
40 class StateType;
41 class VariableType;
42
43 enum e_event_type : unsigned int {
44   PAJE_DefineContainerType,
45   PAJE_DefineVariableType,
46   PAJE_DefineStateType,
47   PAJE_DefineEventType,
48   PAJE_DefineLinkType,
49   PAJE_DefineEntityValue,
50   PAJE_CreateContainer,
51   PAJE_DestroyContainer,
52   PAJE_SetVariable,
53   PAJE_AddVariable,
54   PAJE_SubVariable,
55   PAJE_SetState,
56   PAJE_PushState,
57   PAJE_PopState,
58   PAJE_ResetState,
59   PAJE_StartLink,
60   PAJE_EndLink,
61   PAJE_NewEvent
62 };
63
64 class EntityValue {
65   long long int id_;
66   std::string name_;
67   std::string color_;
68   Type* father_;
69
70 public:
71   explicit EntityValue(std::string name, std::string color, Type* father);
72   ~EntityValue() = default;
73   const char* getCname() { return name_.c_str(); }
74   long long int getId() { return id_; }
75   void print();
76 };
77
78 class PajeEvent {
79 protected:
80   Container* container;
81   Type* type;
82
83 public:
84   double timestamp_;
85   e_event_type eventType_;
86   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
87       : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
88   virtual ~PajeEvent();
89   virtual void print() = 0;
90   void insertIntoBuffer();
91 };
92
93 class VariableEvent : public PajeEvent {
94   double value;
95
96 public:
97   VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value);
98   void print() override;
99 };
100
101 class StateEvent : public PajeEvent {
102   EntityValue* value;
103   std::string filename;
104   int linenumber;
105   void* extra_ = nullptr;
106
107 public:
108   StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value);
109   StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value,
110              void* extra);
111   void print() override;
112 };
113
114 class StartLinkEvent : public PajeEvent {
115   Container* sourceContainer_;
116   std::string value_;
117   std::string key_;
118   int size_;
119
120 public:
121   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
122                  std::string key);
123   StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
124                  std::string key, int size);
125   void print() override;
126 };
127
128 class EndLinkEvent : public PajeEvent {
129   Container* destContainer;
130   std::string value;
131   std::string key;
132
133 public:
134   EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
135                std::string key);
136   ~EndLinkEvent() = default;
137   void print() override;
138 };
139
140 class NewEvent : public PajeEvent {
141   EntityValue* val;
142
143 public:
144   NewEvent(double timestamp, Container* container, Type* type, EntityValue* val);
145   void print() override;
146 };
147 }
148 } // namespace simgrid::instr
149 typedef simgrid::instr::Container* container_t;
150
151 extern "C" {
152
153 extern XBT_PRIVATE std::set<std::string> created_categories;
154 extern XBT_PRIVATE std::set<std::string> declared_marks;
155 extern XBT_PRIVATE std::set<std::string> user_host_variables;
156 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
157 extern XBT_PRIVATE std::set<std::string> user_link_variables;
158 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
159
160 /* instr_paje_header.c */
161 XBT_PRIVATE void TRACE_header(bool basic, int size);
162
163 /* from paje.c */
164 XBT_PRIVATE void TRACE_paje_start();
165 XBT_PRIVATE void TRACE_paje_end();
166
167 /* from instr_config.c */
168 XBT_PRIVATE bool TRACE_needs_platform();
169 XBT_PRIVATE bool TRACE_is_enabled();
170 XBT_PRIVATE bool TRACE_platform();
171 XBT_PRIVATE bool TRACE_platform_topology();
172 XBT_PRIVATE bool TRACE_is_configured();
173 XBT_PRIVATE bool TRACE_categorized();
174 XBT_PRIVATE bool TRACE_uncategorized();
175 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
176 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
177 XBT_PRIVATE bool TRACE_buffer();
178 XBT_PRIVATE bool TRACE_disable_link();
179 XBT_PRIVATE bool TRACE_disable_speed();
180 XBT_PRIVATE bool TRACE_onelink_only();
181 XBT_PRIVATE bool TRACE_disable_destroy();
182 XBT_PRIVATE bool TRACE_basic();
183 XBT_PRIVATE bool TRACE_display_sizes();
184 XBT_PRIVATE char* TRACE_get_comment();
185 XBT_PRIVATE char* TRACE_get_comment_file();
186 XBT_PRIVATE int TRACE_precision();
187 XBT_PRIVATE char* TRACE_get_filename();
188 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
189 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
190 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
191 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
192 XBT_PRIVATE void instr_pause_tracing();
193 XBT_PRIVATE void instr_resume_tracing();
194
195 /* Public functions used in SMPI */
196 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
197 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
198 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
199 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
200 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
201
202 /* from resource_utilization.c */
203 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
204                                                  double delta);
205 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
206                                                  double delta);
207 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
208
209 /* instr_paje.c */
210 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
211 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
212 XBT_PRIVATE long long int instr_new_paje_id();
213 void instr_new_variable_type(std::string new_typename, std::string color);
214 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
215 void instr_new_user_state_type(std::string father_type, std::string new_typename);
216 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
217
218 /* instr_config.c */
219 XBT_PRIVATE void TRACE_TI_start();
220 XBT_PRIVATE void TRACE_TI_end();
221
222 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
223 XBT_PRIVATE void dump_comment_file(std::string filename);
224 XBT_PRIVATE void dump_comment(std::string comment);
225
226 enum e_caller_type {
227   TRACING_INIT,
228   TRACING_FINALIZE,
229   TRACING_COMM_SIZE,
230   TRACING_COMM_SPLIT,
231   TRACING_COMM_DUP,
232   TRACING_SEND,
233   TRACING_ISEND,
234   TRACING_SSEND,
235   TRACING_ISSEND,
236   TRACING_RECV,
237   TRACING_IRECV,
238   TRACING_SENDRECV,
239   TRACING_TEST,
240   TRACING_WAIT,
241   TRACING_WAITALL,
242   TRACING_WAITANY,
243   TRACING_BARRIER,
244   TRACING_BCAST,
245   TRACING_REDUCE,
246   TRACING_ALLREDUCE,
247   TRACING_ALLTOALL,
248   TRACING_ALLTOALLV,
249   TRACING_GATHER,
250   TRACING_GATHERV,
251   TRACING_SCATTER,
252   TRACING_SCATTERV,
253   TRACING_ALLGATHER,
254   TRACING_ALLGATHERV,
255   TRACING_REDUCE_SCATTER,
256   TRACING_COMPUTING,
257   TRACING_SLEEPING,
258   TRACING_SCAN,
259   TRACING_EXSCAN
260 };
261
262 struct s_instr_extra_data_t {
263   e_caller_type type;
264   int send_size;
265   int recv_size;
266   double comp_size;
267   double sleep_duration;
268   int src;
269   int dst;
270   int root;
271   const char* datatype1;
272   const char* datatype2;
273   int* sendcounts;
274   int* recvcounts;
275   int num_processes;
276 };
277 typedef s_instr_extra_data_t* instr_extra_data;
278
279 /* Format of TRACING output.
280  *   - paje is the regular format, that we all know
281  *   - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
282  *     trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
283  *     using the signal that we will create to cleanup the TRACING
284  */
285 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
286 extern instr_fmt_type_t instr_fmt_type;
287 }
288
289 #endif