Skip to contentSkip to conversation

usertools/telemetry: add listing of available file prefixes

PATCH Superseded Conor Walsh 3 participants 9 messages Oct 5, 2021 – Oct 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")

---
 usertools/dpdk-telemetry.py | 40 +++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
usertools/dpdk-telemetry.py +32 -8
index 7f22e21828..b7a7553f52 100755
@@ -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:
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Hi Conor,

Quoted 16 lines

-----Original Message-----
From: Walsh, Conor <[email protected]>
Sent: Tuesday 5 October 2021 16:00
To: Power, Ciara <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]; Walsh, Conor <[email protected]>
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")

<snip>

usertools/dpdk-telemetry.py def print_socket_options(prefix, paths): · line 85

Quoted 4 lines
usertools/dpdk-telemetry.py +4 -0
+
+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.

usertools/dpdk-telemetry.py def print_socket_options(prefix, paths):

Quoted 13 lines
usertools/dpdk-telemetry.py +13 -0
+    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,

Thanks!

#2 lore raw

<snip>

Quoted 22 lines

usertools/dpdk-telemetry.py def print_socket_options(prefix, paths): · line 85

Quoted 5 lines
usertools/dpdk-telemetry.py +4 -0
+
+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.

usertools/dpdk-telemetry.py def print_socket_options(prefix, paths):

Quoted 13 lines
usertools/dpdk-telemetry.py +13 -0
+    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 +
+ "*")))
Quoted 7 lines

<snip>

Asides from that one small comment,

Thanks!

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

#3 lore raw

PATCH v2 1/1 usertools/telemetry: add list of available file-prefixes

In reply to Conor Walsh

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-19464 ("improve telemetry support with in-memory mode")

---
 usertools/dpdk-telemetry.py | 40 +++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
usertools/dpdk-telemetry.py +32 -8
index da3ba60430..d301511c7e 100755
@@ -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 """
+    path = get_dpdk_runtime_dir('')
+    sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
+    prefixes = []
+    if not sockets:
+        print("No DPDK apps with telemetry enabled available")
+    else:
+        print("Valid file-prefixes:\n")
+    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('/', ''))
@@ -147,7 +166,12 @@ def get_dpdk_runtime_dir(fp):
                     help='Provide file-prefix for DPDK runtime directory')
 parser.add_argument('-i', '--instance', default='0', type=int,
                     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')
 args = parser.parse_args()
+if args.list:
+    list_fp()
+    sys.exit(0)
 sock_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), SOCKET_NAME)
 if args.instance > 0:
     sock_path += ":{}".format(args.instance)
Signature · 1 line
2.25.1
#4 lore raw

Re: [dpdk-dev] [PATCH v2] usertools/telemetry: add list of available file-prefixes

<snip>

I forgot to include the changelog.

v2:
- Only print valid prefixes list header if telemetry available apps are available.
- Updated to v7 of the "improve telemetry support with in-memory mode" patchset.

Thanks,
Conor.

#5 lore raw

Re: [dpdk-dev] [PATCH v2] usertools/telemetry: add list of available file-prefixes

This patch is also compatible with the v8 of the "improve telemetry support with in-memory mode" patchset.

Thanks,
Conor.

Quoted 19 lines

-----Original Message-----
From: Walsh, Conor
Sent: Monday 11 October 2021 10:54
To: Power, Ciara <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2] usertools/telemetry: add list of available file-prefixes

<snip>

I forgot to include the changelog.

v2:
- Only print valid prefixes list header if telemetry available apps are available.
- Updated to v7 of the "improve telemetry support with in-memory mode"
patchset.

Thanks,
Conor.

#6 lore raw

Re: [dpdk-dev] [PATCH v2] usertools/telemetry: add list of available file-prefixes

Quoted 2 lines · Conor

This patch is also compatible with the v8 of the "improve telemetry support with in-memory mode" patchset.

Nice addition, can you add a description of this option in telemetry howto? Thanks.

Signature · 1 line
David Marchand
#7 lore raw

PATCH v3 1/1 usertools/telemetry: add list of available file-prefixes

In reply to Conor Walsh

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.

---

v3:
- Add note to docs about list option.
- Remove dependancy notice.

v2:
- Only print valid prefixes list header if telemetry available apps are available.
- Updated to v7 of the "improve telemetry support with in-memory mode" patchset.

---
 doc/guides/howto/telemetry.rst |  4 ++++
 usertools/dpdk-telemetry.py    | 40 +++++++++++++++++++++++++++-------
 2 files changed, 36 insertions(+), 8 deletions(-)
doc/guides/howto/telemetry.rst +4 -0
index b37dc0aab6..0464c431fe 100644
@@ -109,6 +109,10 @@ instances are run:
 
      $ ./usertools/dpdk-telemetry -f "tpmd"
 
+  To list all running telemetry-enabled file-prefixes, the ``-l`` or ``--list`` flags can be used::
+
+     $ ./usertools/dpdk-telemetry -l
+
 * For the case where multiple processes are run using the `--in-memory` EAL flag,
   but no `--file-prefix` flag, or the same `--file-prefix` flag,
   those processes will all share the same runtime directory.
usertools/dpdk-telemetry.py +32 -8
index 8f7d59d139..4d9f2d9787 100755
@@ -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 """
+    path = get_dpdk_runtime_dir('')
+    sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
+    prefixes = []
+    if not sockets:
+        print("No DPDK apps with telemetry enabled available")
+    else:
+        print("Valid file-prefixes:\n")
+    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('/', ''))
@@ -147,7 +166,12 @@ def get_dpdk_runtime_dir(fp):
                     help='Provide file-prefix for DPDK runtime directory')
 parser.add_argument('-i', '--instance', default='0', type=int,
                     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')
 args = parser.parse_args()
+if args.list:
+    list_fp()
+    sys.exit(0)
 sock_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), SOCKET_NAME)
 if args.instance > 0:
     sock_path += ":{}".format(args.instance)
Signature · 1 line
2.25.1
#8 lore raw

Re: [dpdk-dev] [PATCH v3] usertools/telemetry: add list of available file-prefixes

Quoted 8 lines · Conor Walsh

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.

Applied, thanks.

Signature · 1 line
David Marchand