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

Method test_get_stats

Lib/test/test_external_inspection.py:3521–3551  ·  view source on GitHub ↗

Test that get_stats() returns statistics when stats=True.

(self)

Source from the content-addressed store, hash-verified

3519 "Test only runs on Linux with process_vm_readv support",
3520 )
3521 def test_get_stats(self):
3522 """Test that get_stats() returns statistics when stats=True."""
3523 script_body = """\
3524 sock.sendall(b"ready")
3525 sock.recv(16)
3526 """
3527
3528 with self._target_process(script_body) as (p, client_socket, _):
3529 unwinder = RemoteUnwinder(p.pid, all_threads=True, stats=True)
3530 _wait_for_signal(client_socket, b"ready")
3531
3532 # Take a sample
3533 _get_stack_trace_with_retry(unwinder)
3534
3535 stats = unwinder.get_stats()
3536 client_socket.sendall(b"done")
3537
3538 # Verify expected keys exist
3539 expected_keys = [
3540 "total_samples",
3541 "frame_cache_hits",
3542 "frame_cache_misses",
3543 "frame_cache_partial_hits",
3544 "frames_read_from_cache",
3545 "frames_read_from_memory",
3546 "frame_cache_hit_rate",
3547 ]
3548 for key in expected_keys:
3549 self.assertIn(key, stats)
3550
3551 self.assertEqual(stats["total_samples"], 1)
3552
3553 @skip_if_not_supported
3554 @unittest.skipIf(

Callers

nothing calls this directly

Calls 7

_target_processMethod · 0.95
assertInMethod · 0.80
_wait_for_signalFunction · 0.70
get_statsMethod · 0.45
sendallMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected