usertools: telemetry json support pretty print

Message ID 20221014023338.51464-1-fengchengwen@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series usertools: telemetry json support pretty print |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/intel-Testing fail Testing issues
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

fengchengwen Oct. 14, 2022, 2:33 a.m. UTC
  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(-)
  

Patch

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