Check if compilation metrics exceed thresholds. This function checks ONLY the aggregate/total compilation time against the configured threshold. Individual header times are not checked as they can vary significantly between compilations due to caching and other factors. The agg
(analyzer: CompilePerfAnalyzer, thresholds_file: Path)
| 612 | |
| 613 | |
| 614 | def check_thresholds(analyzer: CompilePerfAnalyzer, thresholds_file: Path) -> bool: |
| 615 | """ |
| 616 | Check if compilation metrics exceed thresholds. |
| 617 | |
| 618 | This function checks ONLY the aggregate/total compilation time against the |
| 619 | configured threshold. Individual header times are not checked as they can |
| 620 | vary significantly between compilations due to caching and other factors. |
| 621 | The aggregate time is what matters for real-world user experience. |
| 622 | |
| 623 | Returns True if all checks pass, False otherwise. |
| 624 | """ |
| 625 | if not thresholds_file.exists(): |
| 626 | print( |
| 627 | f"Warning: Thresholds file not found at {thresholds_file}", file=sys.stderr |
| 628 | ) |
| 629 | return True |
| 630 | |
| 631 | with open(thresholds_file, "r") as f: |
| 632 | thresholds = json.load(f) |
| 633 | |
| 634 | total_time = analyzer.get_total_time() |
| 635 | |
| 636 | errors: list[str] = [] |
| 637 | |
| 638 | # Check total compile time (this is the only check that matters) |
| 639 | max_total = thresholds.get("total_compile_time_ms", 2000) |
| 640 | if total_time > max_total: |
| 641 | errors.append( |
| 642 | f"Total compile time {total_time:.1f}ms exceeds threshold {max_total}ms" |
| 643 | ) |
| 644 | |
| 645 | # Print results |
| 646 | if errors: |
| 647 | print("\n❌ ERRORS:", file=sys.stderr) |
| 648 | for error in errors: |
| 649 | print(f" - {error}", file=sys.stderr) |
| 650 | else: |
| 651 | print( |
| 652 | f"\n✓ All threshold checks passed - Total compile time: {total_time:.1f}ms (threshold: {max_total}ms)", |
| 653 | file=sys.stderr, |
| 654 | ) |
| 655 | |
| 656 | return len(errors) == 0 |
| 657 | |
| 658 | |
| 659 | def main() -> None: |