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 {
182 const char* filename;
187 PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
188 PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
189 void print() override;
192 class PopStateEvent : public PajeEvent {
194 PopStateEvent(double timestamp, Container* container, Type* type);
195 void print() override;
198 class ResetStateEvent : public PajeEvent {
200 ResetStateEvent(double timestamp, Container* container, Type* type);
201 void print() override;
204 class StartLinkEvent : public PajeEvent {
205 Container* sourceContainer_;
211 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
213 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value,
214 const char* key, int size);
215 void print() override;
218 class EndLinkEvent : public PajeEvent {
219 Container* destContainer;
224 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
226 ~EndLinkEvent() = default;
227 void print() override;
230 class NewEvent : public PajeEvent {
234 NewEvent(double timestamp, Container* container, Type* type, Value* val);
235 void print() override;
238 } // namespace simgrid::instr
239 typedef simgrid::instr::Container* container_t;
243 extern XBT_PRIVATE std::set<std::string> created_categories;
244 extern XBT_PRIVATE std::set<std::string> declared_marks;
245 extern XBT_PRIVATE std::set<std::string> user_host_variables;
246 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
247 extern XBT_PRIVATE std::set<std::string> user_link_variables;
248 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
250 /* instr_paje_header.c */
251 XBT_PRIVATE void TRACE_header(int basic, int size);
254 XBT_PRIVATE void TRACE_paje_start();
255 XBT_PRIVATE void TRACE_paje_end();
256 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
258 /* from instr_config.c */
259 XBT_PRIVATE bool TRACE_needs_platform();
260 XBT_PRIVATE bool TRACE_is_enabled();
261 XBT_PRIVATE bool TRACE_platform();
262 XBT_PRIVATE bool TRACE_platform_topology();
263 XBT_PRIVATE bool TRACE_is_configured();
264 XBT_PRIVATE bool TRACE_categorized();
265 XBT_PRIVATE bool TRACE_uncategorized();
266 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
267 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
268 XBT_PRIVATE bool TRACE_buffer();
269 XBT_PRIVATE bool TRACE_disable_link();
270 XBT_PRIVATE bool TRACE_disable_speed();
271 XBT_PRIVATE bool TRACE_onelink_only();
272 XBT_PRIVATE bool TRACE_disable_destroy();
273 XBT_PRIVATE bool TRACE_basic();
274 XBT_PRIVATE bool TRACE_display_sizes();
275 XBT_PRIVATE char* TRACE_get_comment();
276 XBT_PRIVATE char* TRACE_get_comment_file();
277 XBT_PRIVATE int TRACE_precision();
278 XBT_PRIVATE char* TRACE_get_filename();
279 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
280 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
281 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
282 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
283 XBT_PRIVATE void instr_pause_tracing();
284 XBT_PRIVATE void instr_resume_tracing();
286 /* Public functions used in SMPI */
287 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
288 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
289 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
290 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
291 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
293 /* from resource_utilization.c */
294 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
296 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
298 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
301 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
302 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
303 XBT_PRIVATE long long int instr_new_paje_id();
304 XBT_PUBLIC(container_t) PJ_container_get(const char* name);
305 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
306 XBT_PUBLIC(container_t) PJ_container_get_root ();
307 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
308 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
310 /* instr_paje_types.c */
311 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
314 XBT_PRIVATE void TRACE_TI_start();
315 XBT_PRIVATE void TRACE_TI_end();
317 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
318 XBT_PRIVATE void dump_comment_file(const char* filename);
319 XBT_PRIVATE void dump_comment(const char* comment);
321 struct s_instr_extra_data;
322 typedef struct s_instr_extra_data* instr_extra_data;
353 TRACING_REDUCE_SCATTER,
360 typedef struct s_instr_extra_data {
365 double sleep_duration;
369 const char* datatype1;
370 const char* datatype2;
374 } s_instr_extra_data_t;
376 /* Format of TRACING output.
377 * - paje is the regular format, that we all know
378 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
379 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
380 * using the signal that we will create to cleanup the TRACING
382 typedef enum { instr_fmt_paje, instr_fmt_TI } instr_fmt_type_t;
383 extern instr_fmt_type_t instr_fmt_type;
386 void LogContainerTypeDefinition(simgrid::instr::Type* type);
387 void LogVariableTypeDefinition(simgrid::instr::Type* type);
388 void LogStateTypeDefinition(simgrid::instr::Type* type);
389 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
390 void LogContainerCreation(container_t container);
391 void LogContainerDestruction(container_t container);
392 void LogDefineEventType(simgrid::instr::Type* type);