-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;
-
-static xbt_dynar_t instr_set_to_dynar(const std::set<std::string>& 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)
- xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
-
- return ret;
-}
-
-/** @ingroup TRACE_category
- * @brief Declare a new category with a random color.
- *
- * This function should be used to define a user category. The category can be used to differentiate the tasks that
- * are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
- * communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
- * task category. Tasks that do not belong to a category are not traced. The color for the category that is being
- * declared is random. This function has no effect if a category with the same name has been already declared.
- *
- * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
- *
- * @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
- */
-void TRACE_category(const char *category)
-{
- TRACE_category_with_color (category, nullptr);
-}
-
-/** @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.
- * 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.
- *
- * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
- *
- * @param category The name of the new tracing category to be created.
- * @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;
- else
- created_categories.insert(category);
-
- //define final_color
- std::string final_color;
- if (not color) {
- //generate a random color
- static std::default_random_engine rnd_engine;
- std::uniform_real_distribution<double> prng(0.0, std::nextafter(1.0, 2.0));
- double red = prng(rnd_engine);
- double green = prng(rnd_engine);
- double blue = prng(rnd_engine);
- 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);
-}
-
-/** @ingroup TRACE_category
- * @brief Get declared categories
- *
- * This function should be used to get categories that were already declared with #TRACE_category or with
- * #TRACE_category_with_color.
- *
- * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
- *
- * @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 ()
-{
- if (not TRACE_is_enabled() || not TRACE_categorized())
- return nullptr;
- return instr_set_to_dynar(created_categories);
-}
-
-/** @ingroup TRACE_mark
- * @brief Declare a new type for tracing mark.
- *
- * This function declares a new Paje event type in the trace file that can be used by simulators to declare
- * application-level marks. This function is independent of which API is used in SimGrid.
- *
- * @param mark_type The name of the new type.
- *
- * @see TRACE_mark
- */
-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()->type_->by_name_or_create<simgrid::instr::EventType>(mark_type);
- declared_marks.insert(mark_type);
-}
-
-/** @ingroup TRACE_mark
- * @brief Declare a new colored value for a previously declared mark type.
- *
- * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
- * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
- * a string with three numbers separated by spaces in the range [0,1].
- * A light-gray color can be specified using "0.7 0.7 0.7" as color. If a nullptr color is provided, the color used will
- * be white ("1 1 1").
- *
- * @param mark_type The name of the new type.
- * @param mark_value The name of the new value for this type.
- * @param mark_color The color of the new value for this type.
- *
- * @see 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");
-
- simgrid::instr::EventType* type =
- static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->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);
- }
-}
-
-/** @ingroup TRACE_mark
- * @brief Declare a new value for a previously declared mark type.
- *
- * This function declares a new value for a Paje event type in the trace file that can be used by simulators to declare
- * application-level marks. This function is independent of which API is used in SimGrid. Calling this function is the
- * same as calling @ref TRACE_declare_mark_value_with_color with a nullptr color.
- *
- * @param mark_type The name of the new type.
- * @param mark_value The name of the new value for this type.
- *
- * @see 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);
-}