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 18673A034F; Mon, 11 Oct 2021 11:49:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 91C9D40E0F; Mon, 11 Oct 2021 11:49:18 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id EC06C40E01 for ; Mon, 11 Oct 2021 11:49:16 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="207644885" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="207644885" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 02:49:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="441372095" Received: from silpixa00401160.ir.intel.com ([10.55.129.96]) by orsmga003.jf.intel.com with ESMTP; 11 Oct 2021 02:49:07 -0700 From: Conor Walsh To: ciara.power@intel.com, bruce.richardson@intel.com Cc: dev@dpdk.org, Conor Walsh Date: Mon, 11 Oct 2021 09:49:03 +0000 Message-Id: <20211011094903.3206203-1-conor.walsh@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211005150017.2779845-1-conor.walsh@intel.com> References: <20211005150017.2779845-1-conor.walsh@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] usertools/telemetry: add list of available file-prefixes 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" This patch adds the option --list (-l) to dpdk-telemetry.py which will print all of the available dpdk file-prefixes that have telemetry enabled. The prefixes will also be printed if the user passes an incorrect prefix in the --file-prefix (-f) option. Depends-on: series-19464 ("improve telemetry support with in-memory mode") Signed-off-by: Conor Walsh Acked-by: Ciara Power --- usertools/dpdk-telemetry.py | 40 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index da3ba60430..d301511c7e 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -72,6 +72,31 @@ def print_socket_options(prefix, paths): s.split(':')[-1])) +def get_dpdk_runtime_dir(fp): + """ Using the same logic as in DPDK's EAL, get the DPDK runtime directory + based on the file-prefix and user """ + if (os.getuid() == 0): + return os.path.join('/var/run/dpdk', fp) + return os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'dpdk', fp) + + +def list_fp(): + """ List all available file-prefixes to user """ + path = get_dpdk_runtime_dir('') + sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*")) + prefixes = [] + if not sockets: + print("No DPDK apps with telemetry enabled available") + else: + print("Valid file-prefixes:\n") + for s in sockets: + prefixes.append(os.path.relpath(os.path.dirname(s), start=path)) + for p in sorted(set(prefixes)): + print(p) + print_socket_options(p, glob.glob(os.path.join(path, p, + SOCKET_NAME + "*"))) + + def handle_socket(args, path): """ Connect to socket and handle user input """ prompt = '' # this evaluates to false in conditions @@ -95,6 +120,8 @@ def handle_socket(args, path): if socks: print("\nOther DPDK telemetry sockets found:") print_socket_options(args.file_prefix, socks) + else: + list_fp() return json_reply = read_socket(sock, 1024, prompt) output_buf_len = json_reply["max_output_len"] @@ -130,14 +157,6 @@ def readline_complete(text, state): return matches[state] -def get_dpdk_runtime_dir(fp): - """ Using the same logic as in DPDK's EAL, get the DPDK runtime directory - based on the file-prefix and user """ - if (os.getuid() == 0): - return os.path.join('/var/run/dpdk', fp) - return os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'dpdk', fp) - - readline.parse_and_bind('tab: complete') readline.set_completer(readline_complete) readline.set_completer_delims(readline.get_completer_delims().replace('/', '')) @@ -147,7 +166,12 @@ def get_dpdk_runtime_dir(fp): help='Provide file-prefix for DPDK runtime directory') parser.add_argument('-i', '--instance', default='0', type=int, help='Provide file-prefix for DPDK runtime directory') +parser.add_argument('-l', '--list', action="store_true", default=False, + help='List all possible file-prefixes and exit') args = parser.parse_args() +if args.list: + list_fp() + sys.exit(0) sock_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), SOCKET_NAME) if args.instance > 0: sock_path += ":{}".format(args.instance) -- 2.25.1