()
| 599 | |
| 600 | |
| 601 | def main() -> None: |
| 602 | parser = argparse.ArgumentParser( |
| 603 | description="Measure PHPantom LSP memory usage (RSS).", |
| 604 | ) |
| 605 | parser.add_argument( |
| 606 | "--binary", |
| 607 | default=None, |
| 608 | help="Path to the phpantom_lsp binary. Auto-detected if omitted.", |
| 609 | ) |
| 610 | parser.add_argument( |
| 611 | "--scenario", |
| 612 | choices=["hello_world", "laravel_model", "all"], |
| 613 | default="all", |
| 614 | help="Which scenario to run (default: all).", |
| 615 | ) |
| 616 | parser.add_argument( |
| 617 | "--work-dir", |
| 618 | default=None, |
| 619 | help=( |
| 620 | "Working directory for temporary files. " |
| 621 | "A temp dir is used if omitted." |
| 622 | ), |
| 623 | ) |
| 624 | |
| 625 | args = parser.parse_args() |
| 626 | |
| 627 | binary = args.binary or find_binary() |
| 628 | if not binary: |
| 629 | print( |
| 630 | "Error: could not find phpantom_lsp binary. Use --binary.", |
| 631 | file=sys.stderr, |
| 632 | ) |
| 633 | sys.exit(1) |
| 634 | |
| 635 | binary = os.path.abspath(binary) |
| 636 | print(f"Using binary: {binary}", file=sys.stderr) |
| 637 | |
| 638 | # Verify the binary works. |
| 639 | try: |
| 640 | result = subprocess.run( |
| 641 | [binary, "--version"], |
| 642 | capture_output=True, |
| 643 | text=True, |
| 644 | timeout=10, |
| 645 | ) |
| 646 | version = result.stdout.strip() or result.stderr.strip() |
| 647 | print(f"Version: {version}", file=sys.stderr) |
| 648 | except Exception as e: |
| 649 | print(f"Warning: could not get version: {e}", file=sys.stderr) |
| 650 | |
| 651 | use_temp = args.work_dir is None |
| 652 | work_dir = args.work_dir or tempfile.mkdtemp(prefix="phpantom_mem_") |
| 653 | os.makedirs(work_dir, exist_ok=True) |
| 654 | |
| 655 | results: dict[str, int] = {} |
| 656 | |
| 657 | try: |
| 658 | if args.scenario in ("hello_world", "all"): |
no test coverage detected