Private
Public Access
feat(startup_profiler): add module-level singleton + live stderr logging
- startup_profiler: StartupProfiler = StartupProfiler() at module bottom so sloppy.py can import it without circular imports. - phase() context manager now writes a [startup] <name>: <ms>ms line to stderr in its finally block. Live visibility of every measured phase.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import time
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Iterator
|
||||
@@ -33,6 +34,11 @@ class StartupProfiler:
|
||||
finally:
|
||||
p.end_ts = time.perf_counter()
|
||||
self._phases.append(p)
|
||||
try:
|
||||
sys.stderr.write(f"[startup] {name}: {(p.end_ts - p.start_ts) * 1000.0:.1f}ms\n")
|
||||
sys.stderr.flush()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def snapshot(self) -> dict[str, Any]:
|
||||
phases: dict[str, dict[str, float]] = {}
|
||||
@@ -52,3 +58,6 @@ class StartupProfiler:
|
||||
|
||||
def reset(self) -> None:
|
||||
self._phases.clear()
|
||||
|
||||
|
||||
startup_profiler: StartupProfiler = StartupProfiler()
|
||||
|
||||
Reference in New Issue
Block a user