Tracks timing for each build phase.
| 15 | |
| 16 | @dataclass |
| 17 | class BuildTimer: |
| 18 | """Tracks timing for each build phase.""" |
| 19 | |
| 20 | # Phase timing (seconds) |
| 21 | meson_setup_time: float = 0.0 |
| 22 | ninja_maintenance_time: float = 0.0 |
| 23 | compile_time: float = 0.0 |
| 24 | test_execution_time: float = 0.0 |
| 25 | total_time: float = 0.0 |
| 26 | |
| 27 | # Checkpoint tracking |
| 28 | _checkpoints: dict[str, float] = field(default_factory=dict) |
| 29 | _start_time: Optional[float] = None |
| 30 | |
| 31 | def start(self) -> None: |
| 32 | """Mark the start of the build process.""" |
| 33 | self._start_time = time.time() |
| 34 | self._checkpoints["start"] = self._start_time |
| 35 | |
| 36 | def checkpoint(self, name: str) -> None: |
| 37 | """Record a timing checkpoint.""" |
| 38 | if self._start_time is None: |
| 39 | raise RuntimeError("Timer not started - call start() first") |
| 40 | self._checkpoints[name] = time.time() |
| 41 | |
| 42 | def calculate_phases(self) -> None: |
| 43 | """Calculate phase durations from checkpoints.""" |
| 44 | if not self._checkpoints: |
| 45 | return |
| 46 | |
| 47 | cp = self._checkpoints |
| 48 | |
| 49 | # Calculate phase times based on checkpoint sequence |
| 50 | if "start" in cp: |
| 51 | if "meson_setup_done" in cp: |
| 52 | self.meson_setup_time = cp["meson_setup_done"] - cp["start"] |
| 53 | |
| 54 | if "ninja_maintenance_done" in cp and "meson_setup_done" in cp: |
| 55 | self.ninja_maintenance_time = ( |
| 56 | cp["ninja_maintenance_done"] - cp["meson_setup_done"] |
| 57 | ) |
| 58 | |
| 59 | if "compile_done" in cp and "ninja_maintenance_done" in cp: |
| 60 | self.compile_time = cp["compile_done"] - cp["ninja_maintenance_done"] |
| 61 | elif "compile_done" in cp and "meson_setup_done" in cp: |
| 62 | # If ninja maintenance wasn't tracked separately |
| 63 | self.compile_time = cp["compile_done"] - cp["meson_setup_done"] |
| 64 | |
| 65 | if "test_execution_done" in cp and "compile_done" in cp: |
| 66 | self.test_execution_time = ( |
| 67 | cp["test_execution_done"] - cp["compile_done"] |
| 68 | ) |
| 69 | |
| 70 | if "test_execution_done" in cp: |
| 71 | self.total_time = cp["test_execution_done"] - cp["start"] |
| 72 | elif "compile_done" in cp: |
| 73 | self.total_time = cp["compile_done"] - cp["start"] |
| 74 | else: |
no outgoing calls
no test coverage detected