stagetimer.py

clew/stagetimer.py

Per-stage wall-clock cost of one build, recorded beside the refresh total.

__init__

None clew.stagetimer.StageTimer.__init__(self)

Start the first segment.

clew/stagetimer.py:61

Show on the map →

Called by none

Calls none

Source · 8 lines
    def __init__(self) -> None:
        """@brief Begin timing at construction.

        @version 1
        """
        self._last = time.perf_counter()
        self._stages: list[tuple[str, int]] = []
Activity · 2 steps
lines 66–66self._last = time.perf_counter()lines 67–67self._stages: list[tuple[str, int]] = []

Requirements

REQ-DDB-MCP-004

as_meta

dict[str, str] clew.stagetimer.StageTimer.as_meta(self)

The breakdown as a build_meta section fragment.

clew/stagetimer.py:104

Show on the map →

Called by none

Calls none

Source · 17 lines
    def as_meta(self) -> dict[str, str]:
        """EMPTY WHEN NOTHING WAS MARKED, so an unmeasured build stamps no key at all.
        `write_build_signature` drops falsy values, so an empty string would vanish
        anyway; returning {} says the same thing at the point a reader looks.

        @brief Serialize the breakdown for `write_build_signature(refresh=...)`.
        @return A one-key mapping, or {}.
        @version 1
        """
        if not self._stages:
            return {}
        rendered = STAGE_SEPARATOR.join(
            f"{name}{STAGE_ASSIGN}{elapsed}" for name, elapsed in self._stages
        )
        return {STAGES_KEY: rendered}

Activity · 4 steps
lines 113–113◇ if not self._stageslines 114–114return {}lines 115–117rendered = STAGE_SEPARATOR.join( f"{name}{STAGE_ASSIGN}{elapsed}" for name, elapsed in self._stages )lines 118–118return {STAGES_KEY: rendered}

Requirements

REQ-DDB-MCP-004

mark

None clew.stagetimer.StageTimer.mark(self, str name)

Close the segment that just ran and name it.

clew/stagetimer.py:73

Show on the map →

Called by none

Calls none

Source · 15 lines
    def mark(self, name: str) -> None:
        """Elapsed time is measured from the previous `mark` (or from construction),
        so the segments partition the timed span with no gaps and no overlaps.

        A repeated name is recorded again rather than merged. Two segments that
        genuinely ran twice are two facts, and silently summing them would report a
        single stage that no single call ever took.

        @brief Record the elapsed time since the last mark under `name`.
        @version 1
        """
        now = time.perf_counter()
        self._stages.append((name, int((now - self._last) * 1000)))
        self._last = now
Activity · 3 steps
lines 84–84now = time.perf_counter()lines 85–85self._stages.append((name, int((now - self._last) * 1000)))lines 86–86self._last = now

Requirements

REQ-DDB-MCP-004

parse_stages

tuple[tuple[str, int], ...] clew.stagetimer.parse_stages(str rendered)

Parse a stamped refresh.stages value back into ordered pairs.

clew/stagetimer.py:126

Source · 16 lines
def parse_stages(rendered: str) -> tuple[tuple[str, int], ...]:
    """The inverse of `StageTimer.as_meta`, kept beside it so the two cannot drift
    into different notions of the separator. A malformed segment is DROPPED rather
    than raised on: this reads a stored measurement in a reporting path, and a
    breakdown that cannot be shown must not take the status call down with it.

    @brief Decode a stored stage breakdown.
    @return The decoded pairs.
    @version 1
    """
    decoded: list[tuple[str, int]] = []
    for segment in rendered.split(STAGE_SEPARATOR):
        name, _, value = segment.partition(STAGE_ASSIGN)
        if name and value.isdigit():
            decoded.append((name, int(value)))
    return tuple(decoded)

1 more lines, not shown

Activity · 6 steps
lines 136–136decoded: list[tuple[str, int]] = []lines 137–137◇ for segment in rendered.split(STAGE_SEPARATOR)lines 138–138name, _, value = segment.partition(STAGE_ASSIGN)lines 139–139◇ if name and value.isdigit()lines 140–140decoded.append((name, int(value)))lines 141–141return tuple(decoded)

Requirements

REQ-DDB-MCP-004

stages

tuple[tuple[str, int], ...] clew.stagetimer.StageTimer.stages(self)

The recorded segments, in execution order.

clew/stagetimer.py:92

Show on the map →

Called by none

Calls none

Source · 8 lines
    def stages(self) -> tuple[tuple[str, int], ...]:
        """@brief Read the recorded segments.

        @return The (name, milliseconds) pairs in order.
        @version 1
        """
        return tuple(self._stages)
Activity · 1 steps
lines 98–98return tuple(self._stages)

Requirements

REQ-DDB-MCP-004