From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 8B54EA0546;
	Tue,  6 Apr 2021 16:28:38 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 0E1BF140FCE;
	Tue,  6 Apr 2021 16:28:38 +0200 (CEST)
Received: from us-smtp-delivery-124.mimecast.com
 (us-smtp-delivery-124.mimecast.com [216.205.24.124])
 by mails.dpdk.org (Postfix) with ESMTP id 24DE7140FBA
 for <dev@dpdk.org>; Tue,  6 Apr 2021 16:28:35 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1617719315;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=ZLo9l51gef2llBRe5n5nXnYFbd9GrSz9SqzGNvWxsLM=;
 b=TLh5Vi+af9jopJNrkr2nz/8mm/rw9BYCNOL7OEUe0yS9i1Ir6xXQEWuYtOdFQYmQpRElIJ
 9C/S/ZyLCVihnAQAb1FVhpwnDPRqbwWTNh3DAyOFt8q8tOlQj+dCMZdr0yYKjwcD+nXFIe
 t+Up3d0N3wDtiJiPJ78yrvyVhegSo6U=
Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com
 [209.85.217.71]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-487-MM_Ci-BwNhms7Bv_ALpnGw-1; Tue, 06 Apr 2021 10:28:32 -0400
X-MC-Unique: MM_Ci-BwNhms7Bv_ALpnGw-1
Received: by mail-vs1-f71.google.com with SMTP id z7so2323653vsz.6
 for <dev@dpdk.org>; Tue, 06 Apr 2021 07:28:32 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=ZLo9l51gef2llBRe5n5nXnYFbd9GrSz9SqzGNvWxsLM=;
 b=G8EnnqyMD+Qo87B8WRh56ho/vCYriCxyHKo0rR2NNL175mUk59Om9/LNBB2IM46me1
 nT6+m6oPcqfKBGDKJHiy7ph1wAiHbQPZDGiDQCIIYLUCJDsdIEupk9ZR4TMN9iHd0NzK
 adm3p5AMvsb8oV1FsrwNm/+zKPZBs2h1NlWB6qdCNtNZWcpZf6bL+k14Rab/OezKPTOu
 /LG41vtWWreEUJYJOV8VyIRlsSZ2SQ++QlQ6tSvme+xz1IM5HqVXxnZFkZHpIyt50CbC
 +haTh70Rfcr7PeGE/w9b9ubyGyIipnwr+FGnf/SllZl04ej9FgjKL+/tj2VmgsZSPE3Z
 UQlg==
X-Gm-Message-State: AOAM533/Bg/DxfIAVzC4EDt0jcwizUcn2cotQGdBbt4xMSpCVjJCqS/J
 HV1ogbGZsM7LpqwW0gfzhGu+WvsOvb/HKOCYAsxV63G6NGELmT1u01kkhMQtEs8HMB/Vc0sU2Dj
 duYHza9H7H7+nEHKSv3E=
X-Received: by 2002:ab0:3345:: with SMTP id h5mr2040451uap.41.1617719312188;
 Tue, 06 Apr 2021 07:28:32 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJz+ugpJRJbNSX0HBKduyfmiV+n5P21xFUEhIMi7Vu6p/uD9N31k6Vy6j9okKBKygo/lyyLqIZ3vrzt5HPoztjc=
X-Received: by 2002:ab0:3345:: with SMTP id h5mr2040424uap.41.1617719311752;
 Tue, 06 Apr 2021 07:28:31 -0700 (PDT)
MIME-Version: 1.0
References: <20210405193000.1113542-1-thomas@monjalon.net>
 <20210406131137.1732110-1-thomas@monjalon.net>
 <20210406131137.1732110-5-thomas@monjalon.net>
In-Reply-To: <20210406131137.1732110-5-thomas@monjalon.net>
From: David Marchand <david.marchand@redhat.com>
Date: Tue, 6 Apr 2021 16:28:20 +0200
Message-ID: <CAJFAV8z+6aB9r6UTjP_0asLa7LqVcU8P=U3jvDq=Uo7s70MJ=w@mail.gmail.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: dev <dev@dpdk.org>, Bruce Richardson <bruce.richardson@intel.com>, 
 Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>, Ray Kinsella <mdr@ashroe.eu>,
 Neil Horman <nhorman@tuxdriver.com>
Authentication-Results: relay.mimecast.com;
 auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset="UTF-8"
Subject: Re: [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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

On Tue, Apr 6, 2021 at 3:12 PM Thomas Monjalon <thomas@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