X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a356bfe3a644a15ebf30281f84436b835bda44e9..f5cd30386a756d5bbacc8d55ffebf21c386e69a4:/src/instr/instr_interface.c diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index 83ce6be28b..5b2140216a 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -19,6 +19,25 @@ typedef enum { XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API"); +xbt_dict_t created_categories = NULL; +xbt_dict_t declared_marks = NULL; +xbt_dict_t user_host_variables = NULL; +xbt_dict_t user_link_variables = NULL; + +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. * @@ -37,7 +56,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API"); * * \param category The name of the new tracing category to be created. * - * \see TRACE_category_with_color, MSG_task_set_category + * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category */ void TRACE_category(const char *category) { @@ -60,7 +79,7 @@ void TRACE_category(const char *category) * \param color The color of the category (see \ref tracing_tracing to * know how to correctly specify the color) * - * \see MSG_task_set_category + * \see MSG_task_set_category, SD_task_set_category */ void TRACE_category_with_color (const char *category, const char *color) { @@ -95,6 +114,28 @@ void TRACE_category_with_color (const char *category, const char *color) 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_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. * @@ -115,6 +156,11 @@ void TRACE_declare_mark(const char *mark_type) if (!mark_type) return; + //check if mark_type is already declared + char *created = xbt_dict_get_or_null(declared_marks, mark_type); + if (created) return; + xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL); + XBT_DEBUG("MARK,declare %s", mark_type); PJ_type_event_new(mark_type, NULL, PJ_type_get_root()); } @@ -144,6 +190,10 @@ void TRACE_mark(const char *mark_type, const char *mark_value) if (!mark_type || !mark_value) return; + //check if mark_type is already declared + char *created = xbt_dict_get_or_null(declared_marks, mark_type); + if (created) return; + XBT_DEBUG("MARK %s %s", mark_type, mark_value); type_t type = PJ_type_get (mark_type, PJ_type_get_root()); if (type == NULL){ @@ -156,20 +206,53 @@ void TRACE_mark(const char *mark_type, const char *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) + const char *color, + xbt_dict_t filter) { /* safe switch */ if (!TRACE_is_enabled()) return; - /* if platform is not traced, we can't deal user variables */ + /* if platform is not traced, we don't allow user variables */ if (!TRACE_needs_platform()) return; + //check if variable is already declared + char *created = xbt_dict_get_or_null(declared_marks, variable); + if (what == INSTR_US_DECLARE){ + if (created){ + //already declared + return; + }else{ + xbt_dict_set (filter, variable, xbt_strdup("1"), NULL); + } + }else{ + if (!created){ + //not declared, ignore + return; + } + } + char valuestr[100]; snprintf(valuestr, 100, "%g", value); @@ -226,10 +309,21 @@ static void instr_user_srcdst_variable(double time, void *link; xbt_dynar_foreach (route, i, link) { char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name; - instr_user_variable (time, link_name, variable, father_type, value, what, NULL); + instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables); } } +/** \ingroup TRACE_API + * \brief Creates a file with the topology of the platform file used for the simulator. + * + * 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. + * + * \param filename The name of the file that will hold the graph. + * + * \return 1 of successful, 0 otherwise. + */ int TRACE_platform_graph_export_graphviz (const char *filename) { /* returns 1 if successful, 0 otherwise */ @@ -263,7 +357,7 @@ int TRACE_platform_graph_export_graphviz (const char *filename) */ void TRACE_host_variable_declare (const char *variable) { - instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL); + instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables); } /** \ingroup TRACE_user_variables @@ -280,7 +374,7 @@ void TRACE_host_variable_declare (const char *variable) */ void TRACE_host_variable_declare_with_color (const char *variable, const char *color) { - instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color); + instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables); } /** \ingroup TRACE_user_variables @@ -344,7 +438,7 @@ void TRACE_host_variable_sub (const char *host, const char *variable, double val */ void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value) { - instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL); + instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables); } /** \ingroup TRACE_user_variables @@ -366,7 +460,7 @@ void TRACE_host_variable_set_with_time (double time, const char *host, const cha */ void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value) { - instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL); + instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables); } /** \ingroup TRACE_user_variables @@ -388,7 +482,20 @@ void TRACE_host_variable_add_with_time (double time, const char *host, const cha */ void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value) { - instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL); + instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables); +} + +/** \ingroup TRACE_user_variables + * \brief Get declared user host variables + * + * This function should be used to get host variables that were already + * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color. + * + * \return A dynar with the declared host variables, must be freed with xbt_dynar_free. + */ +xbt_dynar_t TRACE_get_host_variables (void) +{ + return instr_dict_to_dynar (user_host_variables); } /* for link variables */ @@ -407,7 +514,7 @@ void TRACE_host_variable_sub_with_time (double time, const char *host, const cha */ void TRACE_link_variable_declare (const char *variable) { - instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL); + instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables); } /** \ingroup TRACE_user_variables @@ -424,7 +531,7 @@ void TRACE_link_variable_declare (const char *variable) */ void TRACE_link_variable_declare_with_color (const char *variable, const char *color) { - instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color); + instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables); } /** \ingroup TRACE_user_variables @@ -488,7 +595,7 @@ void TRACE_link_variable_sub (const char *link, const char *variable, double val */ void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value) { - instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL); + instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables); } /** \ingroup TRACE_user_variables @@ -510,7 +617,7 @@ void TRACE_link_variable_set_with_time (double time, const char *link, const cha */ void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value) { - instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL); + instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables); } /** \ingroup TRACE_user_variables @@ -532,7 +639,7 @@ void TRACE_link_variable_add_with_time (double time, const char *link, const cha */ void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value) { - instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL); + instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables); } /* for link variables, but with src and dst used for get_route */ @@ -667,4 +774,17 @@ void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, con instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB); } +/** \ingroup TRACE_user_variables + * \brief Get declared user link variables + * + * This function should be used to get link variables that were already + * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color. + * + * \return A dynar with the declared link variables, must be freed with xbt_dynar_free. + */ +xbt_dynar_t TRACE_get_link_variables (void) +{ + return instr_dict_to_dynar (user_link_variables); +} + #endif /* HAVE_TRACING */