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/instr/instr_paje_containers.hpp"
15 #include "src/instr/instr_paje_types.hpp"
16 #include "src/internal_config.h"
17 #include "xbt/graph.h"
18 #include <iomanip> /** std::setprecision **/
25 #include <direct.h> // _mkdir
26 /* Need to define function drand48 for Windows */
27 /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */
28 #define drand48() (rand() / (RAND_MAX + 1.0))
43 enum e_event_type : unsigned int {
44 PAJE_DefineContainerType,
45 PAJE_DefineVariableType,
49 PAJE_DefineEntityValue,
51 PAJE_DestroyContainer,
71 explicit EntityValue(std::string name, std::string color, Type* father);
72 ~EntityValue() = default;
73 const char* getCname() { return name_.c_str(); }
74 long long int getId() { return id_; }
85 e_event_type eventType_;
86 PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
87 : container(container), type(type), timestamp_(timestamp), eventType_(eventType){};
88 virtual void print() = 0;
90 void insertIntoBuffer();
93 class SetVariableEvent : public PajeEvent {
97 SetVariableEvent(double timestamp, Container* container, Type* type, double value);
98 void print() override;
101 class AddVariableEvent : public PajeEvent {
105 AddVariableEvent(double timestamp, Container* container, Type* type, double value);
106 void print() override;
109 class SubVariableEvent : public PajeEvent {
113 SubVariableEvent(double timestamp, Container* container, Type* type, double value);
114 void print() override;
117 class StateEvent : public PajeEvent {
119 std::string filename;
121 void* extra_ = nullptr;
124 StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value);
125 StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value,
127 void print() override;
130 class StartLinkEvent : public PajeEvent {
131 Container* sourceContainer_;
137 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
139 StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, std::string value,
140 std::string key, int size);
141 void print() override;
144 class EndLinkEvent : public PajeEvent {
145 Container* destContainer;
150 EndLinkEvent(double timestamp, Container* container, Type* type, Container* destContainer, std::string value,
152 ~EndLinkEvent() = default;
153 void print() override;
156 class NewEvent : public PajeEvent {
160 NewEvent(double timestamp, Container* container, Type* type, EntityValue* val);
161 void print() override;
164 } // namespace simgrid::instr
165 typedef simgrid::instr::Container* container_t;
169 extern XBT_PRIVATE std::set<std::string> created_categories;
170 extern XBT_PRIVATE std::set<std::string> declared_marks;
171 extern XBT_PRIVATE std::set<std::string> user_host_variables;
172 extern XBT_PRIVATE std::set<std::string> user_vm_variables;
173 extern XBT_PRIVATE std::set<std::string> user_link_variables;
174 extern XBT_PRIVATE double TRACE_last_timestamp_to_dump;
176 /* instr_paje_header.c */
177 XBT_PRIVATE void TRACE_header(bool basic, int size);
180 XBT_PRIVATE void TRACE_paje_start();
181 XBT_PRIVATE void TRACE_paje_end();
183 /* from instr_config.c */
184 XBT_PRIVATE bool TRACE_needs_platform();
185 XBT_PRIVATE bool TRACE_is_enabled();
186 XBT_PRIVATE bool TRACE_platform();
187 XBT_PRIVATE bool TRACE_platform_topology();
188 XBT_PRIVATE bool TRACE_is_configured();
189 XBT_PRIVATE bool TRACE_categorized();
190 XBT_PRIVATE bool TRACE_uncategorized();
191 XBT_PRIVATE bool TRACE_msg_process_is_enabled();
192 XBT_PRIVATE bool TRACE_msg_vm_is_enabled();
193 XBT_PRIVATE bool TRACE_buffer();
194 XBT_PRIVATE bool TRACE_disable_link();
195 XBT_PRIVATE bool TRACE_disable_speed();
196 XBT_PRIVATE bool TRACE_onelink_only();
197 XBT_PRIVATE bool TRACE_disable_destroy();
198 XBT_PRIVATE bool TRACE_basic();
199 XBT_PRIVATE bool TRACE_display_sizes();
200 XBT_PRIVATE char* TRACE_get_comment();
201 XBT_PRIVATE char* TRACE_get_comment_file();
202 XBT_PRIVATE int TRACE_precision();
203 XBT_PRIVATE char* TRACE_get_filename();
204 XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
205 XBT_PRIVATE char* TRACE_get_viva_cat_conf();
206 XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
207 XBT_PRIVATE void TRACE_generate_viva_cat_conf();
208 XBT_PRIVATE void instr_pause_tracing();
209 XBT_PRIVATE void instr_resume_tracing();
211 /* Public functions used in SMPI */
212 XBT_PUBLIC(bool) TRACE_smpi_is_enabled();
213 XBT_PUBLIC(bool) TRACE_smpi_is_grouped();
214 XBT_PUBLIC(bool) TRACE_smpi_is_computing();
215 XBT_PUBLIC(bool) TRACE_smpi_is_sleeping();
216 XBT_PUBLIC(bool) TRACE_smpi_view_internals();
218 /* from resource_utilization.c */
219 XBT_PRIVATE void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now,
221 XBT_PRIVATE void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now,
223 XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc();
226 extern XBT_PRIVATE std::set<std::string> trivaNodeTypes;
227 extern XBT_PRIVATE std::set<std::string> trivaEdgeTypes;
228 XBT_PRIVATE long long int instr_new_paje_id();
229 void instr_new_variable_type(std::string new_typename, std::string color);
230 void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color);
231 void instr_new_user_state_type(std::string father_type, std::string new_typename);
232 void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color);
235 XBT_PRIVATE void TRACE_TI_start();
236 XBT_PRIVATE void TRACE_TI_end();
238 XBT_PRIVATE void TRACE_paje_dump_buffer(bool force);
239 XBT_PRIVATE void dump_comment_file(std::string filename);
240 XBT_PRIVATE void dump_comment(std::string comment);
271 TRACING_REDUCE_SCATTER,
278 struct s_instr_extra_data_t {
283 double sleep_duration;
287 const char* datatype1;
288 const char* datatype2;
293 typedef s_instr_extra_data_t* instr_extra_data;
295 /* Format of TRACING output.
296 * - paje is the regular format, that we all know
297 * - TI is a trick to reuse the tracing functions to generate a time independent trace during the execution. Such
298 * trace can easily be replayed with smpi_replay afterward. This trick should be removed and replaced by some code
299 * using the signal that we will create to cleanup the TRACING
301 enum instr_fmt_type_t { instr_fmt_paje, instr_fmt_TI };
302 extern instr_fmt_type_t instr_fmt_type;