Make benchmarking results visible by default.

This commit is contained in:
Itamar Turner-Trauring 2023-09-07 17:21:45 -04:00
parent 653f483d9f
commit 6aa6c63b05
2 changed files with 13 additions and 5 deletions

View File

@ -5,6 +5,7 @@ The number of nodes is parameterized via a --number-of-nodes CLI option added
to pytest.
"""
import sys
from shutil import which, rmtree
from tempfile import mkdtemp
from contextlib import contextmanager
@ -111,14 +112,15 @@ class Benchmarker:
"""Keep track of benchmarking results."""
@contextmanager
def record(self, name, **parameters):
def record(self, capsys: pytest.CaptureFixture[str], name, **parameters):
"""Record the timing of running some code, if it succeeds."""
start = time()
yield
elapsed = time() - start
# For now we just print the outcome:
parameters = " ".join(f"{k}={v}" for (k, v) in parameters.items())
print(f"BENCHMARK RESULT: {name} {parameters} elapsed {elapsed} secs")
with capsys.disabled():
print(f"\nBENCHMARK RESULT: {name} {parameters} elapsed {elapsed} secs\n")
@pytest.fixture(scope="session")

View File

@ -14,7 +14,13 @@ def cli_alias(client_node):
@pytest.mark.parametrize("file_size", [1000, 100_000, 1_000_000, 10_000_000])
def test_get_put_one_file(
file_size, client_node, cli_alias, tmp_path, tahoe_benchmarker, number_of_nodes
file_size,
client_node,
cli_alias,
tmp_path,
tahoe_benchmarker,
number_of_nodes,
capsys,
):
"""
Upload a file with ``tahoe put`` and then download it with ``tahoe get``,
@ -26,12 +32,12 @@ def test_get_put_one_file(
f.write(DATA)
with tahoe_benchmarker.record(
"cli-put-file", file_size=file_size, number_of_nodes=number_of_nodes
capsys, "cli-put-file", file_size=file_size, number_of_nodes=number_of_nodes
):
cli(client_node.process, "put", str(file_path), "cli:tostdout")
with tahoe_benchmarker.record(
"cli-get-file", file_size=file_size, number_of_nodes=number_of_nodes
capsys, "cli-get-file", file_size=file_size, number_of_nodes=number_of_nodes
):
p = Popen(
[