From c8936bbc125e2396d1573bb629dc9c32181b729f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 28 Mar 2012 15:41:54 +0200 Subject: [PATCH 1/1] First attempt to display log categoy hierarchy. --- include/xbt/log.h | 7 ++++++ src/surf/surf_config.c | 5 +++- src/xbt/log.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/xbt/log.h b/include/xbt/log.h index 26fdf6fb20..3b77db3737 100644 --- a/include/xbt/log.h +++ b/include/xbt/log.h @@ -361,6 +361,13 @@ extern xbt_log_layout_t xbt_log_default_layout; */ XBT_PUBLIC(void) xbt_log_help(void); +/** + * \ingroup XBT_log + * + * Prints the log category hierarchy. + */ +XBT_PUBLIC(void) xbt_log_help_categories(void); + /** * \ingroup XBT_log * \param catName name of the category diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 52e68879cb..816709cb25 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -44,7 +44,7 @@ static void surf_config_cmd_line(int *argc, char **argv) "You can also use --help-tracing to see the details of all tracing options known by this simulator.\n" #endif "\n" -"You can also use --help-logs to see the details of logging output.\n" +"You can also use --help-logs and --help-log-categories to see the details of logging output.\n" "\n" ); shall_exit = 1; @@ -66,6 +66,9 @@ static void surf_config_cmd_line(int *argc, char **argv) } else if (!strcmp(argv[i], "--help-logs")) { xbt_log_help(); shall_exit = 1; + } else if (!strcmp(argv[i], "--help-log-categories")) { + xbt_log_help_categories(); + shall_exit = 1; #ifdef HAVE_TRACING } else if (!strcmp(argv[i], "--help-tracing")) { TRACE_help (1); diff --git a/src/xbt/log.c b/src/xbt/log.c index f6c02c44c6..2b4f6e2847 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -1153,3 +1153,56 @@ void xbt_log_help(void) "\n" ); } + +static int xbt_log_cat_cmp(const void *pa, const void *pb) +{ + xbt_log_category_t a = *(xbt_log_category_t *)pa; + xbt_log_category_t b = *(xbt_log_category_t *)pb; + return strcmp(a->name, b->name); +} + +static void xbt_log_help_categories_rec(xbt_log_category_t category, + const char *prefix) +{ + char *this_prefix; + char *child_prefix; + xbt_dynar_t dynar; + unsigned i; + xbt_log_category_t cat; + + if (!category) + return; + + if (category->parent) { + this_prefix = bprintf("%s \\_ ", prefix); + child_prefix = bprintf("%s | ", prefix); + } else { + this_prefix = bprintf("%s", prefix); + child_prefix = bprintf("%s", prefix); + } + + dynar = xbt_dynar_new(sizeof(xbt_log_category_t), NULL); + for (cat = category ; cat != NULL; cat = cat->nextSibling) + xbt_dynar_push_as(dynar, xbt_log_category_t, cat); + + xbt_dynar_sort(dynar, xbt_log_cat_cmp); + + for (i = 0; i < xbt_dynar_length(dynar); i++) { + if (i == xbt_dynar_length(dynar) - 1 && category->parent) + *strrchr(child_prefix, '|') = ' '; + cat = xbt_dynar_get_as(dynar, i, xbt_log_category_t); + printf("%s%s\n", this_prefix, cat->name); + xbt_log_help_categories_rec(cat->firstChild, child_prefix); + } + + xbt_dynar_free(&dynar); + xbt_free(this_prefix); + xbt_free(child_prefix); +} + +void xbt_log_help_categories(void) +{ + printf("Current log category hierarchy:\n"); + xbt_log_help_categories_rec(&_XBT_LOGV(XBT_LOG_ROOT_CAT), " "); + printf("\n"); +} -- 2.20.1