[dpdk-dev] [PATCH v6 4/4] log: add option argument help
David Marchand
david.marchand at redhat.com
Tue Apr 6 16:28:20 CEST 2021
On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas at monjalon.net> wrote:
> @@ -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);
> + }
Missing something like:
if (sorted_types != rte_logs.dynamic_types)
free(sorted_types);
> +}
> +
--
David Marchand
More information about the dev
mailing list