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 4AC10A00C2; Wed, 24 Aug 2022 10:15:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD89A410DD; Wed, 24 Aug 2022 10:15:47 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id BEE9640DDE for ; Wed, 24 Aug 2022 10:15:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661328946; x=1692864946; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Kjf9eepqCtCbfkck37FZJCSpyBdLsmOm1KdDcOAklmo=; b=ckopNmS7/3gFJdktqoR/0H/aLKSac+OOt0G/acKCFmJ7aWB+z174Hqmi 3D2rT32w2apqbcA2h7j08mpS53u4zWrKmnwDWY+odE15aj6Um3akIRoYc qw6N/dIQnnxYzc1cv5+Kb99nXpT5EmkmkkIag59A9QJ6T1Pp13P8FbKWC xxXRgLYLICcTohYNfEk2yYmuRTDlh8pK8b43IGLvi7vwSs63JGcT9ypQW eyfaCkwkh4aXYtSVi+UZQ2jTY4bS1p6RVVBT+UfmPTuv2eSl1AFUakdGe o0XI+Mfc+jBjv1ky55qQDMS8sJV1fXps5ZOHptELNRirraM1dHod/uefS Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10448"; a="292645947" X-IronPort-AV: E=Sophos;i="5.93,260,1654585200"; d="scan'208";a="292645947" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2022 01:15:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,260,1654585200"; d="scan'208";a="560505016" Received: from silpixa00401160.ir.intel.com ([10.55.129.109]) by orsmga003.jf.intel.com with ESMTP; 24 Aug 2022 01:15:43 -0700 From: Conor Walsh To: ciara.power@intel.com, thomas@monjalon.net, anatoly.burakov@intel.com Cc: dev@dpdk.org, Conor Walsh Subject: [PATCH 1/2] usertools/telemetry: move main to function Date: Wed, 24 Aug 2022 09:15:38 +0100 Message-Id: <20220824081539.12379-1-conor.walsh@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 In order to allow other tools to use the generic telemetry functions provided within dpdk-telemetry move the "main" part of the code to a function and only run this code if the tool has been called by a user. This allows other scripts to use the tool as a module to prevent code duplication. Signed-off-by: Conor Walsh --- usertools/dpdk-telemetry.py | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index a81868a547..2c85fd95b4 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -161,22 +161,27 @@ def readline_complete(text, state): return matches[state] -readline.parse_and_bind('tab: complete') -readline.set_completer(readline_complete) -readline.set_completer_delims(readline.get_completer_delims().replace('/', '')) - -parser = argparse.ArgumentParser() -parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX, - help='Provide file-prefix for DPDK runtime directory') -parser.add_argument('-i', '--instance', default='0', type=int, - help='Provide instance number for DPDK application') -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) -handle_socket(args, sock_path) +def main(): + readline.parse_and_bind('tab: complete') + readline.set_completer(readline_complete) + readline.set_completer_delims(readline.get_completer_delims().replace('/', '')) + + parser = argparse.ArgumentParser() + parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX, + help='Provide file-prefix for DPDK runtime directory') + parser.add_argument('-i', '--instance', default='0', type=int, + help='Provide instance number for DPDK application') + 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) + handle_socket(args, sock_path) + + +if __name__ == '__main__': + main() -- 2.25.1