Skip to contentSkip to conversation

improvements for telemetry script

PATCH Applied Bruce Richardson 4 participants 7 messages Sep 13, 2021 – Oct 1, 2021

lore
Share & tools
lore
#0 lore raw

cover improvements for telemetry script

Patch 1 fixes errors reported by flake8 in the telemetry python script. Inspired by the work by Dave Hunt [1] the final two patches look to adjust the script so that it works nicer when commands come from an input pipe rather than from an interactive terminal.

Without this set:

  $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
  Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
  {"version": "DPDK 21.11.0-rc0", "pid": 130033, "max_output_len": 16384}
  Connected to application: "dpdk-test"
  --> {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}
  --> Traceback (most recent call last):
    File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 109, in <module>
      handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
    File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 78, in handle_socket
      text = input('--> ').strip()
  EOFError: EOF when reading a line

With this patchset:

  $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
  {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}

[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/

Bruce Richardson (3):
usertools/dpdk-telemetry: fix flake8 errors usertools/dpdk_telemetry: fix handling EOF for input pipe usertools/dpdk-telemetry: silence prompts for input pipes

 usertools/dpdk-telemetry.py | 38 ++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

--
2.30.2

#1 lore raw

PATCH 1/3 usertools/dpdk-telemetry: fix flake8 errors

Fix style errors reported by flake8.

Fixes 6a2967c112a3 ("usertools: add new telemetry script")
Fixes 2d9a697e41ca ("usertools: add file-prefix option for telemetry")
---
 usertools/dpdk-telemetry.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
usertools/dpdk-telemetry.py +4 -5
index e04aa04702..bdc617db18 100755
@@ -9,7 +9,6 @@
 
 import socket
 import os
-import glob
 import json
 import errno
 import readline
@@ -102,8 +101,8 @@ def get_dpdk_runtime_dir(fp):
 readline.set_completer_delims(readline.get_completer_delims().replace('/', ''))
 
 parser = argparse.ArgumentParser()
-parser.add_argument('-f', '--file-prefix', \
-        help='Provide file-prefix for DPDK runtime directory', default='rte')
+parser.add_argument('-f', '--file-prefix', default='rte',
+                    help='Provide file-prefix for DPDK runtime directory')
 args = parser.parse_args()
-rdir = get_dpdk_runtime_dir(args.file_prefix)
-handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
+rd = get_dpdk_runtime_dir(args.file_prefix)
+handle_socket(os.path.join(rd, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
Signature · 1 line
2.30.2
Acked-by on v1 1/3
#2 lore raw

Re: [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors

Quoted 10 lines · Bruce Richardson

Fix style errors reported by flake8.

Fixes 6a2967c112a3 ("usertools: add new telemetry script")
Fixes 2d9a697e41ca ("usertools: add file-prefix option for telemetry")
---
  usertools/dpdk-telemetry.py | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
#3 lore raw

PATCH 2/3 usertools/dpdk_telemetry: fix handling EOF for input pipe

In reply to Bruce Richardson

To allow the script to take queries from input pipes e.g. "echo /ethdev/stats,0 | dpdk-telemetry.py", we need to handle the case of EOF correctly without crashing with an exception. Do this by using a try-except block around the input handling.

Fixes 6a2967c112a3 ("usertools: add new telemetry script")
---
 usertools/dpdk-telemetry.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
usertools/dpdk-telemetry.py +10 -6
index bdc617db18..7ebbb64fce 100755
@@ -69,13 +69,17 @@ def handle_socket(path):
     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)
+    try:
         text = input('--> ').strip()
-    sock.close()
+        while text != "quit":
+            if text.startswith('/'):
+                sock.send(text.encode())
+                read_socket(sock, output_buf_len)
+            text = input('--> ').strip()
+    except EOFError:
+        pass
+    finally:
+        sock.close()
 
 
 def readline_complete(text, state):
Signature · 1 line
2.30.2
#4 lore raw

PATCH 3/3 usertools/dpdk-telemetry: silence prompts for input pipes

In reply to Bruce Richardson

When the input to the script is coming from a device which is not a TTY then we become less verbose and skip the prompts and helpful messages about what is happening.

---
 usertools/dpdk-telemetry.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
usertools/dpdk-telemetry.py +10 -5
index 7ebbb64fce..2974a64732 100755
@@ -9,6 +9,7 @@
 
 import socket
 import os
+import sys
 import json
 import errno
 import readline
@@ -49,19 +50,23 @@ def get_app_name(pid):
 
 def handle_socket(path):
     """ Connect to socket and handle user input """
+    prompt = ''  # this evaluates to false in conditions
     sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
     global CMDS
-    print("Connecting to " + path)
+
+    if os.isatty(sys.stdin.fileno()):
+        prompt = '--> '
+        print("Connecting to " + path)
     try:
         sock.connect(path)
     except OSError:
         print("Error connecting to " + path)
         sock.close()
         return
-    json_reply = read_socket(sock, 1024)
+    json_reply = read_socket(sock, 1024, prompt)
     output_buf_len = json_reply["max_output_len"]
     app_name = get_app_name(json_reply["pid"])
-    if app_name:
+    if app_name and prompt:
         print('Connected to application: "%s"' % app_name)
 
     # get list of commands for readline completion
@@ -70,12 +75,12 @@ def handle_socket(path):
 
     # interactive prompt
     try:
-        text = input('--> ').strip()
+        text = input(prompt).strip()
         while text != "quit":
             if text.startswith('/'):
                 sock.send(text.encode())
                 read_socket(sock, output_buf_len)
-            text = input('--> ').strip()
+            text = input(prompt).strip()
     except EOFError:
         pass
     finally:
Signature · 1 line
2.30.2
Acked-by on the v1 series
#5 lore raw
In reply to Bruce Richardson

Hi Bruce,

Quoted 42 lines

-----Original Message-----
From: Richardson, Bruce <[email protected]>
Sent: Monday 13 September 2021 11:52
To: [email protected]
Cc: Power, Ciara <[email protected]>; Hunt, David <[email protected]>; Richardson, Bruce <[email protected]>
Subject: [PATCH 0/3] improvements for telemetry script

Patch 1 fixes errors reported by flake8 in the telemetry python script. Inspired by the work by Dave Hunt [1] the final two patches look to adjust the script so that it works nicer when commands come from an input pipe rather than from an interactive terminal.

Without this set:

 $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
 Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
 {"version": "DPDK 21.11.0-rc0", "pid": 130033, "max_output_len": 16384}
 Connected to application: "dpdk-test"
 --> {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}
 --> Traceback (most recent call last):
   File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 109, in
<module>
     handle_socket(os.path.join(rdir,
'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
   File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 78, in
handle_socket
     text = input('--> ').strip()
 EOFError: EOF when reading a line

With this patchset:

 $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
 {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}

[1] http://patches.dpdk.org/project/dpdk/patch/20210909155625.24581-1-
[email protected]/

Bruce Richardson (3):
usertools/dpdk-telemetry: fix flake8 errors usertools/dpdk_telemetry: fix handling EOF for input pipe usertools/dpdk-telemetry: silence prompts for input pipes

Quoted 5 lines

usertools/dpdk-telemetry.py | 38 ++++++++++++++++++++++---------------

1 file changed, 23 insertions(+), 15 deletions(-)

--
2.30.2

For the series,

Thanks!

#6 lore raw
Quoted 29 lines
Quoted 29 lines

Patch 1 fixes errors reported by flake8 in the telemetry python script. Inspired by the work by Dave Hunt [1] the final two patches look to adjust the script so that it works nicer when commands come from an input pipe rather than from an interactive terminal.

Without this set:

 $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
 Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
 {"version": "DPDK 21.11.0-rc0", "pid": 130033, "max_output_len": 16384}
 Connected to application: "dpdk-test"
 --> {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}
 --> Traceback (most recent call last):
   File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 109, in
<module>
     handle_socket(os.path.join(rdir,
'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
   File "/home/bruce/dpdk.org/./usertools/dpdk-telemetry.py", line 78, in
handle_socket
     text = input('--> ').strip()
 EOFError: EOF when reading a line

With this patchset:

 $ echo "/eal/params" | ./usertools/dpdk-telemetry.py
 {"/eal/params": ["./build/app/test/dpdk-test", "-c", "F", "--no-huge"]}

[1] http://patches.dpdk.org/project/dpdk/patch/20210909155625.24581-1-
[email protected]/

Quoted 7 lines
Quoted 4 lines

Bruce Richardson (3):
usertools/dpdk-telemetry: fix flake8 errors usertools/dpdk_telemetry: fix handling EOF for input pipe usertools/dpdk-telemetry: silence prompts for input pipes

For the series,

Applied, thanks.