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"
33 PAJE_DefineContainerType,
34 PAJE_DefineVariableType,
38 PAJE_DefineEntityValue,
40 PAJE_DestroyContainer,
53 typedef enum { TYPE_VARIABLE, TYPE_LINK, TYPE_CONTAINER, TYPE_STATE, TYPE_EVENT } e_entity_types;
55 //--------------------------------------------------
66 xbt_dict_t values_; // valid for all types except variable and container
67 Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind, Type* father);
69 Type* getChild(const char* name);
70 Type* getChildOrNull(const char* name);
72 static Type* containerNew(const char* name, Type* father);
73 static Type* eventNew(const char* name, Type* father);
74 static Type* variableNew(const char* name, const char* color, Type* father);
75 static Type* linkNew(const char* name, Type* father, Type* source, Type* dest);
76 static Type* stateNew(const char* name, Type* father);
79 //--------------------------------------------------
86 explicit Value(std::string name, std::string color, Type* father);
91 static Value* byNameOrCreate(std::string name, std::string color, Type* father);
92 static Value* byName(std::string name, Type* father);
93 const char* getCname() { return name_.c_str(); }
94 const char* getId() { return id_.c_str(); }
95 bool isColored() { return not color_.empty(); }
99 //--------------------------------------------------
111 //--------------------------------------------------
115 Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
116 virtual ~Container();
118 sg_netpoint_t netpoint_;
119 std::string name_; /* Unique name of this container */
120 std::string id_; /* Unique id of this container */
121 Type* type_; /* Type of this container */
122 int level_ = 0; /* Level in the hierarchy, root level is 0 */
123 e_container_types kind_; /* This container is of what kind */
125 std::map<std::string, Container*> children_;
128 //--------------------------------------------------
131 Container* container;
136 e_event_type eventType_;
137 PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
138 : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
139 virtual void print() = 0;
140 virtual ~PajeEvent();
143 //--------------------------------------------------
144 class SetVariableEvent : public PajeEvent {
148 SetVariableEvent(double timestamp, Container* container, Type* type, double value);
149 void print() override;
152 class AddVariableEvent : public PajeEvent {
156 AddVariableEvent(double timestamp, Container* container, Type* type, double value);
157 void print() override;
159 //--------------------------------------------------
161 class SubVariableEvent : public PajeEvent {
165 SubVariableEvent(double timestamp, Container* container, Type* type, double value);
166 void print() override;
168 //--------------------------------------------------
170 class SetStateEvent : public PajeEvent {
172 const char* filename;
176 SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
177 void print() override;
180 class PushStateEvent : public PajeEvent {
183 const char* filename;
188 PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
189 PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
190 void print() override;
193 class PopStateEvent : public PajeEvent {
195 PopStateEvent(double timestamp, Container* container, Type* type);
196 void print() override;
199 class ResetStateEvent : public PajeEvent {
201 ResetStateEvent(double timestamp, Container* container, Type* type);
202 void print() override;
205 class StartLinkEvent : public PajeEvent {
206 Container* sourceContainer_;
212 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
214 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
215 const char* key, int size);
216 void print() override;
219 class EndLinkEvent : public PajeEvent {
220 Container* destContainer;
225 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
227 ~EndLinkEvent() = default;
228 void print() override;
231 class NewEvent : public PajeEvent {
235 NewEvent(double timestamp, Container* container, Type* type, Value* val);
236 void print() override;
239 } // namespace simgrid::instr
240 typedef simgrid::instr::Container* container_t;
244 extern XBT_PRIVATE std::set<std::string> created_categories;
245 extern XBT_PRIVATE std::set<std::string> declared_marks;
246 extern XBT_PRIVATE std::set<std::string> user_host_variables;
247 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
248 extern XBT_PRIVATE std::set<std::string> user_link_variables;
249 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
251 /* instr_paje_header.c */
252 XBT_PRIVATE void TRACE_header(int basic, int size);
255 XBT_PRIVATE void TRACE_paje_start();
256 XBT_PRIVATE void TRACE_paje_end();
257 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
259 /* from instr_config.c */
260 XBT_PRIVATE bool TRACE_needs_platform();
261 XBT_PRIVATE bool TRACE_is_enabled();
262 XBT_PRIVATE bool TRACE_platform();
263 XBT_PRIVATE bool TRACE_platform_topology();
264 XBT_PRIVATE bool TRACE_is_configured();
265 XBT_PRIVATE bool TRACE_categorized();
266 XBT_PRIVATE bool TRACE_uncategorized();
267 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
268 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
269 XBT_PRIVATE bool TRACE_buffer();
270 XBT_PRIVATE bool TRACE_disable_link();
271 XBT_PRIVATE bool TRACE_disable_speed();
272 XBT_PRIVATE bool TRACE_onelink_only();
273 XBT_PRIVATE bool TRACE_disable_destroy();
274 XBT_PRIVATE bool TRACE_basic();
275 XBT_PRIVATE bool TRACE_display_sizes();
276 XBT_PRIVATE char* TRACE_get_comment();
277 XBT_PRIVATE char* TRACE_get_comment_file();
278 XBT_PRIVATE int TRACE_precision();
279 XBT_PRIVATE char* TRACE_get_filename();
280 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
281 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
282 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
283 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
284 XBT_PRIVATE void instr_pause_tracing();
285 XBT_PRIVATE void instr_resume_tracing();
287 /* Public functions used in SMPI */
288 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
289 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
290 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
291 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
292 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
294 /* from resource_utilization.c */
295 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
297 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
299 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
302 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
303 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
304 XBT_PRIVATE long long int instr_new_paje_id();
305 XBT_PUBLIC(container_t) PJ_container_get(const char* name);
306 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
307 XBT_PUBLIC(container_t) PJ_container_get_root ();
308 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
309 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
311 /* instr_paje_types.c */
312 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
315 XBT_PRIVATE void TRACE_TI_start();
316 XBT_PRIVATE void TRACE_TI_end();
318 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
319 XBT_PRIVATE void dump_comment_file(const char* filename);
320 XBT_PRIVATE void dump_comment(const char* comment);
322 struct s_instr_extra_data;
323 typedef struct s_instr_extra_data* instr_extra_data;
354 TRACING_REDUCE_SCATTER,
361 typedef struct s_instr_extra_data {
366 double sleep_duration;
370 const char* datatype1;
371 const char* datatype2;
375 } s_instr_extra_data_t;
377 /* Format of TRACING output.
378 * - paje is the regular format, that we all know
379 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
380 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
381 * using the signal that we will create to cleanup the TRACING
383 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
384 extern instr_fmt_type_t instr_fmt_type;
387 void LogContainerTypeDefinition(simgrid::instr::Type* type);
388 void LogVariableTypeDefinition(simgrid::instr::Type* type);
389 void LogStateTypeDefinition(simgrid::instr::Type* type);
390 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
391 void LogContainerCreation(container_t container);
392 void LogContainerDestruction(container_t container);
393 void LogDefineEventType(simgrid::instr::Type* type);