mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 01:53:56 -06:00
feat: time each step in the pipeline summary
This commit is contained in:
1 parent
4e21469b3a
commit
45d446df33
2 files changed
+44
-5
No files matched your search
+26
-5
@@ -62,6 +62,27 @@ from common import (
|
|||||||
from refresh_data_dirs import hold_data_dirs
|
from refresh_data_dirs import hold_data_dirs
|
||||||
|
|
||||||
|
|
||||||
|
class StepResults(dict):
|
||||||
|
"""The outcome of each step, and how long it took.
|
||||||
|
|
||||||
|
A step's time runs from the previous step's outcome to its own, so the
|
||||||
|
in-process steps (consistency, the truth diff) are timed like the ones
|
||||||
|
run() launches. The summary prints it: finding the slow step in a
|
||||||
|
twenty-minute run meant reading the whole log.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, start: float) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.seconds: dict[str, float] = {}
|
||||||
|
self._mark = start
|
||||||
|
|
||||||
|
def __setitem__(self, step: str, outcome: object) -> None:
|
||||||
|
now = time.monotonic()
|
||||||
|
self.seconds[step] = self.seconds.get(step, 0.0) + now - self._mark
|
||||||
|
self._mark = now
|
||||||
|
super().__setitem__(step, outcome)
|
||||||
|
|
||||||
|
|
||||||
def run(cmd: list[str], label: str) -> tuple[bool, str]:
|
def run(cmd: list[str], label: str) -> tuple[bool, str]:
|
||||||
"""Run a command, echoing its output as it comes. Returns (success, output).
|
"""Run a command, echoing its output as it comes. Returns (success, output).
|
||||||
|
|
||||||
@@ -384,9 +405,9 @@ def main() -> None:
|
|||||||
print(f"ERROR: {exc}")
|
print(f"ERROR: {exc}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
results = {}
|
|
||||||
all_ok = True
|
all_ok = True
|
||||||
total_start = time.monotonic()
|
total_start = time.monotonic()
|
||||||
|
results = StepResults(total_start)
|
||||||
|
|
||||||
# Step 1: Generate database
|
# Step 1: Generate database
|
||||||
ok, out = run(
|
ok, out = run(
|
||||||
@@ -709,10 +730,10 @@ def main() -> None:
|
|||||||
print(f"\n{'=' * 60}")
|
print(f"\n{'=' * 60}")
|
||||||
for step, outcome in results.items():
|
for step, outcome in results.items():
|
||||||
if outcome is SKIPPED:
|
if outcome is SKIPPED:
|
||||||
label = "SKIPPED"
|
print(f" {step:.<40} SKIPPED")
|
||||||
else:
|
continue
|
||||||
label = "OK" if outcome else "FAILED"
|
label = "OK" if outcome else "FAILED"
|
||||||
print(f" {step:.<40} {label}")
|
print(f" {step:.<40} {label:<7}{results.seconds[step]:>8.1f}s")
|
||||||
print(f" {'total':.<40} {total_elapsed:.1f}s")
|
print(f" {'total':.<40} {total_elapsed:.1f}s")
|
||||||
print(f"{'=' * 60}")
|
print(f"{'=' * 60}")
|
||||||
print(f" Pipeline {'COMPLETE' if all_ok else 'FINISHED WITH ERRORS'}")
|
print(f" Pipeline {'COMPLETE' if all_ok else 'FINISHED WITH ERRORS'}")
|
||||||
|
|||||||
@@ -5100,5 +5100,23 @@ class TheGroundTruthFooterSaysWhatItCounts(unittest.TestCase):
|
|||||||
self.assertNotIn("0/81", text)
|
self.assertNotIn("0/81", text)
|
||||||
|
|
||||||
|
|
||||||
|
class ThePipelineSummaryTimesEachStep(unittest.TestCase):
|
||||||
|
"""The summary gave OK per step and one total: the slow step of a
|
||||||
|
twenty-minute run could only be found by reading the log."""
|
||||||
|
|
||||||
|
def test_each_outcome_carries_its_time(self):
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
clock = iter([10.0, 12.5, 12.5, 20.0])
|
||||||
|
with mock.patch.object(pipeline.time, "monotonic", lambda: next(clock)):
|
||||||
|
results = pipeline.StepResults(pipeline.time.monotonic())
|
||||||
|
results["generate_db"] = True
|
||||||
|
results["refresh_data"] = pipeline.SKIPPED
|
||||||
|
results["verify"] = True
|
||||||
|
self.assertEqual(results.seconds, {"generate_db": 2.5, "refresh_data": 0.0, "verify": 7.5})
|
||||||
|
self.assertEqual(dict(results), {"generate_db": True, "refresh_data": pipeline.SKIPPED,
|
||||||
|
"verify": True})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user