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

Function main

Tools/inspection/benchmark_external_inspection.py:407–484  ·  view source on GitHub ↗

Main benchmark function

()

Source from the content-addressed store, hash-verified

405
406
407def 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 )

Calls 10

get_colorsFunction · 0.90
can_colorizeFunction · 0.90
parse_argumentsFunction · 0.85
create_target_processFunction · 0.85
cleanup_processFunction · 0.85
print_benchmark_resultsFunction · 0.85
benchmarkFunction · 0.70
getMethod · 0.45
communicateMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…