DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Hunt <david.hunt@intel.com>
To: dev@dpdk.org
Cc: ciara.power@intel.com, David Hunt <david.hunt@intel.com>
Subject: [dpdk-dev] [PATCH v1] usertools/telemetry: add non-interactive mode
Date: Thu,  9 Sep 2021 16:56:25 +0100	[thread overview]
Message-ID: <20210909155625.24581-1-david.hunt@intel.com> (raw)

Add non-interactive mode to dpdk-telemetry.py so that a query string
can be supplied on the command line, and script dumps out data and
exits. Handing for calling from scripts.

Signed-off-by: David Hunt <david.hunt@intel.com>
---
 usertools/dpdk-telemetry.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index e04aa04702..5ce772d49d 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -48,7 +48,7 @@ def get_app_name(pid):
     return None
 
 
-def handle_socket(path):
+def handle_socket(path, query):
     """ Connect to socket and handle user input """
     sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
     global CMDS
@@ -69,13 +69,17 @@ def handle_socket(path):
     sock.send("/".encode())
     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)
+    if (query != ""):
+        sock.send(query.encode())
+        read_socket(sock, output_buf_len)
+    else:
+        # interactive prompt
         text = input('--> ').strip()
+        while text != "quit":
+            if text.startswith('/'):
+                sock.send(text.encode())
+                read_socket(sock, output_buf_len)
+            text = input('--> ').strip()
     sock.close()
 
 
@@ -104,6 +108,8 @@ def get_dpdk_runtime_dir(fp):
 parser = argparse.ArgumentParser()
 parser.add_argument('-f', '--file-prefix', \
         help='Provide file-prefix for DPDK runtime directory', default='rte')
+parser.add_argument('-q', '--query', \
+        help='run this query and exit', default='')
 args = parser.parse_args()
 rdir = get_dpdk_runtime_dir(args.file_prefix)
-handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
+handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)), args.query)
-- 
2.17.1


             reply	other threads:[~2021-09-09 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 15:56 David Hunt [this message]
2021-09-13 10:43 ` Bruce Richardson
2021-09-13 10:53   ` Bruce Richardson
2021-09-15 10:49     ` Power, Ciara
2021-09-15 10:58       ` David Hunt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210909155625.24581-1-david.hunt@intel.com \
    --to=david.hunt@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).