* [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
@ 2021-09-13 10:51 ` Bruce Richardson
2021-09-15 10:05 ` Kevin Laatz
2021-09-13 10:51 ` [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe Bruce Richardson
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Bruce Richardson @ 2021-09-13 10:51 UTC (permalink / raw)
To: dev
Cc: ciara.power, david.hunt, Bruce Richardson, stable, Keith Wiles,
Kevin Laatz, Anatoly Burakov
Fix style errors reported by flake8.
Fixes: 6a2967c112a3 ("usertools: add new telemetry script")
Fixes: 2d9a697e41ca ("usertools: add file-prefix option for telemetry")
Cc: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
usertools/dpdk-telemetry.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index e04aa04702..bdc617db18 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -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)))
--
2.30.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors
2021-09-13 10:51 ` [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors Bruce Richardson
@ 2021-09-15 10:05 ` Kevin Laatz
0 siblings, 0 replies; 7+ messages in thread
From: Kevin Laatz @ 2021-09-15 10:05 UTC (permalink / raw)
To: Bruce Richardson, dev
Cc: ciara.power, david.hunt, stable, Keith Wiles, Anatoly Burakov
On 13/09/2021 11:51, Bruce Richardson wrote:
> Fix style errors reported by flake8.
>
> Fixes: 6a2967c112a3 ("usertools: add new telemetry script")
> Fixes: 2d9a697e41ca ("usertools: add file-prefix option for telemetry")
> Cc: stable@dpdk.org
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> usertools/dpdk-telemetry.py | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Acked-by: Kevin Laatz <kevin.laatz@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors Bruce Richardson
@ 2021-09-13 10:51 ` Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes Bruce Richardson
2021-09-15 10:46 ` [dpdk-dev] [PATCH 0/3] improvements for telemetry script Power, Ciara
3 siblings, 0 replies; 7+ messages in thread
From: Bruce Richardson @ 2021-09-13 10:51 UTC (permalink / raw)
To: dev; +Cc: ciara.power, david.hunt, Bruce Richardson, stable, Keith Wiles
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")
Cc: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
usertools/dpdk-telemetry.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index bdc617db18..7ebbb64fce 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -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):
--
2.30.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe Bruce Richardson
@ 2021-09-13 10:51 ` Bruce Richardson
2021-09-15 10:46 ` [dpdk-dev] [PATCH 0/3] improvements for telemetry script Power, Ciara
3 siblings, 0 replies; 7+ messages in thread
From: Bruce Richardson @ 2021-09-13 10:51 UTC (permalink / raw)
To: dev; +Cc: ciara.power, david.hunt, 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.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
usertools/dpdk-telemetry.py | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 7ebbb64fce..2974a64732 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -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:
--
2.30.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH 0/3] improvements for telemetry script
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
` (2 preceding siblings ...)
2021-09-13 10:51 ` [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes Bruce Richardson
@ 2021-09-15 10:46 ` Power, Ciara
2021-10-01 15:34 ` Thomas Monjalon
3 siblings, 1 reply; 7+ messages in thread
From: Power, Ciara @ 2021-09-15 10:46 UTC (permalink / raw)
To: Richardson, Bruce, dev; +Cc: Hunt, David
Hi Bruce,
>-----Original Message-----
>From: Richardson, Bruce <bruce.richardson@intel.com>
>Sent: Monday 13 September 2021 11:52
>To: dev@dpdk.org
>Cc: Power, Ciara <ciara.power@intel.com>; Hunt, David
><david.hunt@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
>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-
>david.hunt@intel.com/
>
>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
For the series,
Acked-by: Ciara Power <ciara.power@intel.com>
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH 0/3] improvements for telemetry script
2021-09-15 10:46 ` [dpdk-dev] [PATCH 0/3] improvements for telemetry script Power, Ciara
@ 2021-10-01 15:34 ` Thomas Monjalon
0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2021-10-01 15:34 UTC (permalink / raw)
To: Richardson, Bruce; +Cc: dev, Hunt, David, Power, Ciara
> >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-
> >david.hunt@intel.com/
> >
> >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,
> Acked-by: Ciara Power <ciara.power@intel.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread