From 93c85870e8386b283c21170ea0bf545aef3748de Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 12 Feb 2026 19:13:53 -0600 Subject: [PATCH] scripts: Added -Q/--query as alternative to --total This better matches the runners' new -Q/--query-define flag, and, thanks to some argparse trickery, is simpler implementation wise. Example: $ ./scripts/code.py lfs3.o -Qsize 66570 $ ./scripts/stack.py -Qlimit lfs3.ci 3312 The only downside is this takes the --small-table shortform flag, but --small-table doesn't really need a shortform flag. --- Makefile | 2 +- scripts/code.py | 45 ++++++++++++++++++++++++++---------------- scripts/cov.py | 45 ++++++++++++++++++++++++++---------------- scripts/csv.py | 49 ++++++++++++++++++++++++++++++---------------- scripts/ctx.py | 45 ++++++++++++++++++++++++++---------------- scripts/data.py | 45 ++++++++++++++++++++++++++---------------- scripts/perf.py | 45 ++++++++++++++++++++++++++---------------- scripts/perfbd.py | 45 ++++++++++++++++++++++++++---------------- scripts/stack.py | 45 ++++++++++++++++++++++++++---------------- scripts/structs.py | 45 ++++++++++++++++++++++++++---------------- 10 files changed, 257 insertions(+), 154 deletions(-) diff --git a/Makefile b/Makefile index a4469bc5..4d3c95e9 100644 --- a/Makefile +++ b/Makefile @@ -486,7 +486,7 @@ summary-diff sizes-diff: $(OBJ) $(CI) -fstack='max(stack_limit)' \ -fctx='max(ctx_size)' \ -o-) \ - -bbuild -CBEFORE -Q $(SUMMARYFLAGS)) + -bbuild -CBEFORE --small-table $(SUMMARYFLAGS)) ## Generate a codemap svg diff --git a/scripts/code.py b/scripts/code.py index 4eee5950..9429b268 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -620,26 +620,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1188,6 +1176,20 @@ if __name__ == "__main__": action='append', choices=CodeResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=CodeResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1241,17 +1243,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/cov.py b/scripts/cov.py index 7ed59e57..ba28fbc4 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -489,26 +489,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1167,6 +1155,20 @@ if __name__ == "__main__": action='append', choices=CovResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=CovResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1220,17 +1222,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/csv.py b/scripts/csv.py index e9aba0f2..21e34ad1 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -2264,26 +2264,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -3326,6 +3314,24 @@ if __name__ == "__main__": )(*x.split('=', 1)), help="Like -f/--field, but hidden from the table renderer, " "and doesn't affect -f/--field defaults.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append((value, False)) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + type=lambda x: ( + lambda k, v=None: ( + k.strip(), + CsvExpr(v) if v is not None else None) + )(*x.split('=', 1)), + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -3458,17 +3464,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/ctx.py b/scripts/ctx.py index 201b783a..88bf5639 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -879,26 +879,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1483,6 +1471,20 @@ if __name__ == "__main__": action='append', choices=CtxResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=CtxResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1559,17 +1561,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/data.py b/scripts/data.py index 797256d4..ad146b26 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -620,26 +620,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1188,6 +1176,20 @@ if __name__ == "__main__": action='append', choices=DataResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=DataResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1241,17 +1243,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/perf.py b/scripts/perf.py index e1a677cd..5c55849a 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -978,26 +978,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1728,6 +1716,20 @@ if __name__ == "__main__": action='append', choices=PerfResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=PerfResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1809,17 +1811,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/perfbd.py b/scripts/perfbd.py index d9d03827..a555ccea 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -952,26 +952,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1728,6 +1716,20 @@ if __name__ == "__main__": action='append', choices=PerfBdResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=PerfBdResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1809,17 +1811,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/stack.py b/scripts/stack.py index 1d95852d..7620316f 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -620,26 +620,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1226,6 +1214,20 @@ if __name__ == "__main__": action='append', choices=StackResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=StackResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1302,17 +1304,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument( diff --git a/scripts/structs.py b/scripts/structs.py index ad01fa71..50e35ff6 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -768,26 +768,14 @@ def table(Result, results, diff_results=None, *, small_header=False, no_total=False, small_total=False, - small_table=False, summary=False, - total=False, **_): import builtins all_, all = all, builtins.all - # small_table implies small_header + no_total or small_total - if small_table: - small_header = True - small_total = True - no_total = no_total or (not summary and not total) # summary implies small_header if summary: small_header = True - # total implies summary + no_header + small_total - if total: - summary = True - no_header = True - small_total = True if by is None: by = Result._by @@ -1372,6 +1360,20 @@ if __name__ == "__main__": action='append', choices=StructResult._fields, help="Show this field.") + class AppendQuery(argparse.Action): + def __call__(self, parser, namespace, value, option): + if namespace.fields is None: + namespace.fields = [] + namespace.fields.append(value) + namespace.summary = True + namespace.no_header = True + namespace.small_total = True + parser.add_argument( + '-Q', '--query', + action=AppendQuery, + choices=StructResult._fields, + help="Like -f/--field, but also implies --total. Useful for " + "scripting.") parser.add_argument( '-D', '--define', dest='defines', @@ -1448,17 +1450,26 @@ if __name__ == "__main__": '--small-total', action='store_true', help="Don't show TOTAL name.") + class StoreSmallTable(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.small_header = True + namespace.no_total = True parser.add_argument( - '-Q', '--small-table', - action='store_true', - help="Equivalent to --small-header + --no-total or --small-total.") + '--small-table', + action=StoreSmallTable, + help="Equivalent to --small-header + --no-total.") parser.add_argument( '-Y', '--summary', action='store_true', help="Only show the total.") + class StoreTotal(argparse._StoreTrueAction): + def __call__(self, parser, namespace, value, option): + namespace.summary = True + namespace.no_header = True + namespace.small_total = True parser.add_argument( - '-t', '--total', - action='store_true', + '--total', + action=StoreTotal, help="Equivalent to --summary + --no-header + --small-total. " "Useful for scripting.") parser.add_argument(