Skip to content

Commit 17693ff

Browse files
committed
truncate the output file
1 parent 6faacdc commit 17693ff

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

tools/ci/ci_util/bench.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
from pathlib import Path
1212
from subprocess import check_output
1313

14+
_results_file = 'benchmark-results.txt'
15+
16+
1417
def _record_measurement(bench: str, time: int) -> None:
1518
print('{}: {}ms'.format(bench, time), flush=True)
16-
with open('benchmark-results.txt', 'at') as f:
17-
f.write('{},{}'.format(bench, time))
19+
with open(_results_file, 'at') as f:
20+
f.write('{},{}\n'.format(bench, time))
1821

19-
def run_connection_pool_bench(
22+
23+
def _run_connection_pool(
2024
exe_dir: Path,
2125
iters: int,
2226
server_host: str,
@@ -39,7 +43,7 @@ def run_connection_pool_bench(
3943
_record_measurement(bench, time)
4044

4145

42-
def run_protocol_bench(
46+
def _run_protocol(
4347
exe_dir: Path,
4448
iters: int,
4549
) -> None:
@@ -62,3 +66,17 @@ def run_protocol_bench(
6266
time = int(check_output([exe]).decode())
6367
_record_measurement(bench, time)
6468

69+
70+
def run_benchmarks(
71+
exe_dir: Path,
72+
server_host: str,
73+
connection_pool_iters: int,
74+
protocol_iters: int,
75+
) -> None:
76+
# Truncate the results file, if it exists
77+
with open(_results_file, 'wt') as f:
78+
pass
79+
80+
# Run the benchmarks
81+
_run_connection_pool(exe_dir, connection_pool_iters, server_host)
82+
_run_protocol(exe_dir, protocol_iters)

tools/ci/ci_util/cmake.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .common import run, BOOST_ROOT, IS_WINDOWS, mkdir_and_cd
1313
from .db_setup import db_setup, db_setup_bench
1414
from .install_boost import install_boost
15-
from .bench import run_connection_pool_bench, run_protocol_bench
15+
from .bench import run_benchmarks
1616

1717

1818
def _cmake_prefix_path(extra_path: Optional[Path] = None) -> str:
@@ -284,6 +284,9 @@ def bench_build(
284284
runner.build(target='boost_mysql_bench')
285285

286286
# Run the benchmarks
287-
exe_dir = bin_dir.joinpath('stage', 'bin')
288-
run_connection_pool_bench(exe_dir, connection_pool_iters, server_host)
289-
run_protocol_bench(exe_dir, protocol_iters)
287+
run_benchmarks(
288+
exe_dir=bin_dir.joinpath('stage', 'bin'),
289+
server_host=server_host,
290+
connection_pool_iters=connection_pool_iters,
291+
protocol_iters=protocol_iters,
292+
)

0 commit comments

Comments
 (0)