Parse command line arguments
()
| 313 | |
| 314 | |
| 315 | def parse_arguments(): |
| 316 | """Parse command line arguments""" |
| 317 | # Build the code examples description |
| 318 | examples_desc = "\n".join( |
| 319 | [f" {name}: {info['description']}" for name, info in CODE_EXAMPLES.items()] |
| 320 | ) |
| 321 | |
| 322 | parser = argparse.ArgumentParser( |
| 323 | description="Benchmark get_stack_trace() performance", |
| 324 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 325 | epilog=f""" |
| 326 | Examples: |
| 327 | %(prog)s # Run basic benchmark for 10 seconds (default) |
| 328 | %(prog)s --duration 30 # Run basic benchmark for 30 seconds |
| 329 | %(prog)s -d 60 # Run basic benchmark for 60 seconds |
| 330 | %(prog)s --code deep_static # Run deep static call stack benchmark |
| 331 | %(prog)s --code deep_static -d 30 # Run deep static benchmark for 30 seconds |
| 332 | |
| 333 | Available code examples: |
| 334 | {examples_desc} |
| 335 | """, |
| 336 | color=True, |
| 337 | ) |
| 338 | |
| 339 | parser.add_argument( |
| 340 | "--duration", |
| 341 | "-d", |
| 342 | type=int, |
| 343 | default=10, |
| 344 | help="Benchmark duration in seconds (default: 10)", |
| 345 | ) |
| 346 | |
| 347 | parser.add_argument( |
| 348 | "--code", |
| 349 | "-c", |
| 350 | choices=list(CODE_EXAMPLES.keys()), |
| 351 | default="basic", |
| 352 | help="Code example to benchmark (default: basic)", |
| 353 | ) |
| 354 | |
| 355 | parser.add_argument( |
| 356 | "--threads", |
| 357 | choices=["all", "main", "only_active"], |
| 358 | default="all", |
| 359 | help="Which threads to include in the benchmark (default: all)", |
| 360 | ) |
| 361 | |
| 362 | parser.add_argument( |
| 363 | "--blocking", |
| 364 | action="store_true", |
| 365 | help="Stop all threads before sampling for consistent snapshots", |
| 366 | ) |
| 367 | |
| 368 | return parser.parse_args() |
| 369 | |
| 370 | |
| 371 | def create_target_process(temp_file, code_example="basic"): |
no test coverage detected
searching dependent graphs…