MCPcopy Index your code
hub / github.com/python/cpython / _main

Function _main

Lib/profiling/sampling/cli.py:820–951  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

818
819
820def _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
839Examples:
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)

Callers 1

mainFunction · 0.70

Calls 12

add_subparsersMethod · 0.95
parse_argsMethod · 0.95
errorMethod · 0.95
_add_sampling_optionsFunction · 0.85
_add_mode_optionsFunction · 0.85
_add_format_optionsFunction · 0.85
_add_pstats_optionsFunction · 0.85
_validate_argsFunction · 0.85
handlerFunction · 0.85
add_parserMethod · 0.80
add_argumentMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…