mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 21:38:55 -06:00
refactor: one load threshold for every probe
This commit is contained in:
1 parent
91e385598e
commit
eddb26f104
5 files changed
+32
-8
No files matched your search
@@ -1587,8 +1587,13 @@ def probe(args: argparse.Namespace) -> int:
|
|||||||
return _probe(args)
|
return _probe(args)
|
||||||
|
|
||||||
|
|
||||||
|
def default_max_load(cpus: int | None = None) -> float:
|
||||||
|
"""The load above which a run records nothing without --max-load: a quarter of the CPUs."""
|
||||||
|
return (cpus if cpus is not None else os.cpu_count() or 1) / 4
|
||||||
|
|
||||||
|
|
||||||
def _probe(args: argparse.Namespace) -> int:
|
def _probe(args: argparse.Namespace) -> int:
|
||||||
max_load = args.max_load if args.max_load is not None else (os.cpu_count() or 1) / 4
|
max_load = args.max_load if args.max_load is not None else default_max_load()
|
||||||
load_before = load_average()
|
load_before = load_average()
|
||||||
if args.record and load_before and load_before[0] > max_load:
|
if args.record and load_before and load_before[0] > max_load:
|
||||||
print(f"ERROR: load average {load_before[0]} exceeds {max_load}: the machine is busy, "
|
print(f"ERROR: load average {load_before[0]} exceeds {max_load}: the machine is busy, "
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class Host:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def max_load(self) -> float:
|
def max_load(self) -> float:
|
||||||
return self.cpu_count / 4
|
return core_probe.default_max_load(self.cpu_count)
|
||||||
|
|
||||||
|
|
||||||
def parse_budget(text: str) -> float:
|
def parse_budget(text: str) -> float:
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ from collections.abc import Iterable, Sequence
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core_probe import (EXIT_BUSY, PROBE_LOCK_ENV, PROBE_LOCK_HELD_ENV, VERDICTS, head_commit, host_probe_lock,
|
from core_probe import (EXIT_BUSY, PROBE_LOCK_ENV, PROBE_LOCK_HELD_ENV, VERDICTS, default_max_load, head_commit,
|
||||||
probe_lock_path)
|
host_probe_lock, probe_lock_path)
|
||||||
from core.paths import REPO_ROOT
|
from core.paths import REPO_ROOT
|
||||||
from core.statefile import now_iso
|
from core.statefile import now_iso
|
||||||
from model import measurements as mr
|
from model import measurements as mr
|
||||||
@@ -256,9 +256,9 @@ def content_folder(content: Content, fetch: bool) -> Path:
|
|||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
def wait_idle(limit: float = IDLE_WAIT, poll: float = 30.0) -> None:
|
def wait_idle(limit: float = IDLE_WAIT, poll: float = 30.0) -> None:
|
||||||
"""Wait for the load core_probe records under, a quarter of the CPUs.
|
"""Wait for the load core_probe records under (core_probe.default_max_load).
|
||||||
Extracting a pack loads the host itself for a minute or two."""
|
Extracting a pack loads the host itself for a minute or two."""
|
||||||
threshold = (os.cpu_count() or 1) / 4
|
threshold = default_max_load()
|
||||||
waited = 0.0
|
waited = 0.0
|
||||||
while os.getloadavg()[0] > threshold:
|
while os.getloadavg()[0] > threshold:
|
||||||
if waited >= limit:
|
if waited >= limit:
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -101,7 +100,7 @@ def measure(args: argparse.Namespace, emu: Emulator) -> dict:
|
|||||||
meta, tree = installed(emu, args.sha256)
|
meta, tree = installed(emu, args.sha256)
|
||||||
except (cp.ProbeError, OSError, subprocess.SubprocessError) as exc:
|
except (cp.ProbeError, OSError, subprocess.SubprocessError) as exc:
|
||||||
raise RunFailed(exc) from exc
|
raise RunFailed(exc) from exc
|
||||||
max_load = args.max_load if args.max_load is not None else (os.cpu_count() or 1) / 4
|
max_load = args.max_load if args.max_load is not None else cp.default_max_load()
|
||||||
load_before = cp.load_average()
|
load_before = cp.load_average()
|
||||||
if args.record and load_before and load_before[0] > max_load:
|
if args.record and load_before and load_before[0] > max_load:
|
||||||
raise Busy(f"load average {load_before[0]} exceeds {max_load}: the machine is busy, "
|
raise Busy(f"load average {load_before[0]} exceeds {max_load}: the machine is busy, "
|
||||||
|
|||||||
@@ -355,6 +355,26 @@ class Lock(unittest.TestCase):
|
|||||||
self.assertFalse(try_lock())
|
self.assertFalse(try_lock())
|
||||||
|
|
||||||
|
|
||||||
|
class LoadThreshold(unittest.TestCase):
|
||||||
|
"""pack_probe waits for the load core_probe records under, and the campaign
|
||||||
|
passes the same value: all three read core_probe.default_max_load."""
|
||||||
|
|
||||||
|
def test_wait_and_campaign_follow_core_probe(self) -> None:
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import core_probe
|
||||||
|
from probes import host
|
||||||
|
|
||||||
|
with mock.patch.object(os, "cpu_count", return_value=12):
|
||||||
|
threshold = core_probe.default_max_load()
|
||||||
|
self.assertEqual(host.Host(cpu_count=12).max_load, threshold)
|
||||||
|
with mock.patch.object(os, "getloadavg", return_value=(threshold, 0.0, 0.0)):
|
||||||
|
packprobe.wait_idle(limit=0, poll=0)
|
||||||
|
with mock.patch.object(os, "getloadavg", return_value=(threshold + 0.5, 0.0, 0.0)), \
|
||||||
|
self.assertRaisesRegex(packprobe.ProbeFailure, f"above {threshold} "):
|
||||||
|
packprobe.wait_idle(limit=0, poll=0)
|
||||||
|
|
||||||
|
|
||||||
class RecordsNameNoLocalPath(unittest.TestCase):
|
class RecordsNameNoLocalPath(unittest.TestCase):
|
||||||
"""A record is read on other machines: the probe's scratch folders are
|
"""A record is read on other machines: the probe's scratch folders are
|
||||||
written as the options that named them."""
|
written as the options that named them."""
|
||||||
|
|||||||
Reference in new issue
Block a user