Main entry point.
()
| 657 | |
| 658 | |
| 659 | def main() -> None: |
| 660 | """Main entry point.""" |
| 661 | # Parse arguments |
| 662 | args = sys.argv[1:] |
| 663 | output_format = "text" |
| 664 | save_trace = False |
| 665 | compiler = "clang++" |
| 666 | threshold = 50.0 |
| 667 | check_thresholds_only = False |
| 668 | |
| 669 | for arg in args: |
| 670 | if arg.startswith("--output="): |
| 671 | output_format = arg.split("=", 1)[1] |
| 672 | elif arg == "--save-trace": |
| 673 | save_trace = True |
| 674 | elif arg.startswith("--compiler="): |
| 675 | compiler = arg.split("=", 1)[1] |
| 676 | elif arg.startswith("--threshold="): |
| 677 | threshold = float(arg.split("=", 1)[1]) |
| 678 | elif arg == "--check-thresholds": |
| 679 | check_thresholds_only = True |
| 680 | elif arg in ["--help", "-h"]: |
| 681 | print(__doc__) |
| 682 | sys.exit(0) |
| 683 | |
| 684 | # Find project root and source file |
| 685 | script_dir = Path(__file__).parent |
| 686 | project_root = script_dir.parent.parent |
| 687 | source_file = script_dir / "test_compile.cpp" |
| 688 | thresholds_file = script_dir / "thresholds.json" |
| 689 | |
| 690 | if not source_file.exists(): |
| 691 | print(f"Error: Test file not found at {source_file}") |
| 692 | sys.exit(1) |
| 693 | |
| 694 | # Store compiler in env for report |
| 695 | os.environ["COMPILER"] = compiler |
| 696 | |
| 697 | # Compile with trace |
| 698 | print("Compiling test file with -ftime-trace...", file=sys.stderr) |
| 699 | trace_file = compile_with_trace( |
| 700 | source_file, compiler, include_dir=project_root / "src" |
| 701 | ) |
| 702 | |
| 703 | print(f"Trace file generated: {trace_file}", file=sys.stderr) |
| 704 | |
| 705 | # Parse trace |
| 706 | print("Analyzing trace data...", file=sys.stderr) |
| 707 | analyzer = CompilePerfAnalyzer(str(trace_file)) |
| 708 | |
| 709 | # Check thresholds if requested |
| 710 | if check_thresholds_only: |
| 711 | success = check_thresholds(analyzer, thresholds_file) |
| 712 | sys.exit(0 if success else 1) |
| 713 | |
| 714 | # Generate report |
| 715 | report = analyzer.generate_report(output_format, threshold) |
| 716 | print(report) |
no test coverage detected