From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier Matz Subject: [RFC 4/8] eal: change specific log levels at startup Date: Mon, 6 Feb 2017 14:29:12 +0100 Message-ID: <1486387756-16865-5-git-send-email-olivier.matz@6wind.com> References: <1486387756-16865-1-git-send-email-olivier.matz@6wind.com> To: dev@dpdk.org, david.marchand@6wind.com Return-path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 57D5A14EC for ; Mon, 6 Feb 2017 14:29:43 +0100 (CET) In-Reply-To: <1486387756-16865-1-git-send-email-olivier.matz@6wind.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Example of use: ./app/test-pmd --log-level='pmd\.i40e.*,8' This enables debug logs for all dynamic logs whose type starts with 'pmd.i40e'. Signed-off-by: Olivier Matz --- lib/librte_eal/bsdapp/eal/eal.c | 4 +-- lib/librte_eal/common/eal_common_options.c | 48 +++++++++++++++++++++++------- lib/librte_eal/linuxapp/eal/eal.c | 4 +-- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index ee7c9de..e945468 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -505,10 +505,8 @@ rte_eal_init(int argc, char **argv) thread_id = pthread_self(); - eal_log_level_parse(argc, argv); - /* set log level as early as possible */ - rte_set_log_level(internal_config.log_level); + eal_log_level_parse(argc, argv); if (rte_eal_cpu_init() < 0) rte_panic("Cannot detect lcores\n"); diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index f36bc55..2682881 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -739,25 +739,53 @@ eal_parse_syslog(const char *facility, struct internal_config *conf) } static int -eal_parse_log_level(const char *level, uint32_t *log_level) +eal_parse_log_level(const char *arg, struct internal_config *conf) { - char *end; + char *end, *str, *type, *level; unsigned long tmp; + str = strdup(arg); + if (str == NULL) + return -1; + + if (strchr(str, ',') == NULL) { + type = NULL; + level = str; + } else { + type = strsep(&str, ","); + level = strsep(&str, ","); + } + errno = 0; tmp = strtoul(level, &end, 0); /* check for errors */ if ((errno != 0) || (level[0] == '\0') || - end == NULL || (*end != '\0')) - return -1; + end == NULL || (*end != '\0')) + goto fail; /* log_level is a uint32_t */ if (tmp >= UINT32_MAX) - return -1; + goto fail; + + printf("set log level %s,%lu\n", + type, tmp); + + if (type == NULL) { + conf->log_level = tmp; + rte_log_set_global_level(tmp); + } else if (rte_log_set_level_regexp(type, tmp) < 0) { + printf("cannot set log level %s,%lu\n", + type, tmp); + goto fail; + } - *log_level = tmp; + free(str); return 0; + +fail: + free(str); + return -1; } static enum rte_proc_type_t @@ -898,15 +926,12 @@ eal_parse_common_option(int opt, const char *optarg, break; case OPT_LOG_LEVEL_NUM: { - uint32_t log; - - if (eal_parse_log_level(optarg, &log) < 0) { + if (eal_parse_log_level(optarg, conf) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_LOG_LEVEL "\n"); return -1; } - conf->log_level = log; break; } case OPT_LCORES_NUM: @@ -1057,7 +1082,8 @@ eal_common_usage(void) " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" " --"OPT_SYSLOG" Set syslog facility\n" - " --"OPT_LOG_LEVEL" Set default log level\n" + " --"OPT_LOG_LEVEL"= Set global log level\n" + " --"OPT_LOG_LEVEL"=, Set specific log level\n" " -v Display version information on startup\n" " -h, --help This help\n" "\nEAL options for DEBUG use only:\n" diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index bf6b818..0f61447 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -762,10 +762,8 @@ rte_eal_init(int argc, char **argv) thread_id = pthread_self(); - eal_log_level_parse(argc, argv); - /* set log level as early as possible */ - rte_set_log_level(internal_config.log_level); + eal_log_level_parse(argc, argv); if (rte_eal_cpu_init() < 0) rte_panic("Cannot detect lcores\n"); -- 2.8.1