Enhance logging and timing in CLI and session operations

- Updated the `_print_checks` function to replace console prints with logging functions for better traceability.
- Introduced timing functionality in the `doctor`, `dry_run`, and `up` functions to log the duration of preflight checks.
- Modified the `wait_ssh` function to accept a logging callback, improving SSH wait feedback.
- Enhanced the `mark` method in `PhaseTimes` to log phase durations, aiding in performance analysis.
- Updated various remote scripts to ensure error messages are printed to stderr for better error handling.
This commit is contained in:
Leonid Pershin
2026-08-21 08:03:04 +03:00
parent 7756d0d4df
commit ccba40a228
16 changed files with 205 additions and 46 deletions
+48 -1
View File
@@ -1,4 +1,11 @@
from gpu_rent.timing import PhaseTimes, WaitLog, format_duration
from gpu_rent.timing import (
PhaseTimes,
WaitLog,
clock_elapsed,
clock_prefix,
clock_reset,
format_duration,
)
def test_format_duration():
@@ -20,6 +27,36 @@ def test_phase_times_summary(monkeypatch):
assert "всего" in line
def test_phase_times_mark_logs(monkeypatch):
times = iter([0.0, 45.0])
monkeypatch.setattr("gpu_rent.timing.time.monotonic", lambda: next(times))
logs: list[str] = []
clock = PhaseTimes()
clock.mark("SSH", logs.append)
assert logs == ["фаза SSH: 45s · всего 45s"]
def test_phase_summary_lines_annotate_long_work(monkeypatch):
# t0=0, mark provision at 120s
times = iter([0.0, 120.0, 120.0])
monkeypatch.setattr("gpu_rent.timing.time.monotonic", lambda: next(times))
clock = PhaseTimes()
clock.mark("provision")
lines = clock.summary_lines()
assert lines[0] == "тайминг up:"
assert any("provision" in ln and "оптимизировать?" in ln for ln in lines)
assert any("seed/extensions/LLM" in ln for ln in lines)
def test_phase_summary_lines_annotate_wait(monkeypatch):
times = iter([0.0, 40.0, 40.0])
monkeypatch.setattr("gpu_rent.timing.time.monotonic", lambda: next(times))
clock = PhaseTimes()
clock.mark("SSH")
lines = clock.summary_lines()
assert any("SSH" in ln and "ожидание" in ln for ln in lines)
def test_wait_log_throttles(monkeypatch):
logs: list[str] = []
t = {"now": 0.0}
@@ -31,3 +68,13 @@ def test_wait_log_throttles(monkeypatch):
t["now"] = 31.0
w.tick("c")
assert logs == ["a", "c"]
def test_clock_prefix(monkeypatch):
t = {"now": 100.0}
monkeypatch.setattr("gpu_rent.timing.time.monotonic", lambda: t["now"])
clock_reset()
assert clock_prefix() == "[+0s] "
t["now"] = 112.0
assert clock_prefix() == "[+12s] "
assert clock_elapsed() == 12.0