chore: checkpoint current performance and UI changes
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""Tiny opt-in performance tracing helpers.
|
||||
|
||||
Tracing is disabled by default and emits only timings/counts, never prompts,
|
||||
credentials, file contents, or provider payloads.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
_LOG = logging.getLogger("cowork.performance")
|
||||
|
||||
|
||||
def enabled() -> bool:
|
||||
return os.environ.get("COWORK_PERF_TRACE", "").strip().lower() in {"1", "true", "yes"}
|
||||
|
||||
|
||||
@contextmanager
|
||||
def span(name: str, **fields):
|
||||
if not enabled():
|
||||
yield
|
||||
return
|
||||
started = time.perf_counter()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
elapsed = (time.perf_counter() - started) * 1000.0
|
||||
safe = " ".join(f"{k}={v}" for k, v in fields.items())
|
||||
_LOG.info("perf %s %.1fms%s", name, elapsed, f" {safe}" if safe else "")
|
||||
Reference in New Issue
Block a user