Skip to contentSkip to conversation

usertools/telemetry: add non-interactive mode

PATCH In review David Hunt 3 participants 5 messages Sep 9, 2021 – Sep 15, 2021

lore
Share & tools
lore

David Hunt

author
#0 lore raw

PATCH 1/1 usertools/telemetry: add non-interactive mode

Add non-interactive mode to dpdk-telemetry.py so that a query string can be supplied on the command line, and script dumps out data and exits. Handing for calling from scripts.

---
 usertools/dpdk-telemetry.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
usertools/dpdk-telemetry.py +14 -8
index e04aa04702..5ce772d49d 100755
@@ -48,7 +48,7 @@ def get_app_name(pid):
     return None
 
 
-def handle_socket(path):
+def handle_socket(path, query):
     """ Connect to socket and handle user input """
     sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
     global CMDS
@@ -69,13 +69,17 @@ def handle_socket(path):
     sock.send("/".encode())
     CMDS = read_socket(sock, output_buf_len, False)["/"]
 
-    # interactive prompt
-    text = input('--> ').strip()
-    while text != "quit":
-        if text.startswith('/'):
-            sock.send(text.encode())
-            read_socket(sock, output_buf_len)
+    if (query != ""):
+        sock.send(query.encode())
+        read_socket(sock, output_buf_len)
+    else:
+        # interactive prompt
         text = input('--> ').strip()
+        while text != "quit":
+            if text.startswith('/'):
+                sock.send(text.encode())
+                read_socket(sock, output_buf_len)
+            text = input('--> ').strip()
     sock.close()
 
 
@@ -104,6 +108,8 @@ def get_dpdk_runtime_dir(fp):
 parser = argparse.ArgumentParser()
 parser.add_argument('-f', '--file-prefix', \
         help='Provide file-prefix for DPDK runtime directory', default='rte')
+parser.add_argument('-q', '--query', \
+        help='run this query and exit', default='')
 args = parser.parse_args()
 rdir = get_dpdk_runtime_dir(args.file_prefix)
-handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
+handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)), args.query)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · David Hunt

Add non-interactive mode to dpdk-telemetry.py so that a query string can be supplied on the command line, and script dumps out data and exits. Handing for calling from scripts.

---

Hi Dave,

I'm not sure I like the use of "-q" for adding a query mode - it's more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative approach here might be to improve support for piping the input commands to the script instead so that you can do e.g.

"echo /ethdev/stats,0 | dpdk-telemetry.py"

and have that work well in a script.

I'll do up a patchset for improving that and upstream it for feedback.

/Bruce

#2 lore raw
Quoted 14 lines · Bruce Richardson
Quoted 6 lines · David Hunt

Add non-interactive mode to dpdk-telemetry.py so that a query string can be supplied on the command line, and script dumps out data and exits. Handing for calling from scripts.

---

Hi Dave,

I'm not sure I like the use of "-q" for adding a query mode - it's more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative approach here might be to improve support for piping the input commands to the script instead so that you can do e.g.

Quoted 6 lines

"echo /ethdev/stats,0 | dpdk-telemetry.py"

and have that work well in a script.

I'll do up a patchset for improving that and upstream it for feedback.

Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867

/Bruce

#3 lore raw

Hi Dave,

Quoted 25 lines

-----Original Message-----
From: Richardson, Bruce <[email protected]>
Sent: Monday 13 September 2021 11:54
To: Hunt, David <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v1] usertools/telemetry: add non-interactive mode

Quoted 16 lines · Bruce Richardson
Quoted 6 lines · David Hunt

Add non-interactive mode to dpdk-telemetry.py so that a query string can be supplied on the command line, and script dumps out data and exits. Handing for calling from scripts.

---

Hi Dave,

I'm not sure I like the use of "-q" for adding a query mode - it's more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative approach here might be to improve support for piping the input commands to the script instead so that you can do e.g.

"echo /ethdev/stats,0 | dpdk-telemetry.py"

Quoted 8 lines
Quoted 4 lines

and have that work well in a script.

I'll do up a patchset for improving that and upstream it for feedback.

Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867

/Bruce

Thanks for this, although I do think the improvement to allow for piping is a better solution. I have acked Bruce's patchset, hopefully that will be suitable for your use case.

Thanks,
Ciara

author
#4 lore raw
Quoted 31 lines · Ciara

Hi Dave,

Quoted 29 lines

-----Original Message-----
From: Richardson, Bruce <[email protected]>
Sent: Monday 13 September 2021 11:54
To: Hunt, David <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v1] usertools/telemetry: add non-interactive mode

Quoted 20 lines · Bruce Richardson
Quoted 6 lines · David Hunt

Add non-interactive mode to dpdk-telemetry.py so that a query string can be supplied on the command line, and script dumps out data and exits. Handing for calling from scripts.

---

Hi Dave,

I'm not sure I like the use of "-q" for adding a query mode - it's more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative approach here might be to improve support for piping the input commands to the script instead so that you can do e.g.

"echo /ethdev/stats,0 | dpdk-telemetry.py"

and have that work well in a script.

I'll do up a patchset for improving that and upstream it for feedback.

Quoted 8 lines
Quoted 3 lines

Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867

/Bruce

Thanks for this, although I do think the improvement to allow for piping is a better solution. I have acked Bruce's patchset, hopefully that will be suitable for your use case.

Thanks,
Ciara

+1

I'll mark my patchset as superceeded.

Rgds,
Dave.