From patchwork Mon Sep 13 10:51:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 98739 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5F156A0C45; Mon, 13 Sep 2021 12:52:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4877540E28; Mon, 13 Sep 2021 12:52:08 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id A039B4014F; Mon, 13 Sep 2021 12:52:06 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10105"; a="208871210" X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="208871210" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 03:52:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="696638998" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga006.fm.intel.com with ESMTP; 13 Sep 2021 03:52:03 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, david.hunt@intel.com, Bruce Richardson , stable@dpdk.org, Keith Wiles , Kevin Laatz , Anatoly Burakov Date: Mon, 13 Sep 2021 11:51:35 +0100 Message-Id: <20210913105137.130097-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com> References: <20210913105137.130097-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors 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 Sender: "dev" Fix style errors reported by flake8. Fixes: 6a2967c112a3 ("usertools: add new telemetry script") Fixes: 2d9a697e41ca ("usertools: add file-prefix option for telemetry") Cc: stable@dpdk.org Signed-off-by: Bruce Richardson Acked-by: Kevin Laatz --- usertools/dpdk-telemetry.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index e04aa04702..bdc617db18 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -9,7 +9,6 @@ import socket import os -import glob import json import errno import readline @@ -102,8 +101,8 @@ def get_dpdk_runtime_dir(fp): readline.set_completer_delims(readline.get_completer_delims().replace('/', '')) parser = argparse.ArgumentParser() -parser.add_argument('-f', '--file-prefix', \ - help='Provide file-prefix for DPDK runtime directory', default='rte') +parser.add_argument('-f', '--file-prefix', default='rte', + help='Provide file-prefix for DPDK runtime directory') args = parser.parse_args() -rdir = get_dpdk_runtime_dir(args.file_prefix) -handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION))) +rd = get_dpdk_runtime_dir(args.file_prefix) +handle_socket(os.path.join(rd, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION))) From patchwork Mon Sep 13 10:51:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 98740 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8A33BA0C45; Mon, 13 Sep 2021 12:52:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0AA1410EB; Mon, 13 Sep 2021 12:52:12 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 6446C410E1; Mon, 13 Sep 2021 12:52:10 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10105"; a="208871221" X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="208871221" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 03:52:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="696639031" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga006.fm.intel.com with ESMTP; 13 Sep 2021 03:52:08 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, david.hunt@intel.com, Bruce Richardson , stable@dpdk.org, Keith Wiles Date: Mon, 13 Sep 2021 11:51:36 +0100 Message-Id: <20210913105137.130097-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com> References: <20210913105137.130097-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe 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 Sender: "dev" To allow the script to take queries from input pipes e.g. "echo /ethdev/stats,0 | dpdk-telemetry.py", we need to handle the case of EOF correctly without crashing with an exception. Do this by using a try-except block around the input handling. Fixes: 6a2967c112a3 ("usertools: add new telemetry script") Cc: stable@dpdk.org Signed-off-by: Bruce Richardson --- usertools/dpdk-telemetry.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index bdc617db18..7ebbb64fce 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -69,13 +69,17 @@ def handle_socket(path): CMDS = read_socket(sock, output_buf_len, False)["/"] # interactive prompt - text = input('--> ').strip() - while text != "quit": - if text.startswith('/'): - sock.send(text.encode()) - read_socket(sock, output_buf_len) + try: text = input('--> ').strip() - sock.close() + while text != "quit": + if text.startswith('/'): + sock.send(text.encode()) + read_socket(sock, output_buf_len) + text = input('--> ').strip() + except EOFError: + pass + finally: + sock.close() def readline_complete(text, state): From patchwork Mon Sep 13 10:51:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 98741 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41566A0C45; Mon, 13 Sep 2021 12:52:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8C90410FA; Mon, 13 Sep 2021 12:52:14 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 810B5410F5 for ; Mon, 13 Sep 2021 12:52:13 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10105"; a="208871225" X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="208871225" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 03:52:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="696639068" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga006.fm.intel.com with ESMTP; 13 Sep 2021 03:52:11 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, david.hunt@intel.com, Bruce Richardson Date: Mon, 13 Sep 2021 11:51:37 +0100 Message-Id: <20210913105137.130097-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com> References: <20210913105137.130097-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes 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 Sender: "dev" When the input to the script is coming from a device which is not a TTY then we become less verbose and skip the prompts and helpful messages about what is happening. Signed-off-by: Bruce Richardson --- usertools/dpdk-telemetry.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index 7ebbb64fce..2974a64732 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -9,6 +9,7 @@ import socket import os +import sys import json import errno import readline @@ -49,19 +50,23 @@ def get_app_name(pid): def handle_socket(path): """ Connect to socket and handle user input """ + prompt = '' # this evaluates to false in conditions sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) global CMDS - print("Connecting to " + path) + + if os.isatty(sys.stdin.fileno()): + prompt = '--> ' + print("Connecting to " + path) try: sock.connect(path) except OSError: print("Error connecting to " + path) sock.close() return - json_reply = read_socket(sock, 1024) + json_reply = read_socket(sock, 1024, prompt) output_buf_len = json_reply["max_output_len"] app_name = get_app_name(json_reply["pid"]) - if app_name: + if app_name and prompt: print('Connected to application: "%s"' % app_name) # get list of commands for readline completion @@ -70,12 +75,12 @@ def handle_socket(path): # interactive prompt try: - text = input('--> ').strip() + text = input(prompt).strip() while text != "quit": if text.startswith('/'): sock.send(text.encode()) read_socket(sock, output_buf_len) - text = input('--> ').strip() + text = input(prompt).strip() except EOFError: pass finally: