@@ -41,24 +41,20 @@ class CustomFormatter(
4141
4242_HELP_DESCRIPTION = """Sample a process's stack frames and generate profiling data.
4343
44- Commands:
45- run Run and profile a script or module
46- attach Attach to and profile a running process
47-
4844Examples:
4945 # Run and profile a script
50- python -m profiling.sampling run script.py arg1 arg2
46+ ` python -m profiling.sampling run script.py arg1 arg2`
5147
5248 # Attach to a running process
53- python -m profiling.sampling attach 1234
49+ ` python -m profiling.sampling attach 1234`
5450
5551 # Live interactive mode for a script
56- python -m profiling.sampling run --live script.py
52+ ` python -m profiling.sampling run --live script.py`
5753
5854 # Live interactive mode for a running process
59- python -m profiling.sampling attach --live 1234
55+ ` python -m profiling.sampling attach --live 1234`
6056
61- Use ' python -m profiling.sampling <command> --help' for command-specific help."""
57+ Use ` python -m profiling.sampling <command> --help` for command-specific help."""
6258
6359
6460# Constants for socket synchronization
@@ -490,6 +486,13 @@ def main():
490486 parser = argparse .ArgumentParser (
491487 description = _HELP_DESCRIPTION ,
492488 formatter_class = CustomFormatter ,
489+ add_help = False ,
490+ )
491+ parser .add_argument (
492+ "-h" , "--help" ,
493+ action = "help" ,
494+ default = argparse .SUPPRESS ,
495+ help = "Show this help message and exit" ,
493496 )
494497
495498 # Create subparsers for commands
@@ -502,23 +505,30 @@ def main():
502505 "run" ,
503506 help = "Run and profile a script or module" ,
504507 formatter_class = CustomFormatter ,
508+ add_help = False ,
505509 description = """Run and profile a Python script or module
506510
507511Examples:
508512 # Run and profile a module
509- python -m profiling.sampling run -m mymodule arg1 arg2
513+ ` python -m profiling.sampling run -m mymodule arg1 arg2`
510514
511515 # Generate flamegraph from a script
512- python -m profiling.sampling run --flamegraph -o output.html script.py
516+ ` python -m profiling.sampling run --flamegraph -o output.html script.py`
513517
514518 # Profile with custom interval and duration
515- python -m profiling.sampling run -i 50 -d 30 script.py
519+ ` python -m profiling.sampling run -i 50 -d 30 script.py`
516520
517521 # Save collapsed stacks to file
518- python -m profiling.sampling run --collapsed -o stacks.txt script.py
522+ ` python -m profiling.sampling run --collapsed -o stacks.txt script.py`
519523
520524 # Live interactive mode for a script
521- python -m profiling.sampling run --live script.py""" ,
525+ `python -m profiling.sampling run --live script.py`""" ,
526+ )
527+ run_parser .add_argument (
528+ "-h" , "--help" ,
529+ action = "help" ,
530+ default = argparse .SUPPRESS ,
531+ help = "Show this help message and exit" ,
522532 )
523533 run_parser .add_argument (
524534 "-m" ,
@@ -550,14 +560,21 @@ def main():
550560 "attach" ,
551561 help = "Attach to and profile a running process" ,
552562 formatter_class = CustomFormatter ,
563+ add_help = False ,
553564 description = """Attach to a running process and profile it
554565
555566Examples:
556567 # Profile all threads, sort by total time
557- python -m profiling.sampling attach -a --sort tottime 1234
568+ ` python -m profiling.sampling attach -a --sort tottime 1234`
558569
559570 # Live interactive mode for a running process
560- python -m profiling.sampling attach --live 1234""" ,
571+ `python -m profiling.sampling attach --live 1234`""" ,
572+ )
573+ attach_parser .add_argument (
574+ "-h" , "--help" ,
575+ action = "help" ,
576+ default = argparse .SUPPRESS ,
577+ help = "Show this help message and exit" ,
561578 )
562579 attach_parser .add_argument (
563580 "pid" ,
0 commit comments