diff --git a/benchmarks/mempool.py b/benchmarks/mempool.py index 5a4fa3aa93..99a1253e08 100644 --- a/benchmarks/mempool.py +++ b/benchmarks/mempool.py @@ -29,13 +29,13 @@ NUM_PEERS = 5 @contextmanager def enable_profiler(profile: bool, name: str) -> Iterator[None]: - if sys.version_info < (3, 8): - raise Exception(f"Python 3.8 or higher required, running with: {sys.version}") - if not profile: yield return + if sys.version_info < (3, 8): + raise Exception(f"Python 3.8 or higher required when profiling is requested, running with: {sys.version}") + with cProfile.Profile() as pr: yield diff --git a/tests/wallet/test_offer_parsing_performance.py b/tests/wallet/test_offer_parsing_performance.py index aab16a9e54..6414d74329 100644 --- a/tests/wallet/test_offer_parsing_performance.py +++ b/tests/wallet/test_offer_parsing_performance.py @@ -18,13 +18,13 @@ with_profile = False @contextmanager def enable_profiler(name: str) -> Iterator[None]: - if sys.version_info < (3, 8): - raise Exception(f"Python 3.8 or higher required, running with: {sys.version}") - if not with_profile: yield return + if sys.version_info < (3, 8): + raise Exception(f"Python 3.8 or higher required when profiling is requested, running with: {sys.version}") + with cProfile.Profile() as pr: yield diff --git a/tools/generate_chain.py b/tools/generate_chain.py index 6086f1c16a..c2131784fa 100644 --- a/tools/generate_chain.py +++ b/tools/generate_chain.py @@ -23,13 +23,13 @@ from tools.test_constants import test_constants @contextmanager def enable_profiler(profile: bool, counter: int) -> Iterator[None]: - if sys.version_info < (3, 8): - raise Exception(f"Python 3.8 or higher required, running with: {sys.version}") - if not profile: yield return + if sys.version_info < (3, 8): + raise Exception(f"Python 3.8 or higher required when profiling is requested, running with: {sys.version}") + with cProfile.Profile() as pr: yield diff --git a/tools/test_full_sync.py b/tools/test_full_sync.py index f2a578c1f5..7723440f60 100755 --- a/tools/test_full_sync.py +++ b/tools/test_full_sync.py @@ -46,13 +46,13 @@ class ExitOnError(logging.Handler): @contextmanager def enable_profiler(profile: bool, counter: int) -> Iterator[None]: - if sys.version_info < (3, 8): - raise Exception(f"Python 3.8 or higher required, running with: {sys.version}") - if not profile: yield return + if sys.version_info < (3, 8): + raise Exception(f"Python 3.8 or higher required when profiling is requested, running with: {sys.version}") + with cProfile.Profile() as pr: receive_start_time = time.monotonic() yield @@ -112,9 +112,6 @@ async def run_sync_test( node_profiler: bool, start_at_checkpoint: Optional[str], ) -> None: - if sys.version_info < (3, 8): - raise Exception(f"Python 3.8 or higher required, running with: {sys.version}") - logger = logging.getLogger() logger.setLevel(logging.WARNING) handler = logging.FileHandler("test-full-sync.log") @@ -129,9 +126,9 @@ async def run_sync_test( logger.addHandler(check_log) with tempfile.TemporaryDirectory() as root_dir: - root_path = Path(root_dir) + root_path = Path(root_dir, "root") if start_at_checkpoint is not None: - shutil.copytree(Path(start_at_checkpoint) / ".", root_path, dirs_exist_ok=True) + shutil.copytree(start_at_checkpoint, root_path) chia_init(root_path, should_check_keys=False, v1_db=(db_version == 1)) config = load_config(root_path, "config.yaml")