[PATCH 03/36] tuna: Make warnings opt-in with -w/--warn flag

John Kacur <[email protected]> Fri, 10 Jul 2026 10:14:41 -0400
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
Change warnings from automatic to opt-in behavior. Users must now
specify -w or --warn to see warning messages when patterns match
nothing. This keeps output clean for shell scripts and command chaining.

Also adopt rteval-style [WARNING] prefix format instead of
"tuna: warning:" for consistency with other realtime tools.

Examples:
  $ tuna show_threads -t 'foo*'
  (silent - no output)

  $ tuna -w show_threads -t 'foo*'
  [WARNING] thread pattern matched 0 threads

This allows shell chaining without warning noise while still
providing feedback when users want it.

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

diff --git a/tuna-cmd.py b/tuna-cmd.py
index d9d1eaa83757..c4bd55fac3df 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -97,6 +97,7 @@ def gen_parser():
             "logging": dict(dest='loglevel', metavar='LOG-LEVEL', type=get_loglevel, help="Log application details to file for given LOG-LEVEL"),
             "debug" : dict(action='store_true', dest='debug', help='Print DEBUG level logging details to console'),
             "version": dict(action='version', version='0.20', help="show version"),
+            "warn": dict(action='store_true', dest='warn', help='Warn when thread/IRQ patterns match nothing'),
             "threads": dict(dest='thread_list', default='', metavar='THREAD-LIST', type=str, help="THREAD-LIST affected by commands"),
             "irqs": dict(dest='irq_list', default='', metavar='IRQ-LIST', type=str, help="IRQ-LIST affect by commands"),
             "cpus": dict(dest='cpu_list', default=[], metavar='CPU-LIST', type=tuna.cpustring_to_list, help='CPU-LIST affected by commands'),
@@ -124,6 +125,7 @@ def gen_parser():
     parser.add_argument('-v', '--version', **MODS['version'])
     parser.add_argument('-L', '--logging', **MODS['logging'])
     parser.add_argument('-D', '--debug', **MODS['debug'])
+    parser.add_argument('-w', '--warn', **MODS['warn'])
 
     subparser = parser.add_subparsers(dest='command')
 
@@ -712,14 +714,14 @@ def main():
     if 'nohz_full' in vars(args) and args.nohz_full:
         args.cpu_list = nohz_full_to_cpu()
 
-    # Warn if user-specified patterns matched nothing
-    if match_requested:
+    # Warn if user-specified patterns matched nothing (only if --warn)
+    if match_requested and args.warn:
         if args.command in ['show_threads', 'move', 'm', 'spread', 'x', 'priority', 'p', 'what_is', 'W']:
             if 'thread_list' in vars(args) and isinstance(args.thread_list, list) and not args.thread_list:
-                print("tuna: warning: thread pattern matched 0 threads", file=sys.stderr)
+                print("[WARNING] thread pattern matched 0 threads", file=sys.stderr)
         if args.command in ['show_irqs', 'move', 'm', 'spread', 'x']:
             if 'irq_list' in vars(args) and isinstance(args.irq_list, list) and not args.irq_list:
-                print("tuna: warning: IRQ pattern matched 0 IRQs", file=sys.stderr)
+                print("[WARNING] IRQ pattern matched 0 IRQs", file=sys.stderr)
 
     # if args.command in ['apply', 'a']:
     #     apply_config(args.profilename)
-- 
2.54.0