()
| 818 | |
| 819 | |
| 820 | def _main(): |
| 821 | # Create the main parser |
| 822 | parser = argparse.ArgumentParser( |
| 823 | description=_HELP_DESCRIPTION, |
| 824 | formatter_class=CustomFormatter, |
| 825 | ) |
| 826 | |
| 827 | # Create subparsers for commands |
| 828 | subparsers = parser.add_subparsers( |
| 829 | dest="command", required=True, help="Command to run" |
| 830 | ) |
| 831 | |
| 832 | # === RUN COMMAND === |
| 833 | run_parser = subparsers.add_parser( |
| 834 | "run", |
| 835 | help="Run and profile a script or module", |
| 836 | formatter_class=CustomFormatter, |
| 837 | description="""Run and profile a Python script or module |
| 838 | |
| 839 | Examples: |
| 840 | # Run and profile a module |
| 841 | `python -m profiling.sampling run -m mymodule arg1 arg2` |
| 842 | |
| 843 | # Generate flamegraph from a script |
| 844 | `python -m profiling.sampling run --flamegraph -o output.html script.py` |
| 845 | |
| 846 | # Profile with custom rate and duration |
| 847 | `python -m profiling.sampling run -r 5khz -d 30 script.py` |
| 848 | |
| 849 | # Save collapsed stacks to file |
| 850 | `python -m profiling.sampling run --collapsed -o stacks.txt script.py` |
| 851 | |
| 852 | # Live interactive mode for a script |
| 853 | `python -m profiling.sampling run --live script.py`""", |
| 854 | ) |
| 855 | run_parser.add_argument( |
| 856 | "-m", |
| 857 | "--module", |
| 858 | action="store_true", |
| 859 | help="Run target as a module (like python -m)", |
| 860 | ) |
| 861 | run_parser.add_argument( |
| 862 | "target", |
| 863 | help="Script file or module name to profile", |
| 864 | ) |
| 865 | run_parser.add_argument( |
| 866 | "args", |
| 867 | nargs=argparse.REMAINDER, |
| 868 | help="Arguments to pass to the script or module", |
| 869 | ) |
| 870 | run_parser.add_argument( |
| 871 | "--live", |
| 872 | action="store_true", |
| 873 | help="Interactive TUI profiler (top-like interface, press 'q' to quit, 's' to cycle sort)", |
| 874 | ) |
| 875 | _add_sampling_options(run_parser) |
| 876 | _add_mode_options(run_parser) |
| 877 | _add_format_options(run_parser) |
no test coverage detected
searching dependent graphs…