diff mbox series

[v3] usertools/telemetry: add list of available file-prefixes

Message ID 20211018100952.724933-1-conor.walsh@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers show
Series [v3] usertools/telemetry: add list of available file-prefixes | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-spell-check-testing warning Testing issues
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Conor Walsh Oct. 18, 2021, 10:09 a.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.

Signed-off-by: Conor Walsh <conor.walsh@intel.com>
Acked-by: Ciara Power <ciara.power@intel.com>

---

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(-)

Comments

David Marchand Oct. 19, 2021, 1:34 p.m. UTC | #1
On Mon, Oct 18, 2021 at 12:10 PM Conor Walsh <conor.walsh@intel.com> wrote:
>
> 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.
>
> Signed-off-by: Conor Walsh <conor.walsh@intel.com>
> Acked-by: Ciara Power <ciara.power@intel.com>

Applied, thanks.
diff mbox series

Patch

diff --git a/doc/guides/howto/telemetry.rst b/doc/guides/howto/telemetry.rst
index b37dc0aab6..0464c431fe 100644
--- a/doc/guides/howto/telemetry.rst
+++ b/doc/guides/howto/telemetry.rst
@@ -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.
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 8f7d59d139..4d9f2d9787 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 """
+    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)