DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] usertools: telemetry json support pretty print
@ 2022-10-14  2:33 Chengwen Feng
  2022-10-14  3:25 ` [PATCH v2] " Chengwen Feng
  2022-10-17  7:41 ` [PATCH v3] usertools: telemetry pretty print in interactive mode Chengwen Feng
  0 siblings, 2 replies; 12+ messages in thread
From: Chengwen Feng @ 2022-10-14  2:33 UTC (permalink / raw)
  To: thomas; +Cc: dev, ciara.power

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 outupt:
{"/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>
---
 usertools/dpdk-telemetry.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index a81868a547..315f78fb8f 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -33,7 +33,7 @@ def read_socket(sock, buf_len, echo=True):
         sock.close()
         raise
     if echo:
-        print(json.dumps(ret))
+        print(json.dumps(ret, indent=4))
     return ret
 
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14  2:33 [PATCH] usertools: telemetry json support pretty print Chengwen Feng
@ 2022-10-14  3:25 ` Chengwen Feng
  2022-10-14  9:50   ` David Marchand
  2022-10-17  7:41 ` [PATCH v3] usertools: telemetry pretty print in interactive mode Chengwen Feng
  1 sibling, 1 reply; 12+ messages in thread
From: Chengwen Feng @ 2022-10-14  3:25 UTC (permalink / raw)
  To: thomas; +Cc: dev, ciara.power

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>

---
v2: fix typo of output.

---
 usertools/dpdk-telemetry.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index a81868a547..315f78fb8f 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -33,7 +33,7 @@ def read_socket(sock, buf_len, echo=True):
         sock.close()
         raise
     if echo:
-        print(json.dumps(ret))
+        print(json.dumps(ret, indent=4))
     return ret
 
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14  3:25 ` [PATCH v2] " Chengwen Feng
@ 2022-10-14  9:50   ` David Marchand
  2022-10-14 12:44     ` Power, Ciara
  0 siblings, 1 reply; 12+ messages in thread
From: David Marchand @ 2022-10-14  9:50 UTC (permalink / raw)
  To: Chengwen Feng; +Cc: thomas, dev, ciara.power

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.

In any case I like the idea:
Acked-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14  9:50   ` David Marchand
@ 2022-10-14 12:44     ` Power, Ciara
  2022-10-14 13:02       ` Bruce Richardson
  0 siblings, 1 reply; 12+ messages in thread
From: Power, Ciara @ 2022-10-14 12:44 UTC (permalink / raw)
  To: David Marchand, Chengwen Feng; +Cc: thomas, dev

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

> 
> In any case I like the idea:
> Acked-by: David Marchand <david.marchand@redhat.com>
 
Acked-by: Ciara Power <ciara.power@intel.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14 12:44     ` Power, Ciara
@ 2022-10-14 13:02       ` Bruce Richardson
  2022-10-14 15:01         ` Stephen Hemminger
  0 siblings, 1 reply; 12+ messages in thread
From: Bruce Richardson @ 2022-10-14 13:02 UTC (permalink / raw)
  To: Power, Ciara; +Cc: David Marchand, Chengwen Feng, thomas, dev

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
> 
> > 
> > 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.

/Bruce

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14 13:02       ` Bruce Richardson
@ 2022-10-14 15:01         ` Stephen Hemminger
  2022-10-14 15:29           ` Bruce Richardson
  0 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2022-10-14 15:01 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: Power, Ciara, David Marchand, Chengwen Feng, thomas, dev

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
> >   
> > > 
> > > 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.
> 
> /Bruce

Convention in other tools is a -p flag for "pretty output"

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14 15:01         ` Stephen Hemminger
@ 2022-10-14 15:29           ` Bruce Richardson
  2022-10-14 16:10             ` Morten Brørup
  0 siblings, 1 reply; 12+ messages in thread
From: Bruce Richardson @ 2022-10-14 15:29 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Power, Ciara, David Marchand, Chengwen Feng, thomas, dev

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
> > >   
> > > > 
> > > > 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.
> > 
> > /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. For non-interactive
use a -p flag might make sense, but even then I'm not sure it's hugely
worthwhile.

/Bruce

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14 15:29           ` Bruce Richardson
@ 2022-10-14 16:10             ` Morten Brørup
  2022-10-17  7:56               ` fengchengwen
  0 siblings, 1 reply; 12+ messages in thread
From: Morten Brørup @ 2022-10-14 16:10 UTC (permalink / raw)
  To: Bruce Richardson, Stephen Hemminger
  Cc: Power, Ciara, David Marchand, Chengwen Feng, thomas, dev

> 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.

> > > >
> > > > >
> > > > > 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.
> > >
> > > /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. :-)

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?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3] usertools: telemetry pretty print in interactive mode
  2022-10-14  2:33 [PATCH] usertools: telemetry json support pretty print Chengwen Feng
  2022-10-14  3:25 ` [PATCH v2] " Chengwen Feng
@ 2022-10-17  7:41 ` Chengwen Feng
  2022-10-17  9:15   ` Bruce Richardson
  1 sibling, 1 reply; 12+ messages in thread
From: Chengwen Feng @ 2022-10-17  7:41 UTC (permalink / raw)
  To: thomas; +Cc: dev, ciara.power, david.marchand, bruce.richardson, stephen, mb

Currently, the dpdk-telemetry.py show json in raw format under
interactive mode, 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=2
parameter under interactive mode, 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,
    "rx_mbuf_allocation_errors": 0,
    "rx_q0_packets": 0,
    ...
  }
}

