1 /* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef INSTR_PRIVATE_HPP
7 #define INSTR_PRIVATE_HPP
11 #include "instr/instr_interface.h"
12 #include "simgrid/instr.h"
13 #include "simgrid_config.h"
14 #include "src/internal_config.h"
15 #include "xbt/graph.h"
16 #include <iomanip> /** std::setprecision **/
23 #include <direct.h> // _mkdir
24 /* Need to define function drand48 for Windows */
25 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
26 #define drand48() (rand() / (RAND_MAX + 1.0))
29 #define INSTR_DEFAULT_STR_SIZE 500
37 PAJE_DefineContainerType,
38 PAJE_DefineVariableType,
42 PAJE_DefineEntityValue,
44 PAJE_DestroyContainer,
57 //--------------------------------------------------
58 enum e_entity_types { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE_EVENT };
68 std::map<std::string, Type*> children_;
69 std::map<std::string, Value*> values_; // valid for all types except variable and container
71 Type(std::string name, std::string alias, std::string color, e_entity_types kind, Type* father);
74 std::string getName() { return name_; }
75 const char* getCname() { return name_.c_str(); }
76 const char* getId() { return id_.c_str(); }
77 e_entity_types getKind() { return kind_; }
78 bool isColored() { return not color_.empty(); }
80 Type* byName(std::string name);
82 Type* getOrCreateContainerType(std::string name);
83 Type* getOrCreateEventType(std::string name);
84 Type* getOrCreateLinkType(std::string name, Type* source, Type* dest);
85 Type* getOrCreateStateType(std::string name);
86 Type* getOrCreateVariableType(std::string name, std::string color);
88 void addEntityValue(std::string name, std::string color);
89 void addEntityValue(std::string name);
90 Value* getEntityValue(std::string name);
92 void logContainerTypeDefinition();
93 void logVariableTypeDefinition();
94 void logStateTypeDefinition();
95 void logLinkTypeDefinition(simgrid::instr::Type* source, simgrid::instr::Type* dest);
96 void logDefineEventType();
98 static Type* createRootType();
99 static Type* getRootType();
102 //--------------------------------------------------
110 explicit Value(std::string name, std::string color, Type* father);
112 const char* getCname() { return name_.c_str(); }
113 const char* getId() { return id_.c_str(); }
114 bool isColored() { return not color_.empty(); }
118 //--------------------------------------------------
119 enum e_container_types {
131 e_container_types kind_; /* This container is of what kind */
132 std::string name_; /* Unique name of this container */
133 int level_ = 0; /* Level in the hierarchy, root level is 0 */
134 sg_netpoint_t netpoint_ = nullptr;
137 Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
138 virtual ~Container();
140 std::string id_; /* Unique id of this container */
141 Type* type_; /* Type of this container */
143 std::map<std::string, Container*> children_;
144 static Container* byNameOrNull(std::string name);
145 static Container* byName(std::string name);
146 std::string getName() { return name_; }
147 const char* getCname() { return name_.c_str(); }
148 void removeFromParent();
150 void logDestruction();
153 //--------------------------------------------------
156 Container* container;
161 e_event_type eventType_;
162 PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
163 : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
164 virtual void print() = 0;
165 virtual ~PajeEvent();
166 void insertIntoBuffer();
169 //--------------------------------------------------
170 class SetVariableEvent : public PajeEvent {
174 SetVariableEvent(double timestamp, Container* container, Type* type, double value);
175 void print() override;
178 class AddVariableEvent : public PajeEvent {
182 AddVariableEvent(double timestamp, Container* container, Type* type, double value);
183 void print() override;
185 //--------------------------------------------------
187 class SubVariableEvent : public PajeEvent {
191 SubVariableEvent(double timestamp, Container* container, Type* type, double value);
192 void print() override;
194 //--------------------------------------------------
196 class SetStateEvent : public PajeEvent {
198 const char* filename;
202 SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
203 void print() override;
206 class PushStateEvent : public PajeEvent {
208 const char* filename;
213 PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
214 PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
215 void print() override;
218 class PopStateEvent : public PajeEvent {
220 PopStateEvent(double timestamp, Container* container, Type* type);
221 void print() override;
224 class ResetStateEvent : public PajeEvent {
226 ResetStateEvent(double timestamp, Container* container, Type* type);
227 void print() override;
230 class StartLinkEvent : public PajeEvent {
231 Container* sourceContainer_;
237 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
239 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
240 std::string key, int size);
241 void print() override;
244 class EndLinkEvent : public PajeEvent {
245 Container* destContainer;
250 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
252 ~EndLinkEvent() = default;
253 void print() override;
256 class NewEvent : public PajeEvent {
260 NewEvent(double timestamp, Container* container, Type* type, Value* val);
261 void print() override;
264 } // namespace simgrid::instr
265 typedef simgrid::instr::Container* container_t;
269 extern XBT_PRIVATE std::set<std::string> created_categories;
270 extern XBT_PRIVATE std::set<std::string> declared_marks;
271 extern XBT_PRIVATE std::set<std::string> user_host_variables;
272 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
273 extern XBT_PRIVATE std::set<std::string> user_link_variables;
274 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
276 /* instr_paje_header.c */
277 XBT_PRIVATE void TRACE_header(bool basic, int size);
280 XBT_PRIVATE void TRACE_paje_start();
281 XBT_PRIVATE void TRACE_paje_end();
283 /* from instr_config.c */
284 XBT_PRIVATE bool TRACE_needs_platform();
285 XBT_PRIVATE bool TRACE_is_enabled();
286 XBT_PRIVATE bool TRACE_platform();
287 XBT_PRIVATE bool TRACE_platform_topology();
288 XBT_PRIVATE bool TRACE_is_configured();
289 XBT_PRIVATE bool TRACE_categorized();
290 XBT_PRIVATE bool TRACE_uncategorized();
291 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
292 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
293 XBT_PRIVATE bool TRACE_buffer();
294 XBT_PRIVATE bool TRACE_disable_link();
295 XBT_PRIVATE bool TRACE_disable_speed();
296 XBT_PRIVATE bool TRACE_onelink_only();
297 XBT_PRIVATE bool TRACE_disable_destroy();
298 XBT_PRIVATE bool TRACE_basic();
299 XBT_PRIVATE bool TRACE_display_sizes();
300 XBT_PRIVATE char* TRACE_get_comment();
301 XBT_PRIVATE char* TRACE_get_comment_file();
302 XBT_PRIVATE int TRACE_precision();
303 XBT_PRIVATE char* TRACE_get_filename();
304 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
305 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
306 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
307 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
308 XBT_PRIVATE void instr_pause_tracing();
309 XBT_PRIVATE void instr_resume_tracing();
311 /* Public functions used in SMPI */
312 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
313 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
314 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
315 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
316 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
318 /* from resource_utilization.c */
319 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
321 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
323 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
326 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
327 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
328 XBT_PRIVATE long long int instr_new_paje_id();
329 XBT_PUBLIC(container_t) PJ_container_get_root ();
330 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
331 void instr_new_variable_type(std::string new_typename, const char* color);
332 void instr_new_user_variable_type(std::string father_type, std::string new_typename, const char* color);
333 void instr_new_user_state_type(std::string father_type, std::string new_typename);
334 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, const char* color);
337 XBT_PRIVATE void TRACE_TI_start();
338 XBT_PRIVATE void TRACE_TI_end();
340 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
341 XBT_PRIVATE void dump_comment_file(std::string filename);
342 XBT_PRIVATE void dump_comment(std::string comment);
373 TRACING_REDUCE_SCATTER,
380 struct s_instr_extra_data_t {
385 double sleep_duration;
389 const char* datatype1;
390 const char* datatype2;
395 typedef s_instr_extra_data_t* instr_extra_data;
397 /* Format of TRACING output.
398 * - paje is the regular format, that we all know
399 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
400 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
401 * using the signal that we will create to cleanup the TRACING
403 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
404 extern instr_fmt_type_t instr_fmt_type;