X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e94c2a7fc81a82998524aa55db075be69990d4ea..657a66f7b1356f4d91ae3392f2cd999f0406a60c:/src/instr/instr_interface.cpp diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index c55c99fc7a..245e6092a7 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -1,34 +1,35 @@ -/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/Exception.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include "src/instr/instr_private.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/surf_private.hpp" #include "surf/surf.hpp" +#include "xbt/random.hpp" #include +#include enum class InstrUserVariable { DECLARE, SET, ADD, SUB }; XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API"); -std::set created_categories; -std::set declared_marks; -std::set user_host_variables; -std::set user_vm_variables; -std::set user_link_variables; -extern std::set trivaNodeTypes; -extern std::set trivaEdgeTypes; +std::set> created_categories; +std::set> declared_marks; +std::set> user_host_variables; +std::set> user_vm_variables; +std::set> user_link_variables; -static xbt_dynar_t instr_set_to_dynar(std::set* filter) +static xbt_dynar_t instr_set_to_dynar(const std::set>& filter) { if (not TRACE_is_enabled() || not TRACE_needs_platform()) return nullptr; xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref); - for (auto const& name : *filter) + for (auto const& name : filter) xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str())); return ret; @@ -57,7 +58,7 @@ void TRACE_category(const char *category) /** @ingroup TRACE_category * @brief Declare a new category with a color. * - * Same as #TRACE_category, but let user specify a color encoded as a RGB-like string with three floats from 0 to 1. + * Same as #TRACE_category, but let user specify a color encoded as an RGB-like string with three floats from 0 to 1. * So, to specify a red color, pass "1 0 0" as color parameter. A light-gray color can be specified using "0.7 0.7 0.7" * as color. This function has no effect if a category with the same name has been already declared. * @@ -81,16 +82,16 @@ void TRACE_category_with_color (const char *category, const char *color) //check if category is already created if (created_categories.find(category) != created_categories.end()) return; - else - created_categories.insert(category); + + created_categories.emplace(category); //define final_color std::string final_color; if (not color) { //generate a random color - double red = drand48(); - double green = drand48(); - double blue = drand48(); + 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); @@ -118,7 +119,7 @@ xbt_dynar_t TRACE_get_categories () { if (not TRACE_is_enabled() || not TRACE_categorized()) return nullptr; - return instr_set_to_dynar(&created_categories); + return instr_set_to_dynar(created_categories); } /** @ingroup TRACE_mark @@ -133,7 +134,7 @@ xbt_dynar_t TRACE_get_categories () */ void TRACE_declare_mark(const char *mark_type) { - /* safe switchs. tracing has to be activated and if platform is not traced, we can't deal with marks */ + /* 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; @@ -141,12 +142,13 @@ void TRACE_declare_mark(const char *mark_type) //check if mark_type is already declared if (declared_marks.find(mark_type) != declared_marks.end()) { - THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type); + 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()->type_->by_name_or_create(mark_type); - declared_marks.insert(mark_type); + declared_marks.emplace(mark_type); } /** @ingroup TRACE_mark @@ -176,7 +178,8 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar simgrid::instr::EventType* type = static_cast(simgrid::instr::Container::get_root()->type_->by_name(mark_type)); if (not type) { - THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_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*/; @@ -230,10 +233,11 @@ void TRACE_mark(const char *mark_type, const char *mark_value) simgrid::instr::EventType* type = static_cast(simgrid::instr::Container::get_root()->type_->by_name(mark_type)); if (not type) { - THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_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(MSG_get_clock(), simgrid::instr::Container::get_root(), type, + new simgrid::instr::NewEvent(simgrid_get_clock(), simgrid::instr::Container::get_root(), type, type->get_entity_value(mark_value)); } } @@ -250,11 +254,12 @@ xbt_dynar_t TRACE_get_marks () if (not TRACE_is_enabled()) return nullptr; - return instr_set_to_dynar(&declared_marks); + return instr_set_to_dynar(declared_marks); } static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* father_type, - double value, InstrUserVariable what, const char* color, std::set* filter) + double value, InstrUserVariable what, const char* color, + std::set>* 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()) @@ -283,7 +288,6 @@ static void instr_user_variable(double time, const char* resource, const char* v break; default: THROW_IMPOSSIBLE; - break; } } } @@ -293,12 +297,10 @@ static void instr_user_srcdst_variable(double time, const char *src, const char const char *father_type, double value, InstrUserVariable what) { simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src); - if (not src_elm) - xbt_die("Element '%s' not found!",src); + xbt_assert(src_elm, "Element '%s' not found!", src); simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst); - if (not dst_elm) - xbt_die("Element '%s' not found!",dst); + xbt_assert(dst_elm, "Element '%s' not found!", dst); std::vector route; simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr); @@ -311,7 +313,7 @@ static void instr_user_srcdst_variable(double time, const char *src, const char * * The graph topology will have the following properties: all hosts, links and routers of the platform file are mapped * to graph nodes; routes are mapped to edges. - * The platform's AS are not represented in the output. + * The platform's zones are not represented in the output. * * @param filename The name of the file that will hold the graph. * @@ -319,14 +321,7 @@ static void instr_user_srcdst_variable(double time, const char *src, const char */ int TRACE_platform_graph_export_graphviz (const char *filename) { - /* returns 1 if successful, 0 otherwise */ - if (not TRACE_is_enabled()) - return 0; - xbt_graph_t g = instr_routing_platform_graph(); - if (g == nullptr) - return 0; - instr_routing_platform_graph_export_graphviz (g, filename); - xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr); + simgrid::instr::platform_graph_export_graphviz(filename); return 1; } @@ -378,7 +373,7 @@ void TRACE_vm_variable_declare_with_color (const char *variable, const char *col */ void TRACE_vm_variable_set (const char *vm, const char *variable, double value) { - TRACE_vm_variable_set_with_time (MSG_get_clock(), vm, variable, value); + TRACE_vm_variable_set_with_time(simgrid_get_clock(), vm, variable, value); } /** @ingroup TRACE_user_variables @@ -392,7 +387,7 @@ void TRACE_vm_variable_set (const char *vm, const char *variable, double value) */ void TRACE_vm_variable_add (const char *vm, const char *variable, double value) { - TRACE_vm_variable_add_with_time (MSG_get_clock(), vm, variable, value); + TRACE_vm_variable_add_with_time(simgrid_get_clock(), vm, variable, value); } /** @ingroup TRACE_user_variables @@ -406,7 +401,7 @@ void TRACE_vm_variable_add (const char *vm, const char *variable, double value) */ void TRACE_vm_variable_sub (const char *vm, const char *variable, double value) { - TRACE_vm_variable_sub_with_time (MSG_get_clock(), vm, variable, value); + TRACE_vm_variable_sub_with_time(simgrid_get_clock(), vm, variable, value); } /** @ingroup TRACE_user_variables @@ -512,7 +507,7 @@ void TRACE_host_variable_declare_with_color (const char *variable, const char *c */ void TRACE_host_variable_set (const char *host, const char *variable, double value) { - TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value); + TRACE_host_variable_set_with_time(simgrid_get_clock(), host, variable, value); } /** @ingroup TRACE_user_variables @@ -526,7 +521,7 @@ void TRACE_host_variable_set (const char *host, const char *variable, double val */ void TRACE_host_variable_add (const char *host, const char *variable, double value) { - TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value); + TRACE_host_variable_add_with_time(simgrid_get_clock(), host, variable, value); } /** @ingroup TRACE_user_variables @@ -540,7 +535,7 @@ void TRACE_host_variable_add (const char *host, const char *variable, double val */ void TRACE_host_variable_sub (const char *host, const char *variable, double value) { - TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value); + TRACE_host_variable_sub_with_time(simgrid_get_clock(), host, variable, value); } /** @ingroup TRACE_user_variables @@ -613,7 +608,7 @@ void TRACE_host_variable_sub_with_time (double time, const char *host, const cha */ xbt_dynar_t TRACE_get_host_variables () { - return instr_set_to_dynar(&user_host_variables); + return instr_set_to_dynar(user_host_variables); } /* for link variables */ @@ -659,7 +654,7 @@ void TRACE_link_variable_declare_with_color (const char *variable, const char *c */ void TRACE_link_variable_set (const char *link, const char *variable, double value) { - TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value); + TRACE_link_variable_set_with_time(simgrid_get_clock(), link, variable, value); } /** @ingroup TRACE_user_variables @@ -673,7 +668,7 @@ void TRACE_link_variable_set (const char *link, const char *variable, double val */ void TRACE_link_variable_add (const char *link, const char *variable, double value) { - TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value); + TRACE_link_variable_add_with_time(simgrid_get_clock(), link, variable, value); } /** @ingroup TRACE_user_variables @@ -687,7 +682,7 @@ void TRACE_link_variable_add (const char *link, const char *variable, double val */ void TRACE_link_variable_sub (const char *link, const char *variable, double value) { - TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value); + TRACE_link_variable_sub_with_time(simgrid_get_clock(), link, variable, value); } /** @ingroup TRACE_user_variables @@ -767,7 +762,7 @@ void TRACE_link_variable_sub_with_time (double time, const char *link, const cha */ void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value) { - TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value); + TRACE_link_srcdst_variable_set_with_time(simgrid_get_clock(), src, dst, variable, value); } /** @ingroup TRACE_user_variables @@ -786,7 +781,7 @@ void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const cha */ void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value) { - TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value); + TRACE_link_srcdst_variable_add_with_time(simgrid_get_clock(), src, dst, variable, value); } /** @ingroup TRACE_user_variables @@ -805,7 +800,7 @@ void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const cha */ void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value) { - TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value); + TRACE_link_srcdst_variable_sub_with_time(simgrid_get_clock(), src, dst, variable, value); } /** @ingroup TRACE_user_variables @@ -884,7 +879,7 @@ void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, con */ xbt_dynar_t TRACE_get_link_variables () { - return instr_set_to_dynar(&user_link_variables); + return instr_set_to_dynar(user_link_variables); } /** @ingroup TRACE_user_variables @@ -967,29 +962,3 @@ void TRACE_host_pop_state(const char* host, const char* state_name) { simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event(); } - -/** @ingroup TRACE_API - * @brief Get Paje container types that can be mapped to the nodes of a graph. - * - * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the - * functions defined in @ref TRACE_user_variables. - * - * @return A dynar with the types, must be freed with xbt_dynar_free. - */ -xbt_dynar_t TRACE_get_node_types () -{ - return instr_set_to_dynar(&trivaNodeTypes); -} - -/** @ingroup TRACE_API - * @brief Get Paje container types that can be mapped to the edges of a graph. - * - * This function can be used to create a user made graph configuration file for Triva. Normally, it is used with the - * functions defined in @ref TRACE_user_variables. - * - * @return A dynar with the types, must be freed with xbt_dynar_free. - */ -xbt_dynar_t TRACE_get_edge_types () -{ - return instr_set_to_dynar(&trivaEdgeTypes); -}