()
| 689 | |
| 690 | |
| 691 | def main(): |
| 692 | parser = argparse.ArgumentParser( |
| 693 | description="WASM binary size analysis with flamegraph output.", |
| 694 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 695 | epilog="""\ |
| 696 | examples: |
| 697 | %(prog)s Build & analyze (analysis profile) |
| 698 | %(prog)s --skip-build Reuse previous build artifacts |
| 699 | %(prog)s --top 15 Show top 15 items per section |
| 700 | %(prog)s --profile release-debug Match exact release binary |
| 701 | |
| 702 | output: |
| 703 | target/wasm-analysis/report.txt Text summary |
| 704 | target/wasm-analysis/code-flamegraph.svg Interactive code size flamegraph |
| 705 | target/wasm-analysis/data-flamegraph.svg Interactive data size flamegraph |
| 706 | target/wasm-analysis/combined-flamegraph.svg Combined flamegraph |
| 707 | """, |
| 708 | ) |
| 709 | parser.add_argument( |
| 710 | "--skip-build", action="store_true", |
| 711 | help="reuse existing build artifacts (skip cargo build)", |
| 712 | ) |
| 713 | parser.add_argument( |
| 714 | "--profile", |
| 715 | choices=["analysis", "release-debug"], |
| 716 | default="analysis", |
| 717 | help="build profile: 'analysis' (default, matches release DCE) or " |
| 718 | "'release-debug' (overrides release profile with debug info)", |
| 719 | ) |
| 720 | parser.add_argument( |
| 721 | "--top", type=int, default=30, metavar="N", |
| 722 | help="number of top items to show per section (default: 30)", |
| 723 | ) |
| 724 | parser.add_argument( |
| 725 | "--output-dir", type=Path, default=None, metavar="DIR", |
| 726 | help="output directory (default: target/wasm-analysis/)", |
| 727 | ) |
| 728 | parser.add_argument( |
| 729 | "--indent", type=int, default=0, metavar="N", |
| 730 | help="indent all output by N spaces (e.g. 4 for commit messages)", |
| 731 | ) |
| 732 | args = parser.parse_args() |
| 733 | |
| 734 | global _INDENT |
| 735 | _INDENT = " " * args.indent |
| 736 | |
| 737 | output_dir = args.output_dir or TARGET_DIR / "wasm-analysis" |
| 738 | output_dir.mkdir(parents=True, exist_ok=True) |
| 739 | |
| 740 | total_steps = 5 |
| 741 | |
| 742 | # ── Step 0: Check tools ───────────────────────────────────────────── |
| 743 | check_tools() |
| 744 | |
| 745 | # ── Step 1: Build ─────────────────────────────────────────────────── |
| 746 | cargo_profile = "release" if args.profile == "release-debug" else args.profile |
| 747 | wasm_path = TARGET_DIR / "wasm32-wasip2" / cargo_profile / "vercel_python_analysis.wasm" |
| 748 | map_path = output_dir / "wasm.map" |
no test coverage detected