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 F23E7A00C2; Wed, 31 Aug 2022 13:53:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 978E940F18; Wed, 31 Aug 2022 13:53:04 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 751E940395 for ; Wed, 31 Aug 2022 13:53:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661946783; x=1693482783; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kjf9eepqCtCbfkck37FZJCSpyBdLsmOm1KdDcOAklmo=; b=gJf05IJkV4vpdRJgSFhyZnx9hrNiQq/p6r55Bc/MpXuNJVdLZuvltmBP rDfMe3rNrmyLv6awQYnd+3dr5tI9CMvjdgYLaSfG4WKCxX2vzaVphAs51 7xDb9QTbJTwg6eRsLgBm25voew050kXb2HIOmwT5hTL6XSRMBkQ2MQ0zi 5LDR52hCcAcDynmLcuykwY8snBJIttyFweDqqhPU8P0UrK4DIywKT+Xi8 tHGRQ4PIlZDBuRAULzXqdSjehaYuqXqK0XldRtj7cPB6KJZSfcQpvxOYC ykaeDniZtSzRAjccp5/RILovT5gV2ep++ZxBh/ImvFVLDwR2TpS0YBlLD g==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="275176303" X-IronPort-AV: E=Sophos;i="5.93,277,1654585200"; d="scan'208";a="275176303" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2022 04:52:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,277,1654585200"; d="scan'208";a="589002658" Received: from silpixa00401160.ir.intel.com ([10.55.128.243]) by orsmga006.jf.intel.com with ESMTP; 31 Aug 2022 04:52:53 -0700 From: Conor Walsh To: ciara.power@intel.com, thomas@monjalon.net, anatoly.burakov@intel.com Cc: dev@dpdk.org, bruce.richardson@intel.com, Conor Walsh Subject: [PATCH v2 1/2] usertools/telemetry: move main to function Date: Wed, 31 Aug 2022 12:52:49 +0100 Message-Id: <20220831115250.362189-1-conor.walsh@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220824081539.12379-1-conor.walsh@intel.com> References: <20220824081539.12379-1-conor.walsh@intel.com> 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