Main benchmark function
()
| 405 | |
| 406 | |
| 407 | def main(): |
| 408 | """Main benchmark function""" |
| 409 | colors = get_colors(can_colorize()) |
| 410 | args = parse_arguments() |
| 411 | |
| 412 | print(f"{colors.BOLD_MAGENTA}External Inspection Benchmark Tool{colors.RESET}") |
| 413 | print(f"{colors.BOLD_MAGENTA}{'=' * 34}{colors.RESET}") |
| 414 | |
| 415 | example_info = CODE_EXAMPLES.get(args.code, {"description": "Unknown"}) |
| 416 | print( |
| 417 | f"\n{colors.CYAN}Code Example:{colors.RESET} {colors.GREEN}{args.code}{colors.RESET}" |
| 418 | ) |
| 419 | print(f"{colors.CYAN}Description:{colors.RESET} {example_info['description']}") |
| 420 | print( |
| 421 | f"{colors.CYAN}Benchmark Duration:{colors.RESET} {colors.YELLOW}{args.duration}{colors.RESET} seconds" |
| 422 | ) |
| 423 | print( |
| 424 | f"{colors.CYAN}Blocking Mode:{colors.RESET} {colors.GREEN if args.blocking else colors.YELLOW}{'enabled' if args.blocking else 'disabled'}{colors.RESET}" |
| 425 | ) |
| 426 | |
| 427 | process = None |
| 428 | temp_file_path = None |
| 429 | |
| 430 | try: |
| 431 | # Create target process |
| 432 | print(f"\n{colors.BLUE}Creating and starting target process...{colors.RESET}") |
| 433 | with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as temp_file: |
| 434 | process, temp_file_path = create_target_process(temp_file, args.code) |
| 435 | print( |
| 436 | f"{colors.GREEN}Target process started with PID: {colors.BOLD_WHITE}{process.pid}{colors.RESET}" |
| 437 | ) |
| 438 | |
| 439 | # Run benchmark with specified duration |
| 440 | with process: |
| 441 | # Create unwinder and run benchmark |
| 442 | print(f"{colors.BLUE}Initializing unwinder...{colors.RESET}") |
| 443 | try: |
| 444 | kwargs = {} |
| 445 | if args.threads == "all": |
| 446 | kwargs["all_threads"] = True |
| 447 | elif args.threads == "main": |
| 448 | kwargs["all_threads"] = False |
| 449 | elif args.threads == "only_active": |
| 450 | kwargs["only_active_thread"] = True |
| 451 | unwinder = _remote_debugging.RemoteUnwinder( |
| 452 | process.pid, cache_frames=True, **kwargs |
| 453 | ) |
| 454 | results = benchmark(unwinder, duration_seconds=args.duration, blocking=args.blocking) |
| 455 | finally: |
| 456 | cleanup_process(process, temp_file_path) |
| 457 | |
| 458 | # Print results |
| 459 | print_benchmark_results(results) |
| 460 | |
| 461 | except PermissionError as e: |
| 462 | print( |
| 463 | f"{colors.BOLD_RED}Error: Insufficient permissions to read stack trace: {e}{colors.RESET}" |
| 464 | ) |
no test coverage detected
searching dependent graphs…