runners: bench: Added flags to control reading from bench probes

- -S/--probe         - Specify a probe to sample.
- -x/--probe-step    - Sample probes every n steps.
- --probe-runfreq    - Sample probes at this frequency in hz.
- -X/--probe-simfreq - Sample probes at this frequency in simulated hz.

Also:

- --trace-simfreq    - Sample trace output at this frequency in
                       simulated hz.

These give finer grain control over which probes we measure during
benching, and how we measure them.

These also introduce several exciting bench features:

- -S/--probe provides the ability to easily filter which probes you're
  interested in at runtime.

  This should replace the growing use of MASK defines in the benches.

- -x/--probe-step makes it easy to relax sampling rate when the amount
  of data overwhelms later scripts.

  This should replace the growing use of STEP defines in the benches.

- The additional concept of simfreq, which allows perf-esque sampling in
  simtime. This provides another option for intuitively relaxing probe
  sampling rate without sacrificing reproducibility.

  (runfreq depends on wall time, so good bye reproducibility, though may
  still be useful in interactive contexts.)

Note -S/--probe and -x/--probe-step replace MASK/STEP defines, which
have already proved their usefulness, but required reimplementation in
every bench case. An obvious contender to move into the bench_runner!

---

Note note that -S/--probe also supports some simple sample expressions,
allowing flexible step/simfreq/runfreq at the per-probe level:

- -Swrite=100    - Sample probe "write" every 100 steps
- -Swrite=100rhz - Sample probe "write" 100 times a runtime second
- -Swrite=100shz - Sample probe "write" 100 times a simulated second

Though I wonder how long it will take before I forget this feature
exists.
This commit is contained in:
Christopher Haster
2026-02-09 13:43:55 -06:00
parent 81d681cab2
commit 4af4cf3212
8 changed files with 773 additions and 378 deletions
+28 -3
View File
@@ -822,6 +822,15 @@ def find_runner(runner, id=None, main=True, **args):
# other context
if args.get('define_depth'):
cmd.append('--define-depth=%s' % args['define_depth'])
if args.get('probe'):
for probe in args['probe']:
cmd.append('-S%s' % probe)
if args.get('probe_step'):
cmd.append('-x%s' % args['probe_step'])
if args.get('probe_runfreq'):
cmd.append('--probe-runfreq=%s' % args['probe_runfreq'])
if args.get('probe_simfreq'):
cmd.append('-X%s' % args['probe_simfreq'])
if args.get('force'):
cmd.append('--force')
if args.get('no_internal'):
@@ -1203,7 +1212,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
last_defines = None # fetched on demand
last_stdout = co.deque(maxlen=args.get('context', 5) + 1)
last_assert = None
last_time = time.time()
last_runtime = time.time()
try:
while True:
# parse a line for state changes
@@ -1234,7 +1243,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
last_defines = None
last_stdout.clear()
last_assert = None
last_time = time.time()
last_runtime = time.time()
elif op == 'finished':
# force a failure
if args.get('fail'):
@@ -1296,7 +1305,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
'bench_erased': erased_,
'bench_simtime': simtime_,
'bench_runtime': '%.6f' % (
time.time() - last_time)})
time.time() - last_runtime)})
# keep track of total for summary
readed += readed_
progged += progged_
@@ -1758,6 +1767,19 @@ if __name__ == "__main__":
bench_parser.add_argument(
'--define-depth',
help="How deep to evaluate recursive defines before erroring.")
bench_parser.add_argument(
'-S', '--probe',
action='append',
help="Specify a probe to sample.")
bench_parser.add_argument(
'-x', '--probe-step',
help="Sample probes every n steps.")
bench_parser.add_argument(
'--probe-runfreq',
help="Sample probes at this frequency in hz.")
bench_parser.add_argument(
'-X', '--probe-simfreq',
help="Sample probes at this frequency in simulated hz.")
bench_parser.add_argument(
'--force',
action='store_true',
@@ -1786,6 +1808,9 @@ if __name__ == "__main__":
bench_parser.add_argument(
'--trace-runfreq',
help="Sample trace output at this frequency in hz.")
bench_parser.add_argument(
'--trace-simfreq',
help="Sample trace output at this frequency in simulated hz.")
bench_parser.add_argument(
'-O', '--stdout',
help="Direct stdout to this file. Note stderr is already merged "