scripts: runners: Renamed a bunch of flags
Mainly to make space for some planned bench flags, while also preferring "step" over "period" (for consistency), and "runfreq" over "freq" (to differentiate from "simfreq" in the future). In runners: - -s/--step -> --step - --trace-period -> --trace-step - --trace-freq -> --trace-runfreq In scripts: - --record -> -e/--record - --perf-period -> --perf-step - --perf-freq -> --perf-runfreq - --include -> -i/--include --- One thing that makes this work is the new sys.argv regex trick, where we try to predict what mode the script will run in by prematching known mode-switch flags before handing things off to argparse. Note: - Hiding flags from argparse risks confusing help-text, so we include all flags if we see -h/--help in sys.argv. This doesn't work for the help-text printed if argparse errors, but we can only do so much. Maybe argparse only showing relevant flags for the given mode is ok? - We use -[^-]*[hf].* for shortform flags, which should also match multiple shortform flags in a single arg (-fhfhfh). - This requires the conflict_handler='ignore' hack to work, but these scripts already needed it anyways.
This commit is contained in:
+42
-37
@@ -792,11 +792,11 @@ def find_runner(runner, id=None, main=True, **args):
|
||||
# run under perf?
|
||||
if args.get('perf'):
|
||||
cmd[:0] = args['perf_script'] + list(filter(None, [
|
||||
'--record',
|
||||
'--perf-freq=%s' % args['perf_freq']
|
||||
if args.get('perf_freq') else None,
|
||||
'--perf-period=%s' % args['perf_period']
|
||||
if args.get('perf_period') else None,
|
||||
'-e',
|
||||
'--perf-step=%s' % args['perf_step']
|
||||
if args.get('perf_step') else None,
|
||||
'--perf-runfreq=%s' % args['perf_runfreq']
|
||||
if args.get('perf_runfreq') else None,
|
||||
'--perf-events=%s' % args['perf_events']
|
||||
if args.get('perf_events') else None,
|
||||
'--perf-path=%s' % args['perf_path']
|
||||
@@ -822,10 +822,10 @@ def find_runner(runner, id=None, main=True, **args):
|
||||
cmd.append('-t%s' % args['trace'])
|
||||
if args.get('trace_backtrace'):
|
||||
cmd.append('--trace-backtrace')
|
||||
if args.get('trace_period'):
|
||||
cmd.append('--trace-period=%s' % args['trace_period'])
|
||||
if args.get('trace_freq'):
|
||||
cmd.append('--trace-freq=%s' % args['trace_freq'])
|
||||
if args.get('trace_step'):
|
||||
cmd.append('--trace-step=%s' % args['trace_step'])
|
||||
if args.get('trace_runfreq'):
|
||||
cmd.append('--trace-runfreq=%s' % args['trace_runfreq'])
|
||||
if args.get('read_sleep'):
|
||||
cmd.append('--read-sleep=%s' % args['read_sleep'])
|
||||
if args.get('prog_sleep'):
|
||||
@@ -1305,9 +1305,9 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
|
||||
while start < total_perms:
|
||||
runner_ = find_runner(runner, main=main, **args)
|
||||
if args.get('isolate') or args.get('valgrind'):
|
||||
runner_.append('-s%s,%s,%s' % (start, start+step, step))
|
||||
runner_.append('--step=%s,%s,%s' % (start, start+step, step))
|
||||
elif start != 0 or step != 1:
|
||||
runner_.append('-s%s,,%s' % (start, step))
|
||||
runner_.append('--step=%s,,%s' % (start, step))
|
||||
|
||||
runner_.extend(bench_ids)
|
||||
|
||||
@@ -1649,6 +1649,7 @@ def main(**args):
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
import re
|
||||
argparse.ArgumentParser._handle_conflict_ignore = lambda *_: None
|
||||
argparse._ArgumentGroup._handle_conflict_ignore = lambda *_: None
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -1743,10 +1744,10 @@ if __name__ == "__main__":
|
||||
action='store_true',
|
||||
help="Include a backtrace with every trace statement.")
|
||||
bench_parser.add_argument(
|
||||
'--trace-period',
|
||||
help="Sample trace output at this period in cycles.")
|
||||
'--trace-step',
|
||||
help="Sample trace output every n steps.")
|
||||
bench_parser.add_argument(
|
||||
'--trace-freq',
|
||||
'--trace-runfreq',
|
||||
help="Sample trace output at this frequency in hz.")
|
||||
bench_parser.add_argument(
|
||||
'-O', '--stdout',
|
||||
@@ -1847,13 +1848,13 @@ if __name__ == "__main__":
|
||||
help="Run under Linux's perf to sample performance counters, "
|
||||
"writing samples to this file.")
|
||||
bench_parser.add_argument(
|
||||
'--perf-freq',
|
||||
'--perf-step',
|
||||
help="perf sampling step. This is passed directly to the perf "
|
||||
"script.")
|
||||
bench_parser.add_argument(
|
||||
'--perf-runfreq',
|
||||
help="perf sampling frequency. This is passed directly to the "
|
||||
"perf script.")
|
||||
bench_parser.add_argument(
|
||||
'--perf-period',
|
||||
help="perf sampling period. This is passed directly to the perf "
|
||||
"script.")
|
||||
bench_parser.add_argument(
|
||||
'--perf-events',
|
||||
help="perf events to record. This is passed directly to the perf "
|
||||
@@ -1880,27 +1881,31 @@ if __name__ == "__main__":
|
||||
'-c', '--compile',
|
||||
action='store_true',
|
||||
help="Compile a bench suite or source file.")
|
||||
comp_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file.")
|
||||
comp_parser.add_argument(
|
||||
'-s', '--source',
|
||||
help="Source file to compile, possibly injecting internal benches.")
|
||||
comp_parser.add_argument(
|
||||
'--include',
|
||||
help="Inject these header files into every compiled bench file. "
|
||||
"Defaults to %r." % HEADER_PATHS)
|
||||
comp_parser.add_argument(
|
||||
'--no-internal',
|
||||
action='store_true',
|
||||
help="Don't build internal benches.")
|
||||
comp_parser.add_argument(
|
||||
'--no-litmus',
|
||||
action='store_true',
|
||||
help="Don't build litmus benches.")
|
||||
if any(re.fullmatch('-[^-]*[hc].*|--help|--compile', a) for a in sys.argv):
|
||||
comp_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file.")
|
||||
comp_parser.add_argument(
|
||||
'-s', '--source',
|
||||
help="Source file to compile, possibly injecting internal "
|
||||
"benches.")
|
||||
comp_parser.add_argument(
|
||||
'-i', '--include',
|
||||
action='append',
|
||||
help="Inject these header files into every compiled bench "
|
||||
"file. Defaults to %r." % HEADER_PATHS)
|
||||
comp_parser.add_argument(
|
||||
'--no-internal',
|
||||
action='store_true',
|
||||
help="Don't build internal benches.")
|
||||
comp_parser.add_argument(
|
||||
'--no-litmus',
|
||||
action='store_true',
|
||||
help="Don't build litmus benches.")
|
||||
|
||||
# do the thing
|
||||
args = parser.parse_intermixed_args()
|
||||
# bench_paths/bench_ids overlap, so need to do some munging
|
||||
args.bench_paths = args.bench_ids
|
||||
sys.exit(main(**{k: v
|
||||
for k, v in vars(args).items()
|
||||
|
||||
+34
-32
@@ -3,7 +3,7 @@
|
||||
# Script to aggregate and report Linux perf results.
|
||||
#
|
||||
# Example:
|
||||
# ./scripts/perf.py --record -obench.perf ./runners/bench_runner
|
||||
# ./scripts/perf.py -e -obench.perf ./runners/bench_runner
|
||||
# ./scripts/perf.py bench.perf -j -Flfs.c -Flfs_util.c -Scycles
|
||||
#
|
||||
# Copyright (c) 2022, The littlefs authors.
|
||||
@@ -39,7 +39,7 @@ import zipfile
|
||||
|
||||
PERF_PATH = ['perf']
|
||||
PERF_EVENTS = 'cycles,branch-misses,branches,cache-misses,cache-references'
|
||||
PERF_FREQ = 100
|
||||
PERF_RUNFREQ = 100
|
||||
OBJDUMP_PATH = ['objdump']
|
||||
THRESHOLD = (0.5, 0.85)
|
||||
|
||||
@@ -202,8 +202,8 @@ def openio(path, mode='r', buffering=-1):
|
||||
# run perf as a subprocess, storing measurements into a zip file
|
||||
def record(command, *,
|
||||
output=None,
|
||||
perf_freq=PERF_FREQ,
|
||||
perf_period=None,
|
||||
perf_step=None,
|
||||
perf_runfreq=PERF_RUNFREQ,
|
||||
perf_events=PERF_EVENTS,
|
||||
perf_path=PERF_PATH,
|
||||
**args):
|
||||
@@ -213,11 +213,11 @@ def record(command, *,
|
||||
# figure out our perf invocation
|
||||
perf = perf_path + list(filter(None, [
|
||||
'record',
|
||||
'-F%s' % perf_freq
|
||||
if perf_freq is not None
|
||||
and perf_period is None else None,
|
||||
'-c%s' % perf_period
|
||||
if perf_period is not None else None,
|
||||
'-c%s' % perf_step
|
||||
if perf_step is not None else None,
|
||||
'-F%s' % perf_runfreq
|
||||
if perf_runfreq is not None
|
||||
and perf_step is None else None,
|
||||
'-B',
|
||||
'-g',
|
||||
'--all-user',
|
||||
@@ -1660,11 +1660,12 @@ def main(**args):
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
import re
|
||||
|
||||
# bit of a hack, but parse_intermixed_args and REMAINDER are
|
||||
# incompatible, so we need to figure out what we want before running
|
||||
# argparse
|
||||
if '--record' in sys.argv:
|
||||
if any(re.fullmatch('-[^-]*[e].*|--record', a) for a in sys.argv):
|
||||
nargs = argparse.REMAINDER
|
||||
else:
|
||||
nargs = '*'
|
||||
@@ -1900,29 +1901,30 @@ if __name__ == "__main__":
|
||||
nargs=nargs,
|
||||
help="Command to run.")
|
||||
record_parser.add_argument(
|
||||
'--record',
|
||||
'-e', '--record',
|
||||
action='store_true',
|
||||
help="Run a command and aggregate perf measurements.")
|
||||
record_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file. Uses flock to synchronize. This is stored as a "
|
||||
"zip-file of multiple perf results.")
|
||||
record_parser.add_argument(
|
||||
'--perf-freq',
|
||||
help="perf sampling frequency. This is passed directly to perf. "
|
||||
"Defaults to %r." % PERF_FREQ)
|
||||
record_parser.add_argument(
|
||||
'--perf-period',
|
||||
help="perf sampling period. This is passed directly to perf.")
|
||||
record_parser.add_argument(
|
||||
'--perf-events',
|
||||
help="perf events to record. This is passed directly to perf. "
|
||||
"Defaults to %r." % PERF_EVENTS)
|
||||
record_parser.add_argument(
|
||||
'--perf-path',
|
||||
type=lambda x: x.split(),
|
||||
help="Path to the perf executable, may include flags. "
|
||||
"Defaults to %r." % PERF_PATH)
|
||||
if any(re.fullmatch('-[^-]*[he].*|--help|--record', a) for a in sys.argv):
|
||||
record_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file. Uses flock to synchronize. This is stored "
|
||||
"as a zip-file of multiple perf results.")
|
||||
record_parser.add_argument(
|
||||
'--perf-step',
|
||||
help="perf sampling step. This is passed directly to perf.")
|
||||
record_parser.add_argument(
|
||||
'--perf-runfreq',
|
||||
help="perf sampling frequency. This is passed directly to "
|
||||
"perf. Defaults to %r." % PERF_RUNFREQ)
|
||||
record_parser.add_argument(
|
||||
'--perf-events',
|
||||
help="perf events to record. This is passed directly to "
|
||||
"perf. Defaults to %r." % PERF_EVENTS)
|
||||
record_parser.add_argument(
|
||||
'--perf-path',
|
||||
type=lambda x: x.split(),
|
||||
help="Path to the perf executable, may include flags. "
|
||||
"Defaults to %r." % PERF_PATH)
|
||||
|
||||
# avoid intermixed/REMAINDER conflict, see above
|
||||
if nargs == argparse.REMAINDER:
|
||||
@@ -1930,7 +1932,7 @@ if __name__ == "__main__":
|
||||
else:
|
||||
args = parser.parse_intermixed_args()
|
||||
|
||||
# perf_paths/command overlap, so need to do some munging here
|
||||
# perf_paths/command overlap, so need to do some munging
|
||||
args.command = args.perf_paths
|
||||
if args.record:
|
||||
if not args.command:
|
||||
|
||||
+45
-41
@@ -805,11 +805,11 @@ def find_runner(runner, id=None, main=True, **args):
|
||||
# run under perf?
|
||||
if args.get('perf'):
|
||||
cmd[:0] = args['perf_script'] + list(filter(None, [
|
||||
'--record',
|
||||
'--perf-freq=%s' % args['perf_freq']
|
||||
if args.get('perf_freq') else None,
|
||||
'--perf-period=%s' % args['perf_period']
|
||||
if args.get('perf_period') else None,
|
||||
'-e',
|
||||
'--perf-step=%s' % args['perf_step']
|
||||
if args.get('perf_step') else None,
|
||||
'--perf-runfreq=%s' % args['perf_runfreq']
|
||||
if args.get('perf_runfreq') else None,
|
||||
'--perf-events=%s' % args['perf_events']
|
||||
if args.get('perf_events') else None,
|
||||
'--perf-path=%s' % args['perf_path']
|
||||
@@ -839,10 +839,10 @@ def find_runner(runner, id=None, main=True, **args):
|
||||
cmd.append('-t%s' % args['trace'])
|
||||
if args.get('trace_backtrace'):
|
||||
cmd.append('--trace-backtrace')
|
||||
if args.get('trace_period'):
|
||||
cmd.append('--trace-period=%s' % args['trace_period'])
|
||||
if args.get('trace_freq'):
|
||||
cmd.append('--trace-freq=%s' % args['trace_freq'])
|
||||
if args.get('trace_step'):
|
||||
cmd.append('--trace-step=%s' % args['trace_step'])
|
||||
if args.get('trace_runfreq'):
|
||||
cmd.append('--trace-runfreq=%s' % args['trace_runfreq'])
|
||||
if args.get('read_sleep'):
|
||||
cmd.append('--read-sleep=%s' % args['read_sleep'])
|
||||
if args.get('prog_sleep'):
|
||||
@@ -1269,9 +1269,9 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args):
|
||||
while start < total_perms:
|
||||
runner_ = find_runner(runner, main=main, **args)
|
||||
if args.get('isolate') or args.get('valgrind'):
|
||||
runner_.append('-s%s,%s,%s' % (start, start+step, step))
|
||||
runner_.append('--step=%s,%s,%s' % (start, start+step, step))
|
||||
elif start != 0 or step != 1:
|
||||
runner_.append('-s%s,,%s' % (start, step))
|
||||
runner_.append('--step=%s,,%s' % (start, step))
|
||||
|
||||
runner_.extend(test_ids)
|
||||
|
||||
@@ -1655,6 +1655,7 @@ def main(**args):
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
import re
|
||||
argparse.ArgumentParser._handle_conflict_ignore = lambda *_: None
|
||||
argparse._ArgumentGroup._handle_conflict_ignore = lambda *_: None
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -1760,10 +1761,10 @@ if __name__ == "__main__":
|
||||
action='store_true',
|
||||
help="Include a backtrace with every trace statement.")
|
||||
test_parser.add_argument(
|
||||
'--trace-period',
|
||||
help="Sample trace output at this period in cycles.")
|
||||
'--trace-step',
|
||||
help="Sample trace output every n steps.")
|
||||
test_parser.add_argument(
|
||||
'--trace-freq',
|
||||
'--trace-runfreq',
|
||||
help="Sample trace output at this frequency in hz.")
|
||||
test_parser.add_argument(
|
||||
'-O', '--stdout',
|
||||
@@ -1876,13 +1877,13 @@ if __name__ == "__main__":
|
||||
help="Run under Linux's perf to sample performance counters, "
|
||||
"writing samples to this file.")
|
||||
test_parser.add_argument(
|
||||
'--perf-freq',
|
||||
'--perf-step',
|
||||
help="perf sampling step. This is passed directly to the perf "
|
||||
"script.")
|
||||
test_parser.add_argument(
|
||||
'--perf-runfreq',
|
||||
help="perf sampling frequency. This is passed directly to the "
|
||||
"perf script.")
|
||||
test_parser.add_argument(
|
||||
'--perf-period',
|
||||
help="perf sampling period. This is passed directly to the perf "
|
||||
"script.")
|
||||
test_parser.add_argument(
|
||||
'--perf-events',
|
||||
help="perf events to record. This is passed directly to the perf "
|
||||
@@ -1909,31 +1910,34 @@ if __name__ == "__main__":
|
||||
'-c', '--compile',
|
||||
action='store_true',
|
||||
help="Compile a test suite or source file.")
|
||||
comp_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file.")
|
||||
comp_parser.add_argument(
|
||||
'-s', '--source',
|
||||
help="Source file to compile, possibly injecting internal tests.")
|
||||
comp_parser.add_argument(
|
||||
'--include',
|
||||
help="Inject these header files into every compiled test file. "
|
||||
"Defaults to %r." % HEADER_PATHS)
|
||||
comp_parser.add_argument(
|
||||
'--no-internal',
|
||||
action='store_true',
|
||||
help="Don't build internal tests.")
|
||||
comp_parser.add_argument(
|
||||
'--no-reentrant',
|
||||
action='store_true',
|
||||
help="Don't build reentrant tests.")
|
||||
comp_parser.add_argument(
|
||||
'--no-fuzz',
|
||||
action='store_true',
|
||||
help="Don't build fuzz tests.")
|
||||
if any(re.fullmatch('-[^-]*[hc].*|--help|--compile', a) for a in sys.argv):
|
||||
comp_parser.add_argument(
|
||||
'-o', '--output',
|
||||
help="Output file.")
|
||||
comp_parser.add_argument(
|
||||
'-s', '--source',
|
||||
help="Source file to compile, possibly injecting internal "
|
||||
"tests.")
|
||||
comp_parser.add_argument(
|
||||
'-i', '--include',
|
||||
help="Inject these header files into every compiled test "
|
||||
"file. Defaults to %r." % HEADER_PATHS)
|
||||
comp_parser.add_argument(
|
||||
'--no-internal',
|
||||
action='store_true',
|
||||
help="Don't build internal tests.")
|
||||
comp_parser.add_argument(
|
||||
'--no-reentrant',
|
||||
action='store_true',
|
||||
help="Don't build reentrant tests.")
|
||||
comp_parser.add_argument(
|
||||
'--no-fuzz',
|
||||
action='store_true',
|
||||
help="Don't build fuzz tests.")
|
||||
|
||||
# do the thing
|
||||
args = parser.parse_intermixed_args()
|
||||
# test_paths/test_ids overlap, so need to do some munging
|
||||
args.test_paths = args.test_ids
|
||||
sys.exit(main(**{k: v
|
||||
for k, v in vars(args).items()
|
||||
|
||||
Reference in New Issue
Block a user