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 BC5EE423A1; Tue, 10 Jan 2023 08:32:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0654D42D21; Tue, 10 Jan 2023 08:32:00 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id BCF9F40689 for ; Tue, 10 Jan 2023 08:31:58 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NrjBw4ZzhzRr58; Tue, 10 Jan 2023 15:30:16 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 15:31:56 +0800 From: Huisong Li To: CC: , , , , , , Subject: [PATCH v2 2/2] usertools: add an argument for file prefix Date: Tue, 10 Jan 2023 15:31:46 +0800 Message-ID: <20230110073146.8221-3-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20230110073146.8221-1-lihuisong@huawei.com> References: <20230109065547.8819-1-lihuisong@huawei.com> <20230110073146.8221-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600004.china.huawei.com (7.193.23.242) 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 file prefix for DPDK runtime directory is 'rte' which was fixed in the telemetry client script. The user had to modify the prefix each time to run this script if the file prefix of application isn't 'rte'. So this patch adds an optional argument for the file prefix, like, "./dpdk-telemetry-client.py -f rte_xxx sock_path" Signed-off-by: Huisong Li Acked-by: Bruce Richardson --- usertools/dpdk-telemetry-client.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py index 144a8fb5e0..0581ef8a00 100755 --- a/usertools/dpdk-telemetry-client.py +++ b/usertools/dpdk-telemetry-client.py @@ -15,6 +15,8 @@ API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\"" GLOBAL_METRICS_REQ = "{\"action\":0,\"command\":\"global_stat_values\",\"data\":null}" DEFAULT_FP = "/var/run/dpdk/default_client" +DEFAULT_PREFIX = 'rte' +RUNTIME_SOCKET_NAME = 'telemetry' class Socket: @@ -36,6 +38,7 @@ class Client: def __init__(self): # Creates a client instance self.socket = Socket() self.file_path = None + self.run_path = None self.choice = None self.unregistered = 0 @@ -49,6 +52,10 @@ def __del__(self): def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client self.file_path = file_path + def setRunpath(self, file_path): + self.run_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), + RUNTIME_SOCKET_NAME) + def register(self): # Connects a client to DPDK-instance if os.path.exists(self.file_path): os.unlink(self.file_path) @@ -57,7 +64,7 @@ def register(self): # Connects a client to DPDK-instance except socket.error as msg: print ("Error - Socket binding error: " + str(msg) + "\n") self.socket.recv_fd.settimeout(2) - self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry") + self.socket.send_fd.connect(self.run_path) JSON = (API_REG + self.file_path + "\"}}") self.socket.send_fd.sendall(JSON.encode()) @@ -113,15 +120,31 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr except: pass + +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 """ + run_dir = os.environ.get('RUNTIME_DIRECTORY') + if not run_dir: + if (os.getuid() == 0): + run_dir = '/var/run' + else: + run_dir = os.environ.get('XDG_RUNTIME_DIR', '/tmp') + return os.path.join(run_dir, 'dpdk', fp) + + if __name__ == "__main__": sleep_time = 1 parser = argparse.ArgumentParser() + parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX, + help='Provide file-prefix for DPDK runtime directory') parser.add_argument('sock_path', nargs='?', default=DEFAULT_FP, help='Provide socket file path connected by legacy client') args = parser.parse_args() client = Client() client.getFilepath(args.sock_path) + client.setRunpath(args.file_prefix) client.register() client.interactiveMenu(sleep_time) -- 2.22.0