-xbt_dict_t created_categories = NULL;
-xbt_dict_t declared_marks = NULL;
-xbt_dict_t user_host_variables = NULL;
-xbt_dict_t user_vm_variables = NULL;
-xbt_dict_t user_link_variables = NULL;
-extern xbt_dict_t trivaNodeTypes;
-extern xbt_dict_t trivaEdgeTypes;
-
-static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
-{
- if (!TRACE_is_enabled()) return NULL;
- if (!TRACE_needs_platform()) return NULL;
-
- xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
- xbt_dict_cursor_t cursor = NULL;
- char *name, *value;
- xbt_dict_foreach(filter, cursor, name, value) {
- xbt_dynar_push_as (ret, char*, xbt_strdup(name));
- }
- 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 tracing 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, NULL);
-}
-
-/** \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 tracing 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 tracing 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 switch */
- if (!TRACE_is_enabled()) return;
-
- if (!(TRACE_categorized() && category != NULL)) return;
-
- /* if platform is not traced, we can't deal with categories */
- if (!TRACE_needs_platform()) return;
-
- //check if category is already created
- char *created = (char*)xbt_dict_get_or_null(created_categories, category);
- if (created) return;
- xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
-
- //define final_color
- char final_color[INSTR_DEFAULT_STR_SIZE];
- if (!color){
- //generate a random color
- double red = drand48();
- double green = drand48();
- double blue = drand48();
- snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
- }else{
- snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
- }
-
- XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color);
-
- //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 tracing 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 (void)
-{
- if (!TRACE_is_enabled()) return NULL;
- if (!TRACE_categorized()) return NULL;
-
- return instr_dict_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 switch */
- if (!TRACE_is_enabled()) return;
-
- /* if platform is not traced, we don't allow marks */
- if (!TRACE_needs_platform()) return;
-
- if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
-
- //check if mark_type is already declared
- char *created = (char*)xbt_dict_get_or_null(declared_marks, mark_type);
- if (created) {
- THROWF (tracing_error, 1, "mark_type with name (%s) is already declared", mark_type);
- }
-
- XBT_DEBUG("MARK,declare %s", mark_type);
- PJ_type_event_new(mark_type, PJ_type_get_root());
- xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
-}
-
-/** \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 NULL 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 switch */
- if (!TRACE_is_enabled()) return;
-
- /* if platform is not traced, we don't allow marks */
- if (!TRACE_needs_platform()) return;
-
- if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
- if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
-
- type_t type = PJ_type_get (mark_type, PJ_type_get_root());
- if (!type){
- THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
- }
-
- char white[INSTR_DEFAULT_STR_SIZE] = "1.0 1.0 1.0";
- if (!mark_color) mark_color = white;
-
- XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color);
- PJ_value_new (mark_value, mark_color, type);
-}
-
-/** \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 NULL 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, NULL);
-}
-
-/**
- * \ingroup TRACE_mark
- * \brief Create a new instance of a tracing mark type.
- *
- * This function creates a mark in the trace file. The
- * first parameter had to be previously declared using
- * #TRACE_declare_mark, the second is the identifier
- * for this mark instance. We recommend that the
- * mark_value is a unique value for the whole simulation.
- * Nevertheless, this is not a strong requirement: the
- * trace will be valid even if there are multiple mark
- * identifiers for the same trace.
- *
- * \param mark_type The name of the type for which the new instance will belong.
- * \param mark_value The name of the new instance mark.
- *
- * \see TRACE_declare_mark
- */
-void TRACE_mark(const char *mark_type, const char *mark_value)
-{
- /* safe switch */
- if (!TRACE_is_enabled()) return;
-
- /* if platform is not traced, we don't allow marks */
- if (!TRACE_needs_platform()) return;
-
- if (!mark_type) THROWF (tracing_error, 1, "mark_type is NULL");
- if (!mark_value) THROWF (tracing_error, 1, "mark_value is NULL");
-
- //check if mark_type is already declared
- type_t type = PJ_type_get (mark_type, PJ_type_get_root());
- if (!type){
- THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
- }
-
- val_t value = PJ_value_get (mark_value, type);
- XBT_DEBUG("MARK %s %s", mark_type, mark_value);
- new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
-}
-
-/** \ingroup TRACE_mark
- * \brief Get declared marks
- *
- * This function should be used to get marks that were already
- * declared with #TRACE_declare_mark.
- *
- * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
- *
- */
-xbt_dynar_t TRACE_get_marks (void)
-{
- if (!TRACE_is_enabled()) return NULL;
-
- return instr_dict_to_dynar (declared_marks);
-}
-
-static void instr_user_variable(double time,
- const char *resource,
- const char *variable,
- const char *father_type,
- double value,
- InstrUserVariable what,
- const char *color,
- xbt_dict_t filter)
-{
- /* safe switch */
- if (!TRACE_is_enabled()) return;
-
- /* if platform is not traced, we don't allow user variables */
- if (!TRACE_needs_platform()) return;
-
- //check if variable is already declared
- char *created = (char*)xbt_dict_get_or_null(filter, variable);
- if (what == INSTR_US_DECLARE){
- if (created){
- //already declared
- return;
- }else{
- xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);