From patchwork Tue Apr 6 13:11:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 90670 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB472A0546; Tue, 6 Apr 2021 15:12:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D92C140F74; Tue, 6 Apr 2021 15:11:56 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id 964F4140F50 for ; Tue, 6 Apr 2021 15:11:54 +0200 (CEST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 406455C00CE; Tue, 6 Apr 2021 09:11:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 06 Apr 2021 09:11:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=uIvL+0w/mmmGq lgwm4LGyM4G/54P53GXnzWLHDgIuf0=; b=ag8UQ+okeBw4nJk1X4q3UIXeqjkTL +jhw4nybHSZC4KUF7RCmo4h5yQ0CxoNxbT05SIB3jti9zqcPdymrU2QPr3Cp6jiy tWci5DnKT9xdbhxUfJuElT76wPwXM1OrMz3Tjwf2bZBkvlqLuraL31/30ZYVs4tA KmBEo4gpogxbpyowS6BbfMUDvnVS3g3OLPM7++sqgEwIr/1/YfYGMJ+d0KF4Rorh SBr5Eg4DSd1l7GqxFsNoUEkT2mn6q2B58+9pyCsBhVFpyp+FGNa40wEqfFv4KKxN nIvA8ugYZOjwadojTu/kstTXLu5bfsyNNZGiZAxYIo3R4Ci5srliwm6kg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=uIvL+0w/mmmGqlgwm4LGyM4G/54P53GXnzWLHDgIuf0=; b=AhFNXx4y GqoKG3PEAFIYO/DyysIambyKJROD8czOPOr0Jp/TzWfMgy29PvcbjPN7hc6pKqH8 W0jIvI5NsbaZl9/PPQiHor4sCi+oQ/+py+5xk0XfwjJa5FwHsskuev16S3IcA6mh WPbt02LTBfgY9Y6/xDz9Mr3XKk8tYAs8m936EHlvl3vuM6Lic23KYKMJ3iNyML2K jV86YU6+TjMVjOTcQQbmGJXH7u/yMV9NFQL6+8aKWeLDjgxeWJqjC2HB8ucCQXTZ DnxgMMuRtVVVcocd+ciQQkMjeDSACuFJuKN/I5tFJQZ+qD99+chk964SyTAJ33Wk zxPeva/ysuAa9g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl ohhnrdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id EB612240065; Tue, 6 Apr 2021 09:11:52 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson , Andrew Rybchenko , Ray Kinsella , Neil Horman Date: Tue, 6 Apr 2021 15:11:37 +0200 Message-Id: <20210406131137.1732110-5-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210406131137.1732110-1-thomas@monjalon.net> References: <20210405193000.1113542-1-thomas@monjalon.net> <20210406131137.1732110-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 4/4] log: add option argument help X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The option --log-level was not completely described in the usage text, and it was difficult to guess the names of the log types and levels. A new value "help" is accepted after --log-level to give more details about the syntax and listing the log types and levels. The array "levels" used for level name parsing is replaced with a (modified) existing function which was used in rte_log_dump(). The new function rte_log_list_types() is exported in the API for allowing an application to give this info to the user if not exposing the EAL option --log-level. The list of log types cannot include all drivers if not linked in the application (shared object plugin case). Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson Acked-by: Andrew Rybchenko --- lib/librte_eal/common/eal_common_log.c | 51 +++++++++++++++++++--- lib/librte_eal/common/eal_common_options.c | 44 +++++++++++++------ lib/librte_eal/common/eal_log.h | 5 +++ lib/librte_eal/include/rte_log.h | 11 +++++ lib/librte_eal/version.map | 1 + 5 files changed, 94 insertions(+), 18 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index b9b982fdb5..4c6766a360 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -397,12 +397,12 @@ RTE_INIT_PRIO(log_init, LOG) rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID; } -static const char * -loglevel_to_string(uint32_t level) +const char * +eal_log_level2str(uint32_t level) { switch (level) { case 0: return "disabled"; - case RTE_LOG_EMERG: return "emerg"; + case RTE_LOG_EMERG: return "emergency"; case RTE_LOG_ALERT: return "alert"; case RTE_LOG_CRIT: return "critical"; case RTE_LOG_ERR: return "error"; @@ -414,6 +414,47 @@ loglevel_to_string(uint32_t level) } } +static int +log_type_compare(const void *a, const void *b) +{ + const struct rte_log_dynamic_type *type_a = a; + const struct rte_log_dynamic_type *type_b = b; + + if (type_a->name == NULL && type_b->name == NULL) + return 0; + if (type_a->name == NULL) + return -1; + if (type_b->name == NULL) + return 1; + return strcmp(type_a->name, type_b->name); +} + +/* Dump name of each logtype, one per line. */ +void +rte_log_list_types(FILE *out, const char *prefix) +{ + struct rte_log_dynamic_type *sorted_types; + const size_t type_size = sizeof(rte_logs.dynamic_types[0]); + const size_t type_count = rte_logs.dynamic_types_len; + const size_t total_size = type_size * type_count; + size_t type; + + sorted_types = malloc(total_size); + if (sorted_types == NULL) { + /* no sorting - unlikely */ + sorted_types = rte_logs.dynamic_types; + } else { + memcpy(sorted_types, rte_logs.dynamic_types, total_size); + qsort(sorted_types, type_count, type_size, log_type_compare); + } + + for (type = 0; type < type_count; ++type) { + if (sorted_types[type].name == NULL) + continue; + fprintf(out, "%s%s\n", prefix, sorted_types[type].name); + } +} + /* dump global level and registered log types */ void rte_log_dump(FILE *f) @@ -421,14 +462,14 @@ rte_log_dump(FILE *f) size_t i; fprintf(f, "global log level is %s\n", - loglevel_to_string(rte_log_get_global_level())); + eal_log_level2str(rte_log_get_global_level())); for (i = 0; i < rte_logs.dynamic_types_len; i++) { if (rte_logs.dynamic_types[i].name == NULL) continue; fprintf(f, "id %zu: %s, level is %s\n", i, rte_logs.dynamic_types[i].name, - loglevel_to_string(rte_logs.dynamic_types[i].loglevel)); + eal_log_level2str(rte_logs.dynamic_types[i].loglevel)); } } diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 7075a051b8..2951b1aca2 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1227,19 +1227,31 @@ eal_parse_syslog(const char *facility, struct internal_config *conf) } #endif +static void +eal_log_usage(void) +{ + unsigned int level; + + printf("Log type is a pattern matching items of this list" + " (plugins may be missing):\n"); + rte_log_list_types(stdout, "\t"); + printf("\n"); + printf("Syntax using globbing pattern: "); + printf("--"OPT_LOG_LEVEL" pattern:level\n"); + printf("Syntax using regular expression: "); + printf("--"OPT_LOG_LEVEL" regexp,level\n"); + printf("Syntax for the global level: "); + printf("--"OPT_LOG_LEVEL" level\n"); + printf("Logs are emitted if allowed by both global and specific levels.\n"); + printf("\n"); + printf("Log level can be a number or the first letters of its name:\n"); + for (level = 1; level <= RTE_LOG_MAX; level++) + printf("\t%d %s\n", level, eal_log_level2str(level)); +} + static int eal_parse_log_priority(const char *level) { - static const char * const levels[] = { - [RTE_LOG_EMERG] = "emergency", - [RTE_LOG_ALERT] = "alert", - [RTE_LOG_CRIT] = "critical", - [RTE_LOG_ERR] = "error", - [RTE_LOG_WARNING] = "warning", - [RTE_LOG_NOTICE] = "notice", - [RTE_LOG_INFO] = "info", - [RTE_LOG_DEBUG] = "debug", - }; size_t len = strlen(level); unsigned long tmp; char *end; @@ -1250,7 +1262,7 @@ eal_parse_log_priority(const char *level) /* look for named values, skip 0 which is not a valid level */ for (i = 1; i <= RTE_LOG_MAX; i++) { - if (strncmp(levels[i], level, len) == 0) + if (strncmp(eal_log_level2str(i), level, len) == 0) return i; } @@ -1274,6 +1286,11 @@ eal_parse_log_level(const char *arg) char *str, *level; int priority; + if (strcmp(arg, "help") == 0) { + eal_log_usage(); + exit(EXIT_SUCCESS); + } + str = strdup(arg); if (str == NULL) return -1; @@ -2068,9 +2085,10 @@ eal_common_usage(void) #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_SYSLOG" Set syslog facility\n" #endif - " --"OPT_LOG_LEVEL"= Set global log level\n" - " --"OPT_LOG_LEVEL"=:\n" + " --"OPT_LOG_LEVEL"= Set global log level\n" + " --"OPT_LOG_LEVEL"=:\n" " Set specific log level\n" + " --"OPT_LOG_LEVEL"=help Show log types and levels\n" #ifndef RTE_EXEC_ENV_WINDOWS " --"OPT_TRACE"=\n" " Enable trace based on regular expression trace name.\n" diff --git a/lib/librte_eal/common/eal_log.h b/lib/librte_eal/common/eal_log.h index 684650a17b..c784fa6043 100644 --- a/lib/librte_eal/common/eal_log.h +++ b/lib/librte_eal/common/eal_log.h @@ -24,4 +24,9 @@ void eal_log_set_default(FILE *default_log); int eal_log_save_regexp(const char *regexp, uint32_t level); int eal_log_save_pattern(const char *pattern, uint32_t level); +/* + * Convert log level to string. + */ +const char *eal_log_level2str(uint32_t level); + #endif /* EAL_LOG_H */ diff --git a/lib/librte_eal/include/rte_log.h b/lib/librte_eal/include/rte_log.h index 424dfa3fd0..ccbb7ccd81 100644 --- a/lib/librte_eal/include/rte_log.h +++ b/lib/librte_eal/include/rte_log.h @@ -240,6 +240,17 @@ int rte_log_register(const char *name); __rte_experimental int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def); +/** + * Dump name of each logtype, one per line. + * + * @param out + * Stream where the list is sent. + * @param prefix + * String preceding each logtype in the output. + */ +__rte_experimental +void rte_log_list_types(FILE *out, const char *prefix); + /** * Dump log information. * diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index e23745ae6e..6c14fea27b 100644 --- a/lib/librte_eal/version.map +++ b/lib/librte_eal/version.map @@ -411,6 +411,7 @@ EXPERIMENTAL { rte_power_pause; # added in 21.05 + rte_log_list_types; rte_thread_key_create; rte_thread_key_delete; rte_thread_value_get;