DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <dev@dpdk.org>
Cc: <bruce.richardson@intel.com>, <mb@smartsharesystems.com>,
	<andrew.rybchenko@oktetlabs.ru>, <huangdaode@huawei.com>,
	<liudongdong3@huawei.com>, <fengchengwen@huawei.com>,
	<lihuisong@huawei.com>
Subject: [PATCH 2/2] usertools: add an argment for file prefix
Date: Mon, 9 Jan 2023 14:55:47 +0800	[thread overview]
Message-ID: <20230109065547.8819-3-lihuisong@huawei.com> (raw)
In-Reply-To: <20230109065547.8819-1-lihuisong@huawei.com>

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 addes an optional argment for the file prefix, like,
"./dpdk-telemetry-client.py -f rte_xxx -s file_path"

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 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 fd69955b32..f1561af4c6 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('-s', '--sock_path', 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


  parent reply	other threads:[~2023-01-09  6:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  6:55 [PATCH 0/2] usertools: use argparse module to get input and add an argment Huisong Li
2023-01-09  6:55 ` [PATCH 1/2] usertools: use argparse module to get input parameter Huisong Li
2023-01-09  9:14   ` Bruce Richardson
2023-01-09 12:26     ` lihuisong (C)
2023-01-09 14:32       ` Bruce Richardson
2023-01-10  6:24         ` lihuisong (C)
2023-01-09  6:55 ` Huisong Li [this message]
2023-01-09  9:16   ` [PATCH 2/2] usertools: add an argment for file prefix Bruce Richardson
2023-01-09 17:07 ` [PATCH] usertools: fix python warnings Stephen Hemminger
2023-02-06  7:47   ` Thomas Monjalon
2023-01-10  7:31 ` [PATCH v2 0/2] usertools: usertools: use argparse to get input and add an argument Huisong Li
2023-01-10  7:31   ` [PATCH v2 1/2] usertools: use argparse module to get input parameter Huisong Li
2023-01-10  9:12     ` Bruce Richardson
2023-01-10  7:31   ` [PATCH v2 2/2] usertools: add an argument for file prefix Huisong Li
2023-02-06  8:30   ` [PATCH v2 0/2] usertools: usertools: use argparse to get input and add an argument Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109065547.8819-3-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=huangdaode@huawei.com \
    --cc=liudongdong3@huawei.com \
    --cc=mb@smartsharesystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).