diff --git a/scripts/run_benchmarks.py b/scripts/run_benchmarks.py index 843b64f53..0dc25098a 100755 --- a/scripts/run_benchmarks.py +++ b/scripts/run_benchmarks.py @@ -144,6 +144,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("-l", "--list", action="store_true", help="List all benchmarks") parser.add_argument("-t", "--trace", action="store_true", help="Dump waveforms") + parser.add_argument("-p", "--profile", action="store_true", help="Write execution profiles") parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") parser.add_argument("-b", "--backend", default="cocotb", choices=["cocotb", "pysim"], help="Simulation backend") parser.add_argument( @@ -171,6 +172,9 @@ def main(): print(f"Could not find benchmark '{args.benchmark_name}'") sys.exit(1) + if args.profile: + os.environ["__TRANSACTRON_PROFILE"] = "1" + success = run_benchmarks(benchmarks, args.backend, args.trace, args.verbose) if not success: print("Benchmark execution failed") diff --git a/test/regression/benchmark.py b/test/regression/benchmark.py index 8f9cb56c2..5b465d650 100644 --- a/test/regression/benchmark.py +++ b/test/regression/benchmark.py @@ -9,6 +9,7 @@ test_dir = Path(__file__).parent.parent embench_dir = test_dir.joinpath("external/embench/build/src") results_dir = test_dir.joinpath("regression/benchmark_results") +profile_dir = test_dir.joinpath("__profiles__") @dataclass_json @@ -77,6 +78,10 @@ async def run_benchmark(sim_backend: SimulationBackend, benchmark_name: str): result = await sim_backend.run(mem_model, timeout_cycles=2000000) + if result.profile is not None: + os.makedirs(profile_dir, exist_ok=True) + result.profile.encode(f"{profile_dir}/benchmark.{benchmark_name}.json") + if not result.success: raise RuntimeError("Simulation timed out")