Note: the non-interactive mode is made machine-readable and remains the
original way (it means don't use indent to pretty print).

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: David Marchand <david.marchand@redhat.com>
Acked-by: Ciara Power <ciara.power@intel.com>

---
v3: indent modify to 2 and make sure indent under interactive mode
according comments.
v2: fix typo of output.

---
 usertools/dpdk-telemetry.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index a81868a547..568f222a03 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -23,7 +23,7 @@
 CMDS = []
 
 
-def read_socket(sock, buf_len, echo=True):
+def read_socket(sock, buf_len, echo=True, pretty=False):
     """ Read data from socket and return it in JSON format """
     reply = sock.recv(buf_len).decode()
     try:
@@ -33,7 +33,8 @@ def read_socket(sock, buf_len, echo=True):
         sock.close()
         raise
     if echo:
-        print(json.dumps(ret))
+        indent = 2 if pretty else None
+        print(json.dumps(ret, indent=indent))
     return ret
 
 
@@ -127,7 +128,7 @@ def handle_socket(args, path):
         else:
             list_fp()
         return
-    json_reply = read_socket(sock, 1024, prompt)
+    json_reply = read_socket(sock, 1024, prompt, prompt)
     output_buf_len = json_reply["max_output_len"]
     app_name = get_app_name(json_reply["pid"])
     if app_name and prompt:
@@ -143,7 +144,7 @@ def handle_socket(args, path):
         while text != "quit":
             if text.startswith('/'):
                 sock.send(text.encode())
-                read_socket(sock, output_buf_len)
+                read_socket(sock, output_buf_len, pretty=prompt)
             text = input(prompt).strip()
     except EOFError:
         pass
-- 
2.17.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] usertools: telemetry json support pretty print
  2022-10-14 16:10             ` Morten Brørup
@ 2022-10-17  7:56               ` fengchengwen
  0 siblings, 0 replies; 12+ messages in thread
From: fengchengwen @ 2022-10-17  7:56 UTC (permalink / raw)
  To: Morten Brørup, Bruce Richardson, Stephen Hemminger
  Cc: Power, Ciara, David Marchand, thomas, dev

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?
> 
> 
> .
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3] usertools: telemetry pretty print in interactive mode
  2022-10-17  7:41 ` [PATCH v3] usertools: telemetry pretty print in interactive mode Chengwen Feng
@ 2022-10-17  9:15   ` Bruce Richardson
  2022-10-31 15:16     ` Thomas Monjalon
  0 siblings, 1 reply; 12+ messages in thread
From: Bruce Richardson @ 2022-10-17  9:15 UTC (permalink / raw)
  To: Chengwen Feng; +Cc: thomas, dev, ciara.power, david.marchand, stephen, mb

On Mon, Oct 17, 2022 at 07:41:02AM +0000, Chengwen Feng wrote:
> Currently, the dpdk-telemetry.py show json in raw format under
> interactive mode, 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=2
> parameter under interactive mode, 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,
>     "rx_mbuf_allocation_errors": 0,
>     "rx_q0_packets": 0,
>     ...
>   }
> }
> 
> Note: the non-interactive mode is made machine-readable and remains the
> original way (it means don't use indent to pretty print).
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> Acked-by: David Marchand <david.marchand@redhat.com>
> Acked-by: Ciara Power <ciara.power@intel.com>
> 
Tested-by: Bruce Richardson <bruce.richardson@intel.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3] usertools: telemetry pretty print in interactive mode
  2022-10-17  9:15   ` Bruce Richardson
@ 2022-10-31 15:16     ` Thomas Monjalon
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Monjalon @ 2022-10-31 15:16 UTC (permalink / raw)
  To: Chengwen Feng
  Cc: dev, ciara.power, david.marchand, stephen, mb, Bruce Richardson

17/10/2022 11:15, Bruce Richardson:
> On Mon, Oct 17, 2022 at 07:41:02AM +0000, Chengwen Feng wrote:
> > Currently, the dpdk-telemetry.py show json in raw format under
> > interactive mode, 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=2
> > parameter under interactive mode, 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,
> >     "rx_mbuf_allocation_errors": 0,
> >     "rx_q0_packets": 0,
> >     ...
> >   }
> > }
> > 
> > Note: the non-interactive mode is made machine-readable and remains the
> > original way (it means don't use indent to pretty print).
> > 
> > Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> > Acked-by: David Marchand <david.marchand@redhat.com>
> > Acked-by: Ciara Power <ciara.power@intel.com>
> > 
> Tested-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-10-31 15:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14  2:33 [PATCH] usertools: telemetry json support pretty print Chengwen Feng
2022-10-14  3:25 ` [PATCH v2] " Chengwen Feng
2022-10-14  9:50   ` David Marchand
2022-10-14 12:44     ` Power, Ciara
2022-10-14 13:02       ` Bruce Richardson
2022-10-14 15:01         ` Stephen Hemminger
2022-10-14 15:29           ` Bruce Richardson
2022-10-14 16:10             ` Morten Brørup
2022-10-17  7:56               ` fengchengwen
2022-10-17  7:41 ` [PATCH v3] usertools: telemetry pretty print in interactive mode Chengwen Feng
2022-10-17  9:15   ` Bruce Richardson
2022-10-31 15:16     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).