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"
19 /* Need to define function drand48 for Windows */
20 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
22 #define drand48() (rand() / (RAND_MAX + 1.0))
25 #define INSTR_DEFAULT_STR_SIZE 500
28 #include "xbt/graph.h"
36 PAJE_DefineContainerType,
37 PAJE_DefineVariableType,
41 PAJE_DefineEntityValue,
43 PAJE_DestroyContainer,
56 enum e_entity_types { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE_EVENT };
58 //--------------------------------------------------
68 std::map<std::string, Type*> children_;
69 std::map<std::string, Value*> values_; // valid for all types except variable and container
70 Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father);
72 Type* getChild(std::string name);
73 Type* getChildOrNull(std::string name);
75 static Type* containerNew(const char* name, Type* father);
76 static Type* eventNew(const char* name, Type* father);
77 static Type* variableNew(const char* name, std::string color, Type* father);
78 static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
79 static Type* stateNew(const char* name, Type* father);
80 std::string getName() { return name_; }
81 const char* getCname() { return name_.c_str(); }
82 const char* getId() { return id_.c_str(); }
83 bool isColored() { return not color_.empty(); }
86 //--------------------------------------------------
92 explicit Value(std::string name, std::string color, Type* father);
97 static Value* byNameOrCreate(std::string name, std::string color, Type* father);
98 static Value* byName(std::string name, Type* father);
99 const char* getCname() { return name_.c_str(); }
100 const char* getId() { return id_.c_str(); }
101 bool isColored() { return not color_.empty(); }
105 //--------------------------------------------------
106 enum e_container_types {
117 //--------------------------------------------------
121 Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
122 virtual ~Container();
124 sg_netpoint_t netpoint_;
125 std::string name_; /* Unique name of this container */
126 std::string id_; /* Unique id of this container */
127 Type* type_; /* Type of this container */
128 int level_ = 0; /* Level in the hierarchy, root level is 0 */
129 e_container_types kind_; /* This container is of what kind */
131 std::map<std::string, Container*> children_;
132 static simgrid::instr::Container* byNameOrNull(std::string name);
133 static simgrid::instr::Container* byName(std::string name);
136 //--------------------------------------------------
139 Container* container;
144 e_event_type eventType_;
145 PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
146 : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
147 virtual void print() = 0;
148 virtual ~PajeEvent();
149 void insertIntoBuffer();
152 //--------------------------------------------------
153 class SetVariableEvent : public PajeEvent {
157 SetVariableEvent(double timestamp, Container* container, Type* type, double value);
158 void print() override;
161 class AddVariableEvent : public PajeEvent {
165 AddVariableEvent(double timestamp, Container* container, Type* type, double value);
166 void print() override;
168 //--------------------------------------------------
170 class SubVariableEvent : public PajeEvent {
174 SubVariableEvent(double timestamp, Container* container, Type* type, double value);
175 void print() override;
177 //--------------------------------------------------
179 class SetStateEvent : public PajeEvent {
181 const char* filename;
185 SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
186 void print() override;
189 class PushStateEvent : public PajeEvent {
191 const char* filename;
196 PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
197 PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
198 void print() override;
201 class PopStateEvent : public PajeEvent {
203 PopStateEvent(double timestamp, Container* container, Type* type);
204 void print() override;
207 class ResetStateEvent : public PajeEvent {
209 ResetStateEvent(double timestamp, Container* container, Type* type);
210 void print() override;
213 class StartLinkEvent : public PajeEvent {
214 Container* sourceContainer_;
220 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
222 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
223 std::string key, int size);
224 void print() override;
227 class EndLinkEvent : public PajeEvent {
228 Container* destContainer;
233 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
235 ~EndLinkEvent() = default;
236 void print() override;
239 class NewEvent : public PajeEvent {
243 NewEvent(double timestamp, Container* container, Type* type, Value* val);
244 void print() override;
247 } // namespace simgrid::instr
248 typedef simgrid::instr::Container* container_t;
252 extern XBT_PRIVATE std::set<std::string> created_categories;
253 extern XBT_PRIVATE std::set<std::string> declared_marks;
254 extern XBT_PRIVATE std::set<std::string> user_host_variables;
255 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
256 extern XBT_PRIVATE std::set<std::string> user_link_variables;
257 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
259 /* instr_paje_header.c */
260 XBT_PRIVATE void TRACE_header(int basic, int size);
263 XBT_PRIVATE void TRACE_paje_start();
264 XBT_PRIVATE void TRACE_paje_end();
265 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
267 /* from instr_config.c */
268 XBT_PRIVATE bool TRACE_needs_platform();
269 XBT_PRIVATE bool TRACE_is_enabled();
270 XBT_PRIVATE bool TRACE_platform();
271 XBT_PRIVATE bool TRACE_platform_topology();
272 XBT_PRIVATE bool TRACE_is_configured();
273 XBT_PRIVATE bool TRACE_categorized();
274 XBT_PRIVATE bool TRACE_uncategorized();
275 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
276 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
277 XBT_PRIVATE bool TRACE_buffer();
278 XBT_PRIVATE bool TRACE_disable_link();
279 XBT_PRIVATE bool TRACE_disable_speed();
280 XBT_PRIVATE bool TRACE_onelink_only();
281 XBT_PRIVATE bool TRACE_disable_destroy();
282 XBT_PRIVATE bool TRACE_basic();
283 XBT_PRIVATE bool TRACE_display_sizes();
284 XBT_PRIVATE char* TRACE_get_comment();
285 XBT_PRIVATE char* TRACE_get_comment_file();
286 XBT_PRIVATE int TRACE_precision();
287 XBT_PRIVATE char* TRACE_get_filename();
288 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
289 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
290 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
291 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
292 XBT_PRIVATE void instr_pause_tracing();
293 XBT_PRIVATE void instr_resume_tracing();
295 /* Public functions used in SMPI */
296 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
297 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
298 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
299 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
300 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
302 /* from resource_utilization.c */
303 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
305 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
307 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
310 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
311 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
312 XBT_PRIVATE long long int instr_new_paje_id();
313 XBT_PUBLIC(container_t) PJ_container_get_root ();
314 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
315 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
317 /* instr_paje_types.c */
318 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
321 XBT_PRIVATE void TRACE_TI_start();
322 XBT_PRIVATE void TRACE_TI_end();
324 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
325 XBT_PRIVATE void dump_comment_file(const char* filename);
326 XBT_PRIVATE void dump_comment(const char* comment);
357 TRACING_REDUCE_SCATTER,
364 struct s_instr_extra_data_t {
369 double sleep_duration;
373 const char* datatype1;
374 const char* datatype2;
379 typedef s_instr_extra_data_t* instr_extra_data;
381 /* Format of TRACING output.
382 * - paje is the regular format, that we all know
383 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
384 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
385 * using the signal that we will create to cleanup the TRACING
387 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
388 extern instr_fmt_type_t instr_fmt_type;
391 void LogContainerTypeDefinition(simgrid::instr::Type* type);
392 void LogVariableTypeDefinition(simgrid::instr::Type* type);
393 void LogStateTypeDefinition(simgrid::instr::Type* type);
394 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
395 void LogContainerCreation(container_t container);
396 void LogContainerDestruction(container_t container);
397 void LogDefineEventType(simgrid::instr::Type* type);