Coverage for src/tagmania/iac_tools/timing.py: 100%
12 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-02 01:51 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-02 01:51 +0000
1"""Utilities for logging operation durations."""
3from __future__ import annotations
5import logging
6import time
7from collections.abc import Iterator
8from contextlib import contextmanager
11@contextmanager
12def log_duration(logger: logging.Logger, label: str) -> Iterator[None]:
13 """Log the wall-clock duration of the wrapped block at INFO level.
15 Emits the duration even if the wrapped block raises, so partial runs
16 still produce a timing line.
17 """
18 start = time.perf_counter()
19 try:
20 yield
21 finally:
22 elapsed = time.perf_counter() - start
23 logger.info(f"{label} took {elapsed:.1f}s")