[v2,09/16] usertools: add new telemetry python script
diff mbox series

Message ID 20200408164956.47864-10-ciara.power@intel.com
State Superseded, archived
Delegated to: David Marchand
Headers show
Series
  • update and simplify telemetry library.
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Ciara Power April 8, 2020, 4:49 p.m. UTC
From: Bruce Richardson <bruce.richardson@intel.com>

This patch adds a python script that can be used with the new telemetry
socket. It connects as a client to the socket, and allows the user send
a command and see the JSON response.

The example usage below shows the script connecting to the new telemetry
socket, and sending two basic ethdev commands entered by the user.
The response for each command is shown below the user input.

Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
{"pid": 63724, "version": "DPDK 20.05.0-rc0", "max_output_len": 16384}
--> /
{"/": ["/", "/ethdev/link_status", "/ethdev/list", "/ethdev/xstats", \
    "/info"]}
--> /info
{"/info": {"pid": 63724, "version": "DPDK 20.05.0-rc0", \
    "max_output_len": 16384}}
--> /ethdev/list
{"/ethdev/list": [0, 1]}
--> /ethdev/link_status,0
{"/ethdev/link_status": {"status": "UP", "speed": 10000, "duplex": \
    "full-duplex"}}
--> /ethdev/xstats,0
{"/ethdev/xstats": {"rx_good_packets": 0, "tx_good_packets": 0, \
    <snip>
    "tx_priority7_xon_to_xoff_packets": 0}}

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Ciara Power <ciara.power@intel.com>

---
v2:
  - Renamed new python script to dpdk-telemetry.py.
  - Fixed script to validate input before sending to Telemetry.
---
 usertools/dpdk-telemetry.py | 44 +++++++++++++++++++++++++++++++++++++
 usertools/meson.build       |  2 +-
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-telemetry.py

Comments

Pattan, Reshma April 10, 2020, 9:43 a.m. UTC | #1
> -----Original Message-----
> From: Power, Ciara <ciara.power@intel.com>

Some  pylint checks  found, good to address  valid ones.

#pylint-3.6 ./usertools/dpdk-telemetry.py or # pylint ./usertools/dpdk-telemetry.py
************* Module dpdk-telemetry
W: 18, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation)
W: 19, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation)
C: 30, 0: Unnecessary parens after 'while' keyword (superfluous-parens)
W: 41, 0: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
W: 44, 0: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
C:  1, 0: Invalid module name "dpdk-telemetry" (invalid-name)
C:  1, 0: Missing module docstring (missing-docstring)
C: 10, 0: Invalid constant name "telemetry_version" (invalid-name)
C: 12, 0: Missing function docstring (missing-docstring)
C: 21, 0: Missing function docstring (missing-docstring)
C: 38, 0: Invalid constant name "fd" (invalid-name)

>+def read_socket(buf_len):
>+        return json.loads(reply)

Close the open fd?

>+    except:
>+            print("Error in reply: ", reply)

Close the open fd?

>+            raise

> +def handle_socket(path):
<snip>
> +        fd.connect(path)
> +    except OSError:

Good to add reason of error message. 
Do you need to close the fd?

> +        return
Bruce Richardson April 10, 2020, 9:54 a.m. UTC | #2
On Fri, Apr 10, 2020 at 10:43:18AM +0100, Pattan, Reshma wrote:
> 
> 
> > -----Original Message-----
> > From: Power, Ciara <ciara.power@intel.com>
> 
> Some  pylint checks  found, good to address  valid ones.
> 
> #pylint-3.6 ./usertools/dpdk-telemetry.py or # pylint ./usertools/dpdk-telemetry.py
> ************* Module dpdk-telemetry
> W: 18, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation)
> W: 19, 0: Bad indentation. Found 12 spaces, expected 8 (bad-indentation)
> C: 30, 0: Unnecessary parens after 'while' keyword (superfluous-parens)
> W: 41, 0: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
> W: 44, 0: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
> C:  1, 0: Invalid module name "dpdk-telemetry" (invalid-name)
> C:  1, 0: Missing module docstring (missing-docstring)
> C: 10, 0: Invalid constant name "telemetry_version" (invalid-name)
> C: 12, 0: Missing function docstring (missing-docstring)
> C: 21, 0: Missing function docstring (missing-docstring)
> C: 38, 0: Invalid constant name "fd" (invalid-name)
> 
> >+def read_socket(buf_len):
> >+        return json.loads(reply)
> 
> Close the open fd?
> 
> >+    except:
> >+            print("Error in reply: ", reply)
> 
> Close the open fd?
> 
> >+            raise
> 
> > +def handle_socket(path):
> <snip>
> > +        fd.connect(path)
> > +    except OSError:
> 
> Good to add reason of error message.
> Do you need to close the fd?
> 
> > +        return
> 
Thanks for the review, Reshma. For v3 we are ensuring pep8/pycodestyle
compliance, but we'll also add pylint to the list to run. We'll look into
the other issues too.

Patch
diff mbox series

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
new file mode 100755
index 0000000000..55fa532136
--- /dev/null
+++ b/usertools/dpdk-telemetry.py
@@ -0,0 +1,44 @@ 
+#! /usr/bin/python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import socket
+import os
+import glob
+import json
+
+telemetry_version = "v2"
+
+def read_socket(buf_len):
+    reply = fd.recv(buf_len).decode()
+    try:
+        print(json.dumps(json.loads(reply)))
+        return json.loads(reply)
+    except:
+            print("Error in reply: ", reply)
+            raise
+
+def handle_socket(path):
+    print("Connecting to " + path)
+    try:
+        fd.connect(path)
+    except OSError:
+        return
+    json_reply = read_socket(1024)
+    output_buf_len = json_reply["max_output_len"]
+    text = input('--> ').strip()
+    while (text != "quit"):
+        if text.startswith('/'):
+            fd.send(text.encode())
+            read_socket(output_buf_len)
+        text = input('--> ').strip()
+
+    fd.close()
+
+fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+# Path to sockets for processes run as a root user
+for f in glob.glob('/var/run/dpdk/*/dpdk_telemetry.%s' % telemetry_version):
+  handle_socket(f)
+# Path to sockets for processes run as a regular user
+for f in glob.glob('/run/user/%d/dpdk/*/dpdk_telemetry.%s' % (os.getuid(), telemetry_version)):
+  handle_socket(f)
diff --git a/usertools/meson.build b/usertools/meson.build
index 149e788e3d..64e27238f4 100644
--- a/usertools/meson.build
+++ b/usertools/meson.build
@@ -1,4 +1,4 @@ 
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-install_data(['dpdk-devbind.py', 'dpdk-pmdinfo.py'], install_dir: 'bin')
+install_data(['dpdk-devbind.py', 'dpdk-pmdinfo.py', 'dpdk-telemetry.py'], install_dir: 'bin')