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(const char* typeNameBuff, const char* key, std::string color, e_entity_types kind, Type* father);
72 Type* getChild(const char* name);
73 Type* getChildOrNull(const char* 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 bool isColored() { return not color_.empty(); }
83 //--------------------------------------------------
90 explicit Value(std::string name, std::string color, Type* father);
95 static Value* byNameOrCreate(std::string name, std::string color, Type* father);
96 static Value* byName(std::string name, Type* father);
97 const char* getCname() { return name_.c_str(); }
98 const char* getId() { return id_.c_str(); }
99 bool isColored() { return not color_.empty(); }
103 //--------------------------------------------------
104 enum e_container_types {
115 //--------------------------------------------------
119 Container(std::string name, simgrid::instr::e_container_types kind, Container* father);
120 virtual ~Container();
122 sg_netpoint_t netpoint_;
123 std::string name_; /* Unique name of this container */
124 std::string id_; /* Unique id of this container */
125 Type* type_; /* Type of this container */
126 int level_ = 0; /* Level in the hierarchy, root level is 0 */
127 e_container_types kind_; /* This container is of what kind */
129 std::map<std::string, Container*> children_;
130 static simgrid::instr::Container* byNameOrNull(std::string name);
131 static simgrid::instr::Container* byName(std::string name);
134 //--------------------------------------------------
137 Container* container;
142 e_event_type eventType_;
143 PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
144 : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
145 virtual void print() = 0;
146 virtual ~PajeEvent();
147 void insertIntoBuffer();
150 //--------------------------------------------------
151 class SetVariableEvent : public PajeEvent {
155 SetVariableEvent(double timestamp, Container* container, Type* type, double value);
156 void print() override;
159 class AddVariableEvent : public PajeEvent {
163 AddVariableEvent(double timestamp, Container* container, Type* type, double value);
164 void print() override;
166 //--------------------------------------------------
168 class SubVariableEvent : public PajeEvent {
172 SubVariableEvent(double timestamp, Container* container, Type* type, double value);
173 void print() override;
175 //--------------------------------------------------
177 class SetStateEvent : public PajeEvent {
179 const char* filename;
183 SetStateEvent(double timestamp, Container* container, Type* type, Value* val);
184 void print() override;
187 class PushStateEvent : public PajeEvent {
189 const char* filename;
194 PushStateEvent(double timestamp, Container* container, Type* type, Value* val);
195 PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra);
196 void print() override;
199 class PopStateEvent : public PajeEvent {
201 PopStateEvent(double timestamp, Container* container, Type* type);
202 void print() override;
205 class ResetStateEvent : public PajeEvent {
207 ResetStateEvent(double timestamp, Container* container, Type* type);
208 void print() override;
211 class StartLinkEvent : public PajeEvent {
212 Container* sourceContainer_;
218 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
220 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
221 std::string key, int size);
222 void print() override;
225 class EndLinkEvent : public PajeEvent {
226 Container* destContainer;
231 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
233 ~EndLinkEvent() = default;
234 void print() override;
237 class NewEvent : public PajeEvent {
241 NewEvent(double timestamp, Container* container, Type* type, Value* val);
242 void print() override;
245 } // namespace simgrid::instr
246 typedef simgrid::instr::Container* container_t;
250 extern XBT_PRIVATE std::set<std::string> created_categories;
251 extern XBT_PRIVATE std::set<std::string> declared_marks;
252 extern XBT_PRIVATE std::set<std::string> user_host_variables;
253 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
254 extern XBT_PRIVATE std::set<std::string> user_link_variables;
255 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
257 /* instr_paje_header.c */
258 XBT_PRIVATE void TRACE_header(int basic, int size);
261 XBT_PRIVATE void TRACE_paje_start();
262 XBT_PRIVATE void TRACE_paje_end();
263 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
265 /* from instr_config.c */
266 XBT_PRIVATE bool TRACE_needs_platform();
267 XBT_PRIVATE bool TRACE_is_enabled();
268 XBT_PRIVATE bool TRACE_platform();
269 XBT_PRIVATE bool TRACE_platform_topology();
270 XBT_PRIVATE bool TRACE_is_configured();
271 XBT_PRIVATE bool TRACE_categorized();
272 XBT_PRIVATE bool TRACE_uncategorized();
273 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
274 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
275 XBT_PRIVATE bool TRACE_buffer();
276 XBT_PRIVATE bool TRACE_disable_link();
277 XBT_PRIVATE bool TRACE_disable_speed();
278 XBT_PRIVATE bool TRACE_onelink_only();
279 XBT_PRIVATE bool TRACE_disable_destroy();
280 XBT_PRIVATE bool TRACE_basic();
281 XBT_PRIVATE bool TRACE_display_sizes();
282 XBT_PRIVATE char* TRACE_get_comment();
283 XBT_PRIVATE char* TRACE_get_comment_file();
284 XBT_PRIVATE int TRACE_precision();
285 XBT_PRIVATE char* TRACE_get_filename();
286 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
287 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
288 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
289 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
290 XBT_PRIVATE void instr_pause_tracing();
291 XBT_PRIVATE void instr_resume_tracing();
293 /* Public functions used in SMPI */
294 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
295 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
296 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
297 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
298 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
300 /* from resource_utilization.c */
301 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
303 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
305 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
308 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
309 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
310 XBT_PRIVATE long long int instr_new_paje_id();
311 XBT_PUBLIC(container_t) PJ_container_get_root ();
312 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
313 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
315 /* instr_paje_types.c */
316 XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root();
319 XBT_PRIVATE void TRACE_TI_start();
320 XBT_PRIVATE void TRACE_TI_end();
322 XBT_PRIVATE void TRACE_paje_dump_buffer(int force);
323 XBT_PRIVATE void dump_comment_file(const char* filename);
324 XBT_PRIVATE void dump_comment(const char* comment);
355 TRACING_REDUCE_SCATTER,
362 struct s_instr_extra_data_t {
367 double sleep_duration;
371 const char* datatype1;
372 const char* datatype2;
377 typedef s_instr_extra_data_t* instr_extra_data;
379 /* Format of TRACING output.
380 * - paje is the regular format, that we all know
381 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
382 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
383 * using the signal that we will create to cleanup the TRACING
385 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
386 extern instr_fmt_type_t instr_fmt_type;
389 void LogContainerTypeDefinition(simgrid::instr::Type* type);
390 void LogVariableTypeDefinition(simgrid::instr::Type* type);
391 void LogStateTypeDefinition(simgrid::instr::Type* type);
392 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest);
393 void LogContainerCreation(container_t container);
394 void LogContainerDestruction(container_t container);
395 void LogDefineEventType(simgrid::instr::Type* type);