Skip to content

Commit 2331790

Browse files
committed
add benchmark
1 parent 38c61f2 commit 2331790

File tree

6 files changed

+485
-3
lines changed

6 files changed

+485
-3
lines changed

mytonctrl/console_cmd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"enable_alert": "<alert_name>",
7070
"disable_alert": "<alert_name>",
7171
"setup_alert_bot": "<bot_token> <chat_id>",
72-
"download_archive_blocks": "[ton_storage_api_port] <download_path> <from_block_seqno> [to_block_seqno] [--only-master]"
72+
"download_archive_blocks": "[ton_storage_api_port] <download_path> <from_block_seqno> [to_block_seqno] [--only-master]",
73+
"benchmark": "[benchmark args ...]",
7374
}
7475

7576

mytonctrl/mytonctrl.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import sys
99
import getopt
1010
import os
11+
import shutil
12+
import tempfile
13+
from pathlib import Path
1114

1215
from functools import partial
1316

@@ -85,6 +88,7 @@ def inject_globals(func):
8588
add_command(local, console, "get", inject_globals(GetSettings))
8689
add_command(local, console, "set", inject_globals(SetSettings))
8790
add_command(local, console, "download_archive_blocks", inject_globals(download_archive_blocks))
91+
add_command(local, console, "benchmark", inject_globals(run_benchmark))
8892

8993
from modules.backups import BackupModule
9094
module = BackupModule(ton, local)
@@ -400,6 +404,45 @@ def upgrade_btc_teleport(local, ton, reinstall=False, branch: str = 'master', us
400404
local.try_function(module.init, args=[reinstall, branch, user])
401405

402406

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+
403446
def check_mytonctrl_update(local):
404447
git_path = local.buffer.my_dir
405448
result = check_git_update(git_path)

0 commit comments

Comments
 (0)