From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 2/2] usertools/telemetry: support using aliases for long commands
Date: Thu, 21 May 2026 16:39:13 +0100 [thread overview]
Message-ID: <20260521153913.82634-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260521153913.82634-1-bruce.richardson@intel.com>
Similarly to how shell aliases work, allow specifying of short alias
commands for dpdk-telemetry.py script. The aliases are read from
"$HOME/.dpdk_telemetry_aliases" at startup.
Some examples of use from the docs. Alias file contents:
# Basic shortcuts
ls=/ethdev/list
names=FOREACH i /ethdev/list /ethdev/info,$i .name
q=quit
Alias use:
--> ls
{"/ethdev/list": [0, 1]}
--> names
[{"i": 0, "name": "0000:
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
doc/guides/howto/telemetry.rst | 34 +++++++++++++++
usertools/dpdk-telemetry.py | 75 ++++++++++++++++++++++++++++++++--
2 files changed, 105 insertions(+), 4 deletions(-)
diff --git a/doc/guides/howto/telemetry.rst b/doc/guides/howto/telemetry.rst
index 4bf48c635e..072289aec8 100644
--- a/doc/guides/howto/telemetry.rst
+++ b/doc/guides/howto/telemetry.rst
@@ -130,6 +130,40 @@ and query information using the telemetry client python script.
- With loop variable: returns an array of objects containing the loop
variable field and requested value fields.
+ * Use command aliases.
+
+ The telemetry script can load aliases at startup from::
+
+ $HOME/.dpdk_telemetry_aliases
+
+ Each alias entry must be in ``alias=command`` format.
+ Empty lines and lines starting with ``#`` are ignored.
+
+ Example alias file::
+
+ # Basic shortcuts
+ ls=/ethdev/list
+ names=FOREACH i /ethdev/list /ethdev/info,$i .name
+ q=quit
+
+ Alias behavior is intentionally similar to shell aliases:
+
+ - The first token of the entered input is checked for an alias match.
+ - If matched, that first token is replaced with its expansion.
+ - Alias expansion is recursive (aliases can expand to other aliases).
+ - Expansion has a safety limit to prevent infinite loops.
+
+ Examples::
+
+ --> ls
+ {"/ethdev/list": [0, 1]}
+
+ --> names
+ [{"i": 0, "name": "0000:16:00.0"}, {"i": 1, "name": "0000:16:00.1"}]
+
+ --> q
+ # exits the client
+
Connecting to Different DPDK Processes
--------------------------------------
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 2de10cff69..8b976160e0 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -21,6 +21,70 @@
SOCKET_NAME = "dpdk_telemetry.{}".format(TELEMETRY_VERSION)
DEFAULT_PREFIX = "rte"
CMDS = []
+ALIASES = {}
+ALIAS_FILE = ".dpdk_telemetry_aliases"
+MAX_ALIAS_EXPANSIONS = 32
+
+
+def load_aliases():
+ """Load aliases from $HOME/.dpdk_telemetry_aliases"""
+ aliases = {}
+ home = os.environ.get("HOME")
+ if not home:
+ return aliases
+
+ alias_path = os.path.join(home, ALIAS_FILE)
+ if not os.path.isfile(alias_path):
+ return aliases
+
+ try:
+ with open(alias_path) as alias_file:
+ for line_num, line in enumerate(alias_file, start=1):
+ entry = line.strip()
+ if not entry or entry.startswith("#"):
+ continue
+ if "=" not in entry:
+ print(
+ "Warning: ignoring malformed alias at {}:{}".format(alias_path, line_num),
+ file=sys.stderr,
+ )
+ continue
+ name, command = entry.split("=", 1)
+ name = name.strip()
+ command = command.strip()
+ if not name or not command:
+ print(
+ "Warning: ignoring malformed alias at {}:{}".format(alias_path, line_num),
+ file=sys.stderr,
+ )
+ continue
+ aliases[name] = command
+ except OSError as e:
+ print("Warning: failed to read {}: {}".format(alias_path, e), file=sys.stderr)
+
+ return aliases
+
+
+def expand_aliases(text, aliases):
+ """Expand aliases similarly to shell aliases on the first token"""
+ expanded = text
+ for _ in range(MAX_ALIAS_EXPANSIONS):
+ stripped = expanded.lstrip()
+ if not stripped:
+ return expanded
+
+ parts = stripped.split(None, 1)
+ first = parts[0]
+ rest = parts[1] if len(parts) > 1 else ""
+
+ if first not in aliases:
+ return expanded
+
+ alias_value = aliases[first]
+ expanded = "{} {}".format(alias_value, rest).strip() if rest else alias_value
+
+ print("Warning: alias expansion limit reached", file=sys.stderr)
+ return expanded
def send_command(sock, cmd, output_buf_len, echo=False, pretty=False):
@@ -262,10 +326,12 @@ def handle_socket(args, path):
# interactive prompt
try:
- text = input(prompt).strip()
- while text != "quit":
- handle_command(sock, output_buf_len, text, pretty=prompt)
+ while True:
text = input(prompt).strip()
+ expanded = expand_aliases(text, ALIASES)
+ if expanded == "quit":
+ break
+ handle_command(sock, output_buf_len, expanded, pretty=prompt)
except EOFError:
pass
finally:
@@ -274,7 +340,7 @@ def handle_socket(args, path):
def readline_complete(text, state):
"""Find any matching commands from the list based on user input"""
- all_cmds = ["quit"] + CMDS
+ all_cmds = ["quit"] + list(ALIASES.keys()) + CMDS
if text:
matches = [c for c in all_cmds if c.startswith(text)]
else:
@@ -304,6 +370,7 @@ def readline_complete(text, state):
help="List all possible file-prefixes and exit",
)
args = parser.parse_args()
+ALIASES = load_aliases()
if args.list:
list_fp()
sys.exit(0)
--
2.53.0
next prev parent reply other threads:[~2026-05-21 15:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 15:39 [PATCH 0/2] extend interactive telemetry script Bruce Richardson
2026-05-21 15:39 ` [PATCH 1/2] usertools/telemetry: add a FOREACH command Bruce Richardson
2026-05-21 15:39 ` Bruce Richardson [this message]
2026-05-22 0:44 ` [PATCH 0/2] extend interactive telemetry script fengchengwen
2026-05-22 7:51 ` Bruce Richardson
2026-05-22 13:37 ` [PATCH v2 0/3] " Bruce Richardson
2026-05-22 13:37 ` [PATCH v2 1/3] usertools/telemetry: add a FOREACH command Bruce Richardson
2026-05-29 0:17 ` fengchengwen
2026-05-22 13:37 ` [PATCH v2 2/3] usertools/telemetry: support using aliases for long commands Bruce Richardson
2026-05-29 0:25 ` fengchengwen
2026-05-22 13:37 ` [PATCH v2 3/3] usertools/telemetry: add help support Bruce Richardson
2026-05-29 0:27 ` fengchengwen
2026-06-09 16:13 ` [PATCH v3 0/3] extend interactive telemetry script Bruce Richardson
2026-06-09 16:13 ` [PATCH v3 1/3] usertools/telemetry: add a FOREACH command Bruce Richardson
2026-06-09 16:13 ` [PATCH v3 2/3] usertools/telemetry: support using aliases for long commands Bruce Richardson
2026-06-09 16:14 ` [PATCH v3 3/3] usertools/telemetry: add help support Bruce Richardson
2026-06-09 16:17 ` Bruce Richardson
2026-06-10 1:39 ` [PATCH v3 0/3] extend interactive telemetry script fengchengwen
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=20260521153913.82634-3-bruce.richardson@intel.com \
--to=bruce.richardson@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