From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0BA77A0556; Mon, 17 Oct 2022 09:47:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFB2640143; Mon, 17 Oct 2022 09:47:04 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 83EC4400D7 for ; Mon, 17 Oct 2022 09:47:03 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MrTXS0X2BzJn4k; Mon, 17 Oct 2022 15:44:24 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) 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:46:47 +0800 From: Chengwen Feng To: CC: , , , , , Subject: [PATCH v3] usertools: telemetry pretty print in interactive mode Date: Mon, 17 Oct 2022 07:41:02 +0000 Message-ID: <20221017074102.55509-1-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014023338.51464-1-fengchengwen@huawei.com> References: <20221014023338.51464-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Acked-by: David Marchand Acked-by: Ciara Power --- 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