mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 21:17:54 +00:00
Also record CPU time of subprocesses.
This commit is contained in:
parent
6aa6c63b05
commit
a497b8d86f
@ -5,11 +5,12 @@ The number of nodes is parameterized via a --number-of-nodes CLI option added
|
||||
to pytest.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from resource import getrusage, RUSAGE_CHILDREN
|
||||
from shutil import which, rmtree
|
||||
from tempfile import mkdtemp
|
||||
from contextlib import contextmanager
|
||||
from time import time
|
||||
from psutil import Process
|
||||
|
||||
import pytest
|
||||
import pytest_twisted
|
||||
@ -114,13 +115,27 @@ class Benchmarker:
|
||||
@contextmanager
|
||||
def record(self, capsys: pytest.CaptureFixture[str], name, **parameters):
|
||||
"""Record the timing of running some code, if it succeeds."""
|
||||
process = Process()
|
||||
|
||||
def get_children_cpu_time():
|
||||
cpu = 0
|
||||
for subprocess in process.children():
|
||||
usage = subprocess.cpu_times()
|
||||
cpu += usage.system + usage.user
|
||||
return cpu
|
||||
|
||||
start_cpu = get_children_cpu_time()
|
||||
start = time()
|
||||
yield
|
||||
elapsed = time() - start
|
||||
# For now we just print the outcome:
|
||||
end_cpu = get_children_cpu_time()
|
||||
elapsed_cpu = end_cpu - start_cpu
|
||||
# FOR now we just print the outcome:
|
||||
parameters = " ".join(f"{k}={v}" for (k, v) in parameters.items())
|
||||
with capsys.disabled():
|
||||
print(f"\nBENCHMARK RESULT: {name} {parameters} elapsed {elapsed} secs\n")
|
||||
print(
|
||||
f"\nBENCHMARK RESULT: {name} {parameters} elapsed={elapsed:.3} (secs) CPU={elapsed_cpu:.3} (secs)\n"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
3
setup.py
3
setup.py
@ -435,7 +435,8 @@ setup(name="tahoe-lafs", # also set in __init__.py
|
||||
"paramiko < 2.9",
|
||||
"pytest-timeout",
|
||||
# Does our OpenMetrics endpoint adhere to the spec:
|
||||
"prometheus-client == 0.11.0"
|
||||
"prometheus-client == 0.11.0",
|
||||
"psutil",
|
||||
] + tor_requires + i2p_requires,
|
||||
"tor": tor_requires,
|
||||
"i2p": i2p_requires,
|
||||
|
Loading…
Reference in New Issue
Block a user