-/* Copyright (c) 2010-2019. 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 <algorithm>
+#include <cmath>
enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
-std::set<std::string> created_categories;
-std::set<std::string> declared_marks;
-std::set<std::string> user_host_variables;
-std::set<std::string> user_vm_variables;
-std::set<std::string> user_link_variables;
-extern std::set<std::string> trivaNodeTypes;
-extern std::set<std::string> trivaEdgeTypes;
+std::set<std::string, std::less<>> created_categories;
+std::set<std::string, std::less<>> declared_marks;
+std::set<std::string, std::less<>> user_host_variables;
+std::set<std::string, std::less<>> user_vm_variables;
+std::set<std::string, std::less<>> user_link_variables;
-static xbt_dynar_t instr_set_to_dynar(std::set<std::string>* filter)
+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())
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;
/** @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.
*
//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);
{
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
*/
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;
//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<simgrid::instr::EventType>(mark_type);
- declared_marks.insert(mark_type);
+ declared_marks.emplace(mark_type);
}
/** @ingroup TRACE_mark
simgrid::instr::EventType* type =
static_cast<simgrid::instr::EventType*>(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*/;
simgrid::instr::EventType* type =
static_cast<simgrid::instr::EventType*>(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));
}
}
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<std::string>* filter)
+ 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())
break;
default:
THROW_IMPOSSIBLE;
- break;
}
}
}
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<simgrid::kernel::resource::LinkImpl*> route;
simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
*
* 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.
*
*/
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;
}
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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 */
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
{
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);
-}