[PATCH 02/36] tuna: Suppress output when pattern matches zero results

John Kacur <[email protected]> Fri, 10 Jul 2026 10:14:40 -0400
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
When a user-specified pattern matches nothing, showing empty column
headers is redundant after already displaying the warning message.

Suppress the display output entirely for show_threads and show_irqs
commands when patterns match zero results. The warning message to
stderr provides sufficient feedback to the user.

Example:
  $ tuna show_threads -t 'foo*'
  tuna: warning: thread pattern matched 0 threads
  (no headers or empty output displayed)

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: John Kacur <[email protected]>
---
 tuna-cmd.py | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/tuna-cmd.py b/tuna-cmd.py
index 015bb7a54663..d9d1eaa83757 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -746,11 +746,31 @@ def main():
         list_config()
 
     elif args.command in ['show_threads']:
-        do_ps(args.thread_list, args.cpu_list, args.irq_list, args.uthreads,
-                args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups, args.compact, match_requested)
+        # Skip display if pattern matched nothing (warning already shown)
+        has_content = False
+        if match_requested:
+            if 'thread_list' in vars(args) and isinstance(args.thread_list, list) and args.thread_list:
+                has_content = True
+            if 'irq_list' in vars(args) and isinstance(args.irq_list, list) and args.irq_list:
+                has_content = True
+        else:
+            has_content = True  # No filtering, will show content
+
+        if has_content:
+            do_ps(args.thread_list, args.cpu_list, args.irq_list, args.uthreads,
+                    args.kthreads, args.affect_children, args.show_sockets if "show_sockets" in args else None, args.cgroups, args.compact, match_requested)
 
     elif args.command in ['show_irqs']:
-        show_irqs(args.irq_list, args.cpu_list, match_requested)
+        # Skip display if pattern matched nothing (warning already shown)
+        has_content = False
+        if match_requested:
+            if 'irq_list' in vars(args) and isinstance(args.irq_list, list) and args.irq_list:
+                has_content = True
+        else:
+            has_content = True  # No filtering, will show content
+
+        if has_content:
+            show_irqs(args.irq_list, args.cpu_list, match_requested)
 
     elif args.command in ['move', 'm', 'spread', 'x']:
         spread = args.command in ['spread', 'x']
-- 
2.54.0