usertools/telemetry: add listing of available file prefixes

Message ID 20211005150017.2779845-1-conor.walsh@intel.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series usertools/telemetry: add listing of available file prefixes |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure
ci/Intel-compilation warning apply issues

Commit Message

Conor Walsh Oct. 5, 2021, 3 p.m. UTC
This patch adds the option --list (-l) to dpdk-telemetry.py which will
print all of the available dpdk file-prefixes that have telemetry enabled.
The prefixes will also be printed if the user passes an incorrect prefix
in the --file-prefix (-f) option.

Depends-on: series-19390 ("improve telemetry support with in-memory mode")

Signed-off-by: Conor Walsh <conor.walsh@intel.com>
---
 usertools/dpdk-telemetry.py | 40 +++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
  

Comments

Power, Ciara Oct. 7, 2021, 3:47 p.m. UTC | #1
Hi Conor,

>-----Original Message-----
>From: Walsh, Conor <conor.walsh@intel.com>
>Sent: Tuesday 5 October 2021 16:00
>To: Power, Ciara <ciara.power@intel.com>; Richardson, Bruce
><bruce.richardson@intel.com>
>Cc: dev@dpdk.org; Walsh, Conor <conor.walsh@intel.com>
>Subject: [PATCH] usertools/telemetry: add listing of available file prefixes
>
>This patch adds the option --list (-l) to dpdk-telemetry.py which will print all of the
>available dpdk file-prefixes that have telemetry enabled.
>The prefixes will also be printed if the user passes an incorrect prefix in the --file-
>prefix (-f) option.
>
>Depends-on: series-19390 ("improve telemetry support with in-memory mode")
>
>Signed-off-by: Conor Walsh <conor.walsh@intel.com>

<snip>

>+
>+def list_fp():
>+    """ List all available file-prefixes to user """
>+    print("Valid file-prefixes:\n")

Nit: I think it might be cleaner to move this down to just before the file prefixes print out, so it doesn't print out when no apps are available.

>+    path = get_dpdk_runtime_dir('')
>+
>+    sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
>+    prefixes = []
>+    if not sockets:
>+        print("\tNo DPDK apps with telemetry enabled available")
>+    for s in sockets:
>+        prefixes.append(os.path.relpath(os.path.dirname(s), start=path))
>+    for p in sorted(set(prefixes)):
>+        print(p)
>+        print_socket_options(p, glob.glob(os.path.join(path, p,
>+                                                       SOCKET_NAME +
>+ "*")))
<snip>

Asides from that one small comment,

Acked-by: Ciara Power <ciara.power@intel.com>

Thanks!
  
Conor Walsh Oct. 8, 2021, 8:20 a.m. UTC | #2
<snip>

> 
> >+
> >+def list_fp():
> >+    """ List all available file-prefixes to user """
> >+    print("Valid file-prefixes:\n")
> 
> Nit: I think it might be cleaner to move this down to just before the file
> prefixes print out, so it doesn't print out when no apps are available.
> 
> >+    path = get_dpdk_runtime_dir('')
> >+
> >+    sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
> >+    prefixes = []
> >+    if not sockets:
> >+        print("\tNo DPDK apps with telemetry enabled available")
> >+    for s in sockets:
> >+        prefixes.append(os.path.relpath(os.path.dirname(s), start=path))
> >+    for p in sorted(set(prefixes)):
> >+        print(p)
> >+        print_socket_options(p, glob.glob(os.path.join(path, p,
> >+                                                       SOCKET_NAME +
> >+ "*")))
> <snip>
> 
> Asides from that one small comment,
> 
> Acked-by: Ciara Power <ciara.power@intel.com>
> 
> Thanks!

Hi Ciara,
Thanks for the ack, I will address your comment in v2.
/Conor.
  

Patch

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 7f22e21828..b7a7553f52 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -72,6 +72,31 @@  def print_socket_options(prefix, paths):
                                                            s.split('.')[-1]))
 
 
+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 """
+    if (os.getuid() == 0):
+        return os.path.join('/var/run/dpdk', fp)
+    return os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'dpdk', fp)
+
+
+def list_fp():
+    """ List all available file-prefixes to user """
+    print("Valid file-prefixes:\n")
+    path = get_dpdk_runtime_dir('')
+
+    sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
+    prefixes = []
+    if not sockets:
+        print("\tNo DPDK apps with telemetry enabled available")
+    for s in sockets:
+        prefixes.append(os.path.relpath(os.path.dirname(s), start=path))
+    for p in sorted(set(prefixes)):
+        print(p)
+        print_socket_options(p, glob.glob(os.path.join(path, p,
+                                                       SOCKET_NAME + "*")))
+
+
 def handle_socket(args, path):
     """ Connect to socket and handle user input """
     prompt = ''  # this evaluates to false in conditions
@@ -95,6 +120,8 @@  def handle_socket(args, path):
         if socks:
             print("\nOther DPDK telemetry sockets found:")
             print_socket_options(args.file_prefix, socks)
+        else:
+            list_fp()
         return
     json_reply = read_socket(sock, 1024, prompt)
     output_buf_len = json_reply["max_output_len"]
@@ -130,14 +157,6 @@  def readline_complete(text, state):
     return matches[state]
 
 
-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 """
-    if (os.getuid() == 0):
-        return os.path.join('/var/run/dpdk', fp)
-    return os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'dpdk', fp)
-
-
 readline.parse_and_bind('tab: complete')
 readline.set_completer(readline_complete)
 readline.set_completer_delims(readline.get_completer_delims().replace('/', ''))
@@ -145,9 +164,14 @@  def get_dpdk_runtime_dir(fp):
 parser = argparse.ArgumentParser()
 parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX,
                     help='Provide file-prefix for DPDK runtime directory')
+parser.add_argument('-l', '--list', action="store_true", default=False,
+                    help='List all possible file-prefixes and exit')
 parser.add_argument('-p', '--pid',
                     help='Connect to DPDK process with the given pid')
 args = parser.parse_args()
+if args.list:
+    list_fp()
+    sys.exit(0)
 rd = get_dpdk_runtime_dir(args.file_prefix)
 sock_path = os.path.join(rd, SOCKET_NAME)
 if args.pid: