|
8 | 8 | import sys |
9 | 9 | import getopt |
10 | 10 | import os |
| 11 | +import shutil |
| 12 | +import tempfile |
| 13 | +from pathlib import Path |
11 | 14 |
|
12 | 15 | from functools import partial |
13 | 16 |
|
@@ -85,6 +88,7 @@ def inject_globals(func): |
85 | 88 | add_command(local, console, "get", inject_globals(GetSettings)) |
86 | 89 | add_command(local, console, "set", inject_globals(SetSettings)) |
87 | 90 | add_command(local, console, "download_archive_blocks", inject_globals(download_archive_blocks)) |
| 91 | + add_command(local, console, "benchmark", inject_globals(run_benchmark)) |
88 | 92 |
|
89 | 93 | from modules.backups import BackupModule |
90 | 94 | module = BackupModule(ton, local) |
@@ -400,6 +404,45 @@ def upgrade_btc_teleport(local, ton, reinstall=False, branch: str = 'master', us |
400 | 404 | local.try_function(module.init, args=[reinstall, branch, user]) |
401 | 405 |
|
402 | 406 |
|
| 407 | +def run_benchmark(args: list): |
| 408 | + if shutil.which("uv") is None: |
| 409 | + color_print("{red}Error: uv is not installed. Install it: https://docs.astral.sh/uv/getting-started/installation/{endc}") |
| 410 | + return |
| 411 | + |
| 412 | + if get_service_status("validator"): |
| 413 | + color_print("{red}Error: validator service is running. Stop it before running benchmark: `sudo systemctl stop validator`{endc}") |
| 414 | + return |
| 415 | + |
| 416 | + with tempfile.TemporaryDirectory() as tmp_dir: |
| 417 | + tmp_dir = Path(tmp_dir) |
| 418 | + with get_package_resource_path('mytonctrl', 'scripts/benchmark.py') as benchmark_path: |
| 419 | + shutil.copy(benchmark_path, tmp_dir / "benchmark.py") |
| 420 | + |
| 421 | + subprocess.run(["uv", "init", "--no-workspace", "--name", "benchmark"], cwd=tmp_dir, check=True) |
| 422 | + |
| 423 | + src_dir = Path("/usr/src/ton") |
| 424 | + test_dir = tmp_dir / "test" |
| 425 | + tontester_dir = test_dir / "tontester" |
| 426 | + |
| 427 | + shutil.copytree(src_dir / "test", test_dir) |
| 428 | + |
| 429 | + tl_dest = tmp_dir / "tl" / "generate" / "scheme" |
| 430 | + Path(tl_dest).mkdir(parents=True, exist_ok=True) |
| 431 | + |
| 432 | + for f in (src_dir / "tl" / "generate" / "scheme").glob('*.tl'): |
| 433 | + shutil.copy(f, tl_dest) |
| 434 | + |
| 435 | + subprocess.run(["uv", "add", tontester_dir], cwd=tmp_dir, check=True) |
| 436 | + |
| 437 | + subprocess.run(["uv", "run", tontester_dir / "generate_tl.py"], cwd=tmp_dir, check=True) |
| 438 | + |
| 439 | + cmd = ["uv", "run", "benchmark.py", |
| 440 | + "--build-dir", '/usr/bin/ton', |
| 441 | + "--source-dir", '/usr/src/ton', |
| 442 | + "--work-dir", str(tmp_dir / "test" / "integration" / ".network")] + args |
| 443 | + subprocess.run(cmd, cwd=tmp_dir) |
| 444 | + |
| 445 | + |
403 | 446 | def check_mytonctrl_update(local): |
404 | 447 | git_path = local.buffer.my_dir |
405 | 448 | result = check_git_update(git_path) |
|
0 commit comments