From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>
Cc: <dev@dpdk.org>, <ciara.power@intel.com>,
<david.marchand@redhat.com>, <bruce.richardson@intel.com>,
<stephen@networkplumber.org>, <mb@smartsharesystems.com>
Subject: [PATCH v3] usertools: telemetry pretty print in interactive mode
Date: Mon, 17 Oct 2022 07:41:02 +0000 [thread overview]
Message-ID: <20221017074102.55509-1-fengchengwen@huawei.com> (raw)
In-Reply-To: <20221014023338.51464-1-fengchengwen@huawei.com>
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
next prev parent reply other threads:[~2022-10-17 7:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Chengwen Feng [this message]
2022-10-17 9:15 ` [PATCH v3] usertools: telemetry pretty print in interactive mode Bruce Richardson
2022-10-31 15:16 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221017074102.55509-1-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=bruce.richardson@intel.com \
--cc=ciara.power@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).