Skip to content

Class peagen.plugins.evaluators.psutil_io.PsutilIOEvaluator

peagen.plugins.evaluators.psutil_io.PsutilIOEvaluator

PsutilIOEvaluator(**_)

Bases: Evaluator

Evaluate disk I/O usage of bench_cmd using psutil.

Source code in peagen/plugins/evaluators/base.py
14
15
def __init__(self, **_: Any) -> None:
    self.last_result = None

last_result instance-attribute

last_result = None

run

run(workspace, bench_cmd, runs=1, **kw)
Source code in peagen/plugins/evaluators/psutil_io.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def run(self, workspace: Path, bench_cmd: str, runs: int = 1, **kw: Any) -> float:
    deltas: list[float] = []
    runs = max(1, int(runs))
    for _ in range(runs):
        before = psutil.disk_io_counters()
        start = time.perf_counter()
        subprocess.run(
            shlex.split(bench_cmd), cwd=workspace, check=False, capture_output=True
        )
        duration = time.perf_counter() - start
        after = psutil.disk_io_counters()
        delta = (after.read_bytes - before.read_bytes) + (
            after.write_bytes - before.write_bytes
        )
        deltas.append(delta / (1024 * 1024))
    median_delta = statistics.median(deltas)
    self.last_result = {
        "deltas_mib": deltas,
        "median_mib": median_delta,
        "runs": runs,
        "duration_s": duration,
    }
    return -median_delta