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 79DD0A0556;
	Mon, 17 Oct 2022 09:56:50 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 642FF4021D;
	Mon, 17 Oct 2022 09:56:50 +0200 (CEST)
Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188])
 by mails.dpdk.org (Postfix) with ESMTP id E683540143
 for <dev@dpdk.org>; Mon, 17 Oct 2022 09:56:48 +0200 (CEST)
Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56])
 by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MrTpd1scPzHvfX;
 Mon, 17 Oct 2022 15:56:41 +0800 (CST)
Received: from [10.67.100.224] (10.67.100.224) by
 dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2375.31; Mon, 17 Oct 2022 15:56:34 +0800
Subject: Re: [PATCH v2] usertools: telemetry json support pretty print
To: =?UTF-8?Q?Morten_Br=c3=b8rup?= <mb@smartsharesystems.com>, Bruce
 Richardson <bruce.richardson@intel.com>, Stephen Hemminger
 <stephen@networkplumber.org>
CC: "Power, Ciara" <ciara.power@intel.com>, David Marchand
 <david.marchand@redhat.com>, <thomas@monjalon.net>, <dev@dpdk.org>
References: <20221014023338.51464-1-fengchengwen@huawei.com>
 <20221014032504.32534-1-fengchengwen@huawei.com>
 <CAJFAV8yLnG4Ch7jektQdeNE+yD66v0Bwi9KRH=naYruh3XD=NA@mail.gmail.com>
 <MN2PR11MB382136DE29701C4B84CCA88EE6249@MN2PR11MB3821.namprd11.prod.outlook.com>
 <Y0ld0q09n8bUg6qM@bricha3-MOBL.ger.corp.intel.com>
 <20221014080111.79c7c0bd@hermes.local>
 <Y0mAXtTjL9BTxbIM@bricha3-MOBL.ger.corp.intel.com>
 <98CBD80474FA8B44BF855DF32C47DC35D873E4@smartserver.smartshare.dk>
From: fengchengwen <fengchengwen@huawei.com>
Message-ID: <cc71292e-efa2-e60a-00ca-f22e376a1975@huawei.com>
Date: Mon, 17 Oct 2022 15:56:34 +0800
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
 Thunderbird/68.11.0
MIME-Version: 1.0
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D873E4@smartserver.smartshare.dk>
Content-Type: text/plain; charset="utf-8"
Content-Language: en-US
Content-Transfer-Encoding: 8bit
X-Originating-IP: [10.67.100.224]
X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To
 dggpeml500024.china.huawei.com (7.185.36.10)
X-CFilter-Loop: Reflected
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

Hi all,

On 2022/10/15 0:10, Morten Brørup wrote:
>> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
>> Sent: Friday, 14 October 2022 17.30
>>
>> On Fri, Oct 14, 2022 at 08:01:11AM -0700, Stephen Hemminger wrote:
>>> On Fri, 14 Oct 2022 14:02:10 +0100
>>> Bruce Richardson <bruce.richardson@intel.com> wrote:
>>>
>>>> On Fri, Oct 14, 2022 at 12:44:33PM +0000, Power, Ciara wrote:
>>>>> Hi Chengwen,
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: David Marchand <david.marchand@redhat.com>
>>>>>> Sent: Friday 14 October 2022 10:50
>>>>>> To: Chengwen Feng <fengchengwen@huawei.com>
>>>>>> Cc: thomas@monjalon.net; dev@dpdk.org; Power, Ciara
>>>>>> <ciara.power@intel.com>
>>>>>> Subject: Re: [PATCH v2] usertools: telemetry json support
>> pretty print
>>>>>>
>>>>>> On Fri, Oct 14, 2022 at 5:31 AM Chengwen Feng
>> <fengchengwen@huawei.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Currently, the dpdk-telemetry.py show json in raw format,
>> which is not
>>>>>>> good for human reading.
>>>>>>>
>>>>>>> E.g. The command '/ethdev/xstats,0' will output:
>>>>>>> {"/ethdev/xstats": {"rx_good_packets": 0, "tx_good_packets":
>> 0,
>>>>>>> "rx_good_bytes": 0, "tx_good_bytes": 0, "rx_missed_errors":
>> 0,
>>>>>>> "rx_errors": 0, "tx_errors": 0, "rx_mbuf_allocation_errors":
>> 0,
>>>>>>> "rx_q0_packets": 0,...}}
>>>>>>>
>>>>>>> This patch supports json pretty print by adding extra
>> indent=4
>>>>>>> parameter, so the same command will output:
>>>>>>> {
>>>>>>>     "/ethdev/xstats": {
>>>>>>>         "rx_good_packets": 0,
>>>>>>>         "tx_good_packets": 0,
>>>>>>>         "rx_good_bytes": 0,
>>>>>>>         "tx_good_bytes": 0,
>>>>>>>         "rx_missed_errors": 0,
>>>>>>>         "rx_errors": 0,
>>>>>>>         "tx_errors": 0,
>>>>>>>         "rx_mbuf_allocation_errors": 0,
>>>>>>>         "rx_q0_packets": 0,
>>>>>>>         ...
>>>>>>>     }
>>>>>>> }
>>>>>>>
>>>>>>> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
>>>>>>
>>>>>> It's indeed easier to read, but maybe 4 chars is too much.
>>>>>> 2 chars seem enough to me.
>>>>> [CP]
>>>>> +1 on using 2 chars
> 
> +1 to 2 spaces, following the convention of the rte_<lib>_dump() functions in DPDK.

Already fix in v3.

> 
>>>>>
>>>>>>
>>>>>> In any case I like the idea:
>>>>
>>>> I like it too, for interactive use. However, we also have some
>> hooks in the
>>>> code for when the app is being run non-interactively i.e. from a
>> script. In
>>>> that case, we probably want the indent to be unused.
>>>>
>>>> The function "handle_socket()" tracks if the output is a tty via
>> the "prompt"
>>>> variable. That could be passed through to the "read_socket()" call
>> to
>>>> optionally not-indent the output.

The v3 support indent only under interactive mode.

>>>>
>>>> /Bruce
>>>
>>> Convention in other tools is a -p flag for "pretty output"
>>
>> Since we already support detecting interactive use, I think having the
>> pretty output by default in that case is probably good.
> 
> +1 to pretty by default.
> 
>> For non-
>> interactive
>> use a -p flag might make sense, but even then I'm not sure it's hugely
>> worthwhile.
> 
> +1 to Bruce's comment about not being worthwhile. And we would need the inverse of -p. :-)

+1 for not being worthwhile.

> 
> Closely related:
> 
> If we agree that the JSON output is either for human or machine consumption, why don't we give JANSSON the JSON_COMPACT flag to save some spaces?
> 
> 
> .
>