DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Kinsella, Ray" <mdr@ashroe.eu>
To: Thomas Monjalon <thomas@monjalon.net>, dev@dpdk.org
Cc: david.marchand@redhat.com, bruce.richardson@intel.com,
	mb@smartsharesystems.com, Neil Horman <nhorman@tuxdriver.com>
Subject: Re: [dpdk-dev] [PATCH v3 07/11] eal: add log level help
Date: Mon, 15 Mar 2021 10:19:47 +0000
Message-ID: <44934eac-9808-ada4-fe97-7d24382bced4@ashroe.eu> (raw)
In-Reply-To: <20210312181720.242252-8-thomas@monjalon.net>



On 12/03/2021 18:17, Thomas Monjalon wrote:
> 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 <thomas@monjalon.net>
> ---
>  lib/librte_eal/common/eal_common_log.c     | 24 +++++++++---
>  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                 |  3 ++
>  5 files changed, 69 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
> index 40cac36f89..d695b04068 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,20 @@ loglevel_to_string(uint32_t level)
>  	}
>  }
>  
> +/* Dump name of each logtype, one per line. */
> +void
> +rte_log_list_types(FILE *out, const char *prefix)
> +{
> +	size_t type;
> +
> +	for (type = 0; type < rte_logs.dynamic_types_len; ++type) {
> +		if (rte_logs.dynamic_types[type].name == NULL)
> +			continue;
> +		fprintf(out, "%s%s\n",
> +				prefix, rte_logs.dynamic_types[type].name);
> +	}
> +}
> +
>  /* dump global level and registered log types */
>  void
>  rte_log_dump(FILE *f)
> @@ -421,14 +435,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 2df3ae04ea..1da6583d71 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) {

So I think the convention is to support both "?" and "help".
Qemu does this at least. 

> +		eal_log_usage();
> +		exit(EXIT_SUCCESS);
> +	}
> +
>  	str = strdup(arg);
>  	if (str == NULL)
>  		return -1;
> @@ -2067,9 +2084,10 @@ eal_common_usage(void)
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  	       "  --"OPT_SYSLOG"            Set syslog facility\n"
>  #endif
> -	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
> -	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
> +	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
> +	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
>  	       "                      Set specific log level\n"
> +	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  	       "  --"OPT_TRACE"=<regex-match>\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 394e8682b9..e6192892c3 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 fce90a112f..6b7876a0b9 100644
> --- a/lib/librte_eal/version.map
> +++ b/lib/librte_eal/version.map
> @@ -412,6 +412,9 @@ EXPERIMENTAL {
>  	rte_thread_tls_key_delete;
>  	rte_thread_tls_value_get;
>  	rte_thread_tls_value_set;
> +
> +	# added in 21.05
> +	rte_log_list_types;
>  };
>  
>  INTERNAL {
> 

  reply	other threads:[~2021-03-15 10:19 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 23:31 [dpdk-dev] [PATCH 00/11] improve options help Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 02/11] eal: improve options usage text Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 03/11] eal: use macros for help option Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 04/11] eal: move private log functions Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-10 12:46   ` Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-10 12:19   ` Bruce Richardson
