double compute_cost = std::stod(args[2]);
long communication_cost = std::stol(args[3]);
size_t workers_count = args.size() - 4;
- const char* my_hostname = simgrid::s4u::this_actor::get_host()->get_cname();
+ auto* my_host = simgrid::s4u::this_actor::get_host();
auto mailbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
XBT_DEBUG("Got %zu workers and %ld tasks to process", workers_count, tasks_count);
// setting the variable "is_master" (previously declared) to value 1
- TRACE_host_variable_set(my_hostname, "is_master", 1);
+ simgrid::instr::set_host_variable(my_host, "is_master", 1);
- TRACE_mark("msmark", "start_send_tasks");
+ simgrid::instr::mark("msmark", "start_send_tasks");
for (int i = 0; i < tasks_count; i++) {
// setting the variable "task_creation" to value i
- TRACE_host_variable_set(my_hostname, "task_creation", i);
+ simgrid::instr::set_host_variable(my_host, "task_creation", i);
// setting the category of task to "compute"
Task task = {"task", "compute", compute_cost};
mailbox->put(new Task(task), communication_cost);
}
- TRACE_mark("msmark", "finish_send_tasks");
+ simgrid::instr::mark("msmark", "finish_send_tasks");
XBT_DEBUG("All tasks have been dispatched. Request all workers to stop.");
for (unsigned int i = 0; i < workers_count; i++) {
{
xbt_assert(args.size() == 1, "The worker expects no argument");
- const char* my_hostname = simgrid::s4u::this_actor::get_host()->get_cname();
- auto mailbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
+ auto my_host = simgrid::s4u::this_actor::get_host();
+ auto mailbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
- TRACE_host_variable_set(my_hostname, "is_worker", 1);
- TRACE_host_variable_set(my_hostname, "task_computation", 0);
+ simgrid::instr::set_host_variable(my_host, "is_worker", 1);
+ simgrid::instr::set_host_variable(my_host, "task_computation", 0);
while (true) {
auto task = mailbox->get_unique<Task>();
break;
}
// adding the task's cost to the variable "task_computation"
- TRACE_host_variable_add(my_hostname, "task_computation", task->flops);
+ simgrid::instr::add_host_variable(my_host, "task_computation", task->flops);
simgrid::s4u::this_actor::exec_init(task->flops)
->set_name(task->name)
->set_tracing_category(task->category)
e.load_platform(argv[1]);
// declaring user variables
- TRACE_host_variable_declare("is_worker");
- TRACE_host_variable_declare("is_master");
- TRACE_host_variable_declare("task_creation");
- TRACE_host_variable_declare("task_computation");
+ simgrid::instr::declare_host_variable("is_worker");
+ simgrid::instr::declare_host_variable("is_master");
+ simgrid::instr::declare_host_variable("task_creation");
+ simgrid::instr::declare_host_variable("task_computation");
// declaring user markers and values
- TRACE_declare_mark("msmark");
- TRACE_declare_mark_value("msmark", "start_send_tasks");
- TRACE_declare_mark_value("msmark", "finish_send_tasks");
+ simgrid::instr::declare_mark("msmark");
+ simgrid::instr::declare_mark_value("msmark", "start_send_tasks");
+ simgrid::instr::declare_mark_value("msmark", "finish_send_tasks");
// declaring user categories with RGB colors (values from 0 to 1)
- TRACE_category_with_color("compute", "1 0 0"); // compute is red
- TRACE_category_with_color("finalize", "0 1 0"); // finalize is green
+ simgrid::instr::declare_tracing_category("compute", "1 0 0"); // compute is red
+ simgrid::instr::declare_tracing_category("finalize", "0 1 0"); // finalize is green
// categories without user-defined colors receive random colors generated by the tracing system
- TRACE_category("request");
- TRACE_category_with_color("report", nullptr);
+ simgrid::instr::declare_tracing_category("request");
+ simgrid::instr::declare_tracing_category("report");
e.register_function("master", &master);
e.register_function("worker", &worker);
XBT_DEBUG("Simulation is over");
- unsigned int cursor;
- xbt_dynar_t categories = TRACE_get_categories();
- if (categories) {
+ auto categories = simgrid::instr::get_tracing_categories();
+ if (not categories.empty()) {
XBT_INFO("Declared tracing categories:");
- char* category;
- xbt_dynar_foreach (categories, cursor, category) {
- XBT_INFO("%s", category);
- }
- xbt_dynar_free(&categories);
+ for (const auto& category : categories)
+ XBT_INFO("%s", category.c_str());
}
- xbt_dynar_t marks = TRACE_get_marks();
- if (marks) {
+ auto marks = simgrid::instr::get_marks();
+ if (not marks.empty()) {
XBT_INFO("Declared marks:");
- char* mark;
- xbt_dynar_foreach (marks, cursor, mark) {
- XBT_INFO("%s", mark);
- }
- xbt_dynar_free(&marks);
+ for (const auto& mark : marks)
+ XBT_INFO("%s", mark.c_str());
}
return 0;
#include <simgrid/Exception.hpp>
#include <simgrid/kernel/routing/NetPoint.hpp>
+#include <simgrid/s4u/Host.hpp>
#include <xbt/random.hpp>
#include "src/instr/instr_private.hpp"
std::set<std::string, std::less<>> user_vm_variables;
std::set<std::string, std::less<>> user_link_variables;
+static void instr_user_variable(double time, const char* resource, const std::string& variable_name,
+ const std::string& parent_type, double value, InstrUserVariable what,
+ const std::string& color, std::set<std::string, std::less<>>* filter)
+{
+ /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
+ if (not TRACE_is_enabled() || not TRACE_needs_platform())
+ return;
+
+ // check if variable is already declared
+ auto created = filter->find(variable_name);
+ if (what == InstrUserVariable::DECLARE) {
+ if (created == filter->end()) { // not declared yet
+ filter->insert(variable_name);
+ instr_new_user_variable_type(parent_type, variable_name, color);
+ }
+ } else {
+ if (created != filter->end()) { // declared, let's work
+ simgrid::instr::VariableType* variable =
+ simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
+ switch (what) {
+ case InstrUserVariable::SET:
+ variable->set_event(time, value);
+ break;
+ case InstrUserVariable::ADD:
+ variable->add_event(time, value);
+ break;
+ case InstrUserVariable::SUB:
+ variable->sub_event(time, value);
+ break;
+ default:
+ THROW_IMPOSSIBLE;
+ }
+ }
+ }
+}
+
+static void instr_user_srcdst_variable(double time, const char* src, const char* dst, const std::string& variable,
+ const std::string& parent_type, double value, InstrUserVariable what)
+{
+ const simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
+ xbt_assert(src_elm, "Element '%s' not found!", src);
+
+ const simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
+ xbt_assert(dst_elm, "Element '%s' not found!", dst);
+
+ std::vector<simgrid::kernel::resource::StandardLinkImpl*> route;
+ simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
+ for (auto const& link : route)
+ instr_user_variable(time, link->get_cname(), variable, parent_type, value, what, "", &user_link_variables);
+}
+
+namespace simgrid {
+namespace instr {
+
+void declare_host_variable(const std::string& variable, const std::string& color)
+{
+ instr_user_variable(0, nullptr, variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
+}
+
+void set_host_variable(const s4u::Host* host, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, host->get_cname(), variable, "HOST", value, InstrUserVariable::SET, "",
+ &user_host_variables);
+}
+
+void add_host_variable(const s4u::Host* host, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, host->get_cname(), variable, "HOST", value, InstrUserVariable::ADD, "",
+ &user_host_variables);
+}
+
+void sub_host_variable(const s4u::Host* host, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, host->get_cname(), variable, "HOST", value, InstrUserVariable::SUB, "",
+ &user_host_variables);
+}
+
+const std::set<std::string, std::less<>>& get_host_variables()
+{
+ return user_host_variables;
+}
+
+void declare_link_variable(const std::string& variable, const std::string& color)
+{
+ instr_user_variable(0, nullptr, variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
+}
+
+void set_link_variable(const s4u::Link* link, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, link->get_cname(), variable, "LINK", value, InstrUserVariable::SET, "",
+ &user_link_variables);
+}
+
+void set_link_variable(const s4u::Host* src, const s4u::Host* dst, const std::string& variable, double value,
+ double time)
+{
+ instr_user_srcdst_variable(time, src->get_cname(), dst->get_cname(), variable, "LINK", value, InstrUserVariable::SET);
+}
+
+void add_link_variable(const s4u::Link* link, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, link->get_cname(), variable, "LINK", value, InstrUserVariable::ADD, "",
+ &user_link_variables);
+}
+
+void add_link_variable(const s4u::Host* src, const s4u::Host* dst, const std::string& variable, double value,
+ double time)
+{
+ instr_user_srcdst_variable(time, src->get_cname(), dst->get_cname(), variable, "LINK", value, InstrUserVariable::ADD);
+}
+
+void sub_link_variable(const s4u::Link* link, const std::string& variable, double value, double time)
+{
+ instr_user_variable(time, link->get_cname(), variable, "LINK", value, InstrUserVariable::SUB, "",
+ &user_link_variables);
+}
+
+void sub_link_variable(const s4u::Host* src, const s4u::Host* dst, const std::string& variable, double value,
+ double time)
+{
+ instr_user_srcdst_variable(time, src->get_cname(), dst->get_cname(), variable, "LINK", value, InstrUserVariable::SUB);
+}
+
+const std::set<std::string, std::less<>>& get_link_variables()
+{
+ return user_link_variables;
+}
+
+void declare_mark(const std::string& mark_type)
+{
+ /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
+ if (not TRACE_is_enabled() || not TRACE_needs_platform())
+ return;
+
+ // check if mark_type is already declared
+ if (declared_marks.find(mark_type) != declared_marks.end()) {
+ throw TracingError(XBT_THROW_POINT,
+ xbt::string_printf("mark_type with name (%s) is already declared", mark_type.c_str()));
+ }
+
+ XBT_DEBUG("MARK,declare %s", mark_type.c_str());
+ Container::get_root()->get_type()->by_name_or_create<EventType>(mark_type);
+ declared_marks.emplace(mark_type);
+}
+
+void declare_mark_value(const std::string& mark_type, const std::string& mark_value, const std::string& mark_color)
+{
+ /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
+ if (not TRACE_is_enabled() || not TRACE_needs_platform())
+ return;
+
+ auto* type = static_cast<EventType*>(Container::get_root()->get_type()->by_name(mark_type));
+ if (not type) {
+ throw TracingError(XBT_THROW_POINT,
+ xbt::string_printf("mark_type with name (%s) is not declared", mark_type.c_str()));
+ } else {
+ XBT_DEBUG("MARK, declare_value %s %s %s", mark_type.c_str(), mark_value.c_str(), mark_color.c_str());
+ type->add_entity_value(mark_value, mark_color);
+ }
+}
+
+void mark(const std::string& mark_type, const std::string& mark_value)
+{
+ /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
+ if (not TRACE_is_enabled() || not TRACE_needs_platform())
+ return;
+
+ // check if mark_type is already declared
+ auto* type = static_cast<EventType*>(Container::get_root()->get_type()->by_name(mark_type));
+ if (not type) {
+ throw TracingError(XBT_THROW_POINT,
+ xbt::string_printf("mark_type with name (%s) is not declared", mark_type.c_str()));
+ } else {
+ XBT_DEBUG("MARK %s %s", mark_type.c_str(), mark_value.c_str());
+ new NewEvent(simgrid_get_clock(), Container::get_root(), type, type->get_entity_value(mark_value));
+ }
+}
+
+const std::set<std::string, std::less<>>& get_marks()
+{
+ return declared_marks;
+}
+
+void declare_tracing_category(const std::string& name, const std::string& color)
+{
+ /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
+ if (not TRACE_is_enabled() || not TRACE_needs_platform() || not TRACE_categorized())
+ return;
+
+ // check if category is already created
+ if (created_categories.find(name) != created_categories.end())
+ return;
+
+ created_categories.emplace(name);
+
+ // define final_color
+ std::string final_color;
+ if (color.empty()) {
+ // generate a random color
+ double red = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
+ double green = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
+ double blue = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
+ final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
+ } else {
+ final_color = std::string(color);
+ }
+
+ XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", name.c_str(), color.c_str(), final_color.c_str());
+
+ // define the type of this category on top of hosts and links
+ instr_new_variable_type(name, final_color);
+}
+
+const std::set<std::string, std::less<>>& get_tracing_categories()
+{
+ return created_categories;
+}
+
+} // namespace instr
+} // namespace simgrid
+
static xbt_dynar_t instr_set_to_dynar(const std::set<std::string, std::less<>>& filter)
{
if (not TRACE_is_enabled() || not TRACE_needs_platform())
*
* @param category The name of the new tracing category to be created.
*
- * @see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
+ * @see TRACE_category_with_color
*/
void TRACE_category(const char *category)
{
- TRACE_category_with_color (category, nullptr);
+ simgrid::instr::declare_tracing_category(category);
}
/** @ingroup TRACE_category
* @param color The color of the category (see @ref outcomes_vizu to
* know how to correctly specify the color)
*
- * @see MSG_task_set_category, SD_task_set_category
*/
void TRACE_category_with_color (const char *category, const char *color)
{
- /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
- if (not TRACE_is_enabled() || not TRACE_needs_platform())
- return;
-
- if (not(TRACE_categorized() && category != nullptr))
- return;
-
- //check if category is already created
- if (created_categories.find(category) != created_categories.end())
- return;
-
- created_categories.emplace(category);
-
- //define final_color
- std::string final_color;
- if (not color) {
- //generate a random color
- double red = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
- double green = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
- double blue = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
- final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
- }else{
- final_color = std::string(color);
- }
-
- XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color.c_str());
-
- //define the type of this category on top of hosts and links
- instr_new_variable_type (category, final_color);
+ simgrid::instr::declare_tracing_category(category, color);
}
/** @ingroup TRACE_category
*
* @return A dynar with the declared categories, must be freed with xbt_dynar_free.
*
- * @see MSG_task_set_category, SD_task_set_category
*/
xbt_dynar_t TRACE_get_categories ()
{
*/
void TRACE_declare_mark(const char *mark_type)
{
- /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
- if (not TRACE_is_enabled() || not TRACE_needs_platform())
- return;
-
- xbt_assert(mark_type, "mark_type is nullptr");
-
- //check if mark_type is already declared
- if (declared_marks.find(mark_type) != declared_marks.end()) {
- throw simgrid::TracingError(XBT_THROW_POINT,
- simgrid::xbt::string_printf("mark_type with name (%s) is already declared", mark_type));
- }
-
- XBT_DEBUG("MARK,declare %s", mark_type);
- simgrid::instr::Container::get_root()->get_type()->by_name_or_create<simgrid::instr::EventType>(mark_type);
- declared_marks.emplace(mark_type);
+ simgrid::instr::declare_mark(mark_type);
}
/** @ingroup TRACE_mark
*/
void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mark_value, const char *mark_color)
{
- /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
- if (not TRACE_is_enabled() || not TRACE_needs_platform())
- return;
-
- xbt_assert(mark_type, "mark_type is nullptr");
- xbt_assert(mark_value, "mark_value is nullptr");
-
- auto* type =
- static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->get_type()->by_name(mark_type));
- if (not type) {
- throw simgrid::TracingError(XBT_THROW_POINT,
- simgrid::xbt::string_printf("mark_type with name (%s) is not declared", mark_type));
- } else {
- if (not mark_color)
- mark_color = "1.0 1.0 1.0" /*white*/;
-
- XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
- type->add_entity_value(mark_value, mark_color);
- }
+ simgrid::instr::declare_mark_value(mark_type, mark_value, mark_color);
}
/** @ingroup TRACE_mark
*/
void TRACE_declare_mark_value (const char *mark_type, const char *mark_value)
{
- TRACE_declare_mark_value_with_color (mark_type, mark_value, nullptr);
+ simgrid::instr::declare_mark_value(mark_type, mark_value);
}
/**
*/
void TRACE_mark(const char *mark_type, const char *mark_value)
{
- /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
- if (not TRACE_is_enabled() || not TRACE_needs_platform())
- return;
-
- xbt_assert(mark_type, "mark_type is nullptr");
- xbt_assert(mark_value, "mark_value is nullptr");
-
- //check if mark_type is already declared
- auto* type =
- static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->get_type()->by_name(mark_type));
- if (not type) {
- throw simgrid::TracingError(XBT_THROW_POINT,
- simgrid::xbt::string_printf("mark_type with name (%s) is not declared", mark_type));
- } else {
- XBT_DEBUG("MARK %s %s", mark_type, mark_value);
- new simgrid::instr::NewEvent(simgrid_get_clock(), simgrid::instr::Container::get_root(), type,
- type->get_entity_value(mark_value));
- }
+ simgrid::instr::mark(mark_type, mark_value);
}
/** @ingroup TRACE_mark
return instr_set_to_dynar(declared_marks);
}
-static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* parent_type,
- double value, InstrUserVariable what, const char* color,
- std::set<std::string, std::less<>>* filter)
-{
- /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
- if (not TRACE_is_enabled() || not TRACE_needs_platform())
- return;
-
- //check if variable is already declared
- auto created = filter->find(variable_name);
- if (what == InstrUserVariable::DECLARE) {
- if (created == filter->end()) { // not declared yet
- filter->insert(variable_name);
- instr_new_user_variable_type(parent_type, variable_name, color == nullptr ? "" : color);
- }
- }else{
- if (created != filter->end()) { // declared, let's work
- simgrid::instr::VariableType* variable =
- simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
- switch (what){
- case InstrUserVariable::SET:
- variable->set_event(time, value);
- break;
- case InstrUserVariable::ADD:
- variable->add_event(time, value);
- break;
- case InstrUserVariable::SUB:
- variable->sub_event(time, value);
- break;
- default:
- THROW_IMPOSSIBLE;
- }
- }
- }
-}
-
-static void instr_user_srcdst_variable(double time, const char* src, const char* dst, const char* variable,
- const char* parent_type, double value, InstrUserVariable what)
-{
- const simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
- xbt_assert(src_elm, "Element '%s' not found!", src);
-
- const simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
- xbt_assert(dst_elm, "Element '%s' not found!", dst);
-
- std::vector<simgrid::kernel::resource::StandardLinkImpl*> route;
- simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
- for (auto const& link : route)
- instr_user_variable(time, link->get_cname(), variable, parent_type, value, what, nullptr, &user_link_variables);
-}
-
/** @ingroup TRACE_API
* @brief Creates a file with the topology of the platform file used for the simulator.
*