From 0e80de8b3d9fcea9e668bdaf8b17f78a266be789 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 12 Dec 2025 12:17:46 -0800 Subject: [PATCH 1/2] Use backticks and clean up styles --- Lib/profiling/sampling/cli.py | 49 +++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/Lib/profiling/sampling/cli.py b/Lib/profiling/sampling/cli.py index 3a0444db4c3636..a34713e7cc3c4c 100644 --- a/Lib/profiling/sampling/cli.py +++ b/Lib/profiling/sampling/cli.py @@ -41,24 +41,20 @@ class CustomFormatter( _HELP_DESCRIPTION = """Sample a process's stack frames and generate profiling data. -Commands: - run Run and profile a script or module - attach Attach to and profile a running process - Examples: # Run and profile a script - python -m profiling.sampling run script.py arg1 arg2 + `python -m profiling.sampling run script.py arg1 arg2` # Attach to a running process - python -m profiling.sampling attach 1234 + `python -m profiling.sampling attach 1234` # Live interactive mode for a script - python -m profiling.sampling run --live script.py + `python -m profiling.sampling run --live script.py` # Live interactive mode for a running process - python -m profiling.sampling attach --live 1234 + `python -m profiling.sampling attach --live 1234` -Use 'python -m profiling.sampling --help' for command-specific help.""" +Use `python -m profiling.sampling --help` for command-specific help.""" # Constants for socket synchronization @@ -490,6 +486,13 @@ def main(): parser = argparse.ArgumentParser( description=_HELP_DESCRIPTION, formatter_class=CustomFormatter, + add_help=False, + ) + parser.add_argument( + "-h", "--help", + action="help", + default=argparse.SUPPRESS, + help="Show this help message and exit", ) # Create subparsers for commands @@ -502,23 +505,30 @@ def main(): "run", help="Run and profile a script or module", formatter_class=CustomFormatter, + add_help=False, description="""Run and profile a Python script or module Examples: # Run and profile a module - python -m profiling.sampling run -m mymodule arg1 arg2 + `python -m profiling.sampling run -m mymodule arg1 arg2` # Generate flamegraph from a script - python -m profiling.sampling run --flamegraph -o output.html script.py + `python -m profiling.sampling run --flamegraph -o output.html script.py` # Profile with custom interval and duration - python -m profiling.sampling run -i 50 -d 30 script.py + `python -m profiling.sampling run -i 50 -d 30 script.py` # Save collapsed stacks to file - python -m profiling.sampling run --collapsed -o stacks.txt script.py + `python -m profiling.sampling run --collapsed -o stacks.txt script.py` # Live interactive mode for a script - python -m profiling.sampling run --live script.py""", + `python -m profiling.sampling run --live script.py`""", + ) + run_parser.add_argument( + "-h", "--help", + action="help", + default=argparse.SUPPRESS, + help="Show this help message and exit", ) run_parser.add_argument( "-m", @@ -550,14 +560,21 @@ def main(): "attach", help="Attach to and profile a running process", formatter_class=CustomFormatter, + add_help=False, description="""Attach to a running process and profile it Examples: # Profile all threads, sort by total time - python -m profiling.sampling attach -a --sort tottime 1234 + `python -m profiling.sampling attach -a --sort tottime 1234` # Live interactive mode for a running process - python -m profiling.sampling attach --live 1234""", + `python -m profiling.sampling attach --live 1234`""", + ) + attach_parser.add_argument( + "-h", "--help", + action="help", + default=argparse.SUPPRESS, + help="Show this help message and exit", ) attach_parser.add_argument( "pid", From 1accb7b592905df7e9d8b3d165cc21389d79966e Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 12 Dec 2025 12:35:10 -0800 Subject: [PATCH 2/2] Cleanup --- Lib/profiling/sampling/cli.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Lib/profiling/sampling/cli.py b/Lib/profiling/sampling/cli.py index a34713e7cc3c4c..2bb4f31efe17be 100644 --- a/Lib/profiling/sampling/cli.py +++ b/Lib/profiling/sampling/cli.py @@ -486,13 +486,6 @@ def main(): parser = argparse.ArgumentParser( description=_HELP_DESCRIPTION, formatter_class=CustomFormatter, - add_help=False, - ) - parser.add_argument( - "-h", "--help", - action="help", - default=argparse.SUPPRESS, - help="Show this help message and exit", ) # Create subparsers for commands @@ -505,7 +498,6 @@ def main(): "run", help="Run and profile a script or module", formatter_class=CustomFormatter, - add_help=False, description="""Run and profile a Python script or module Examples: @@ -524,12 +516,6 @@ def main(): # Live interactive mode for a script `python -m profiling.sampling run --live script.py`""", ) - run_parser.add_argument( - "-h", "--help", - action="help", - default=argparse.SUPPRESS, - help="Show this help message and exit", - ) run_parser.add_argument( "-m", "--module", @@ -560,7 +546,6 @@ def main(): "attach", help="Attach to and profile a running process", formatter_class=CustomFormatter, - add_help=False, description="""Attach to a running process and profile it Examples: @@ -570,12 +555,6 @@ def main(): # Live interactive mode for a running process `python -m profiling.sampling attach --live 1234`""", ) - attach_parser.add_argument( - "-h", "--help", - action="help", - default=argparse.SUPPRESS, - help="Show this help message and exit", - ) attach_parser.add_argument( "pid", type=int,