2021-03-10 12:33     ` Thomas Monjalon
2021-03-10 13:26       ` Bruce Richardson
2021-03-10 13:35         ` Thomas Monjalon
2021-03-10 16:35           ` Morten Brørup
2021-03-10 16:52           ` Bruce Richardson
2021-03-10 15:16     ` Stephen Hemminger
2021-03-09 23:31 ` [dpdk-dev] [PATCH 07/11] eal: add log level help Thomas Monjalon
2021-03-09 23:31 ` [dpdk-dev] [PATCH 08/11] app: fix exit messages Thomas Monjalon
2021-03-10  7:10   ` Ori Kam
2021-03-10  9:23   ` Wisam Monther
2021-03-09 23:31 ` [dpdk-dev] [PATCH 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-10  9:25   ` Wisam Monther
2021-03-09 23:31 ` [dpdk-dev] [PATCH 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-10  7:08   ` Ori Kam
2021-03-09 23:31 ` [dpdk-dev] [PATCH 11/11] app/testpmd: " Thomas Monjalon
2021-03-12 19:09   ` Ajit Khaparde
2021-03-10  0:45 ` [dpdk-dev] [PATCH 00/11] improve options help Stephen Hemminger
2021-03-10 13:28 ` [dpdk-dev] [PATCH v2 " Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 02/11] eal: improve options usage text Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 03/11] eal: use macros for help option Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 04/11] eal: move private log functions Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 07/11] eal: add log level help Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 08/11] app: fix exit messages Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-10 13:28   ` [dpdk-dev] [PATCH v2 11/11] app/testpmd: " Thomas Monjalon
2021-03-12 18:17 ` [dpdk-dev] [PATCH v3 00/11] improve options help Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 02/11] eal: improve options usage text Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 03/11] eal: use macros for help option Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 04/11] eal: move private log functions Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 07/11] eal: add log level help Thomas Monjalon
2021-03-15 10:19     ` Kinsella, Ray [this message]
2021-03-15 10:31       ` Bruce Richardson
2021-03-15 10:42         ` Kinsella, Ray
2021-03-15 10:52           ` Thomas Monjalon
2021-03-15 15:59             ` Stephen Hemminger
2021-03-15 17:01               ` Kinsella, Ray
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 08/11] app: fix exit messages Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-12 18:17   ` [dpdk-dev] [PATCH v3 11/11] app/testpmd: " Thomas Monjalon
2021-03-19  8:59     ` Li, Xiaoyun
2021-03-19  9:29       ` Thomas Monjalon
2021-03-15  9:40   ` [dpdk-dev] [PATCH v3 00/11] improve options help Bruce Richardson
2021-03-15 10:47     ` Andrew Rybchenko
2021-03-21 22:31 ` [dpdk-dev] [PATCH v4 " Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 01/11] eal: explain argv behaviour during init Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 02/11] eal: improve options usage text Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 03/11] eal: use macros for help option Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 04/11] eal: move private log functions Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 05/11] eal: introduce maximum log level macro Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 06/11] eal: catch invalid log level number Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 07/11] eal: add log level help Thomas Monjalon
2021-03-23 13:37     ` David Marchand
2021-03-23 15:10       ` Thomas Monjalon
2021-03-23 18:18         ` David Marchand
2021-03-23 18:41           ` Thomas Monjalon
2021-03-24 13:41             ` David Marchand
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 08/11] app: fix exit messages Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 09/11] app: hook in EAL usage help Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 10/11] app/regex: fix usage text Thomas Monjalon
2021-03-21 22:31   ` [dpdk-dev] [PATCH v4 11/11] app/testpmd: " Thomas Monjalon
2021-03-22  1:45     ` Li, Xiaoyun
2021-03-22  8:27     ` Jens Freimann
2021-03-22  9:05       ` Bing Zhao
2021-03-24 15:03   ` [dpdk-dev] [PATCH v4 00/11] improve options help David Marchand
2021-03-24 16:55     ` Thomas Monjalon
2021-04-05 19:29 ` [dpdk-dev] [PATCH v5 0/4] log level enhancements Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 1/4] log: move private functions Thomas Monjalon
2021-04-06 11:28     ` David Marchand
2021-04-06 12:08       ` Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-05 19:29   ` [dpdk-dev] [PATCH v5 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-05 19:30   ` [dpdk-dev] [PATCH v5 4/4] log: add option argument help Thomas Monjalon
2021-04-06 13:11   ` [dpdk-dev] [PATCH v6 0/4] log level enhancements Thomas Monjalon
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 1/4] log: move private functions Thomas Monjalon
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-06 14:32       ` David Marchand
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-06 14:35       ` David Marchand
2021-04-06 13:11     ` [dpdk-dev] [PATCH v6 4/4] log: add option argument help Thomas Monjalon
2021-04-06 14:28       ` David Marchand
2021-04-06 14:58         ` Thomas Monjalon
2021-04-06 16:04       ` Thomas Monjalon
2021-04-06 16:35         ` David Marchand
2021-04-08 16:47   ` [dpdk-dev] [PATCH v7 0/4] log level enhancements Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 1/4] log: move private functions Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 2/4] log: introduce macro for maximum level Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 3/4] log: catch invalid level option number Thomas Monjalon
2021-04-08 16:47     ` [dpdk-dev] [PATCH v7 4/4] log: add option argument help Thomas Monjalon
2021-04-09  9:31       ` David Marchand
2021-04-13 16:55       ` Kinsella, Ray
2021-04-09 10:55     ` [dpdk-dev] [PATCH v7 0/4] log level enhancements David Marchand
2021-04-05 19:33 ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 1/3] app: fix exit messages Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 2/3] app/regex: fix usage text Thomas Monjalon
2021-04-05 19:33   ` [dpdk-dev] [PATCH v5 3/3] app/testpmd: " Thomas Monjalon
2021-04-09 12:31   ` [dpdk-dev] [PATCH v5 0/3] cleanup exit and usage messages in apps David Marchand
2021-04-05 19:39 ` [dpdk-dev] [PATCH v5 0/4] improve options help Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 1/4] eal: explain argv behaviour during init Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 2/4] eal: improve options usage text Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 3/4] eal: use macros for help option Thomas Monjalon
2021-04-05 19:39   ` [dpdk-dev] [PATCH v5 4/4] app: hook in EAL usage help Thomas Monjalon
2021-04-06 13:32     ` Jerin Jacob
2021-04-06 14:05       ` Thomas Monjalon
2021-04-06 14:13         ` Jerin Jacob

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44934eac-9808-ada4-fe97-7d24382bced4@ashroe.eu \
    --to=mdr@ashroe.eu \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    --cc=nhorman@tuxdriver.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git