Skip to content

Commit 71c6b97

Browse files
committed
skip sample_interval_usec in v0
1 parent 1bc72ec commit 71c6b97

4 files changed

Lines changed: 16 additions & 40 deletions

File tree

Lib/profiling/sampling/_control.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class ProfilerControl:
1212
def __init__(self):
1313
self.enabled = True
1414
self.running = True
15-
self.sample_interval_usec = 0
1615

1716

1817
def parse_control_uri(uri, *, allowed_schemes=("unix",)):
@@ -188,10 +187,7 @@ def _dispatch(self, conn, command):
188187
case "ping":
189188
reply = "ok\n"
190189
case "status":
191-
reply = (
192-
f"ok enabled={self.control.enabled} "
193-
f"rate_usec={self.control.sample_interval_usec}\n"
194-
)
190+
reply = f"ok enabled={self.control.enabled}\n"
195191
case "quit":
196192
self.control.running = False
197193
conn.close_after_write = True

Lib/profiling/sampling/sample.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ def sample(
125125
pending_timestamps = [] if aggregating else None
126126

127127
control = control_server.control if control_server is not None else None
128-
if control is not None:
129-
control.sample_interval_usec = self.sample_interval_usec
130128

131129
def flush_pending():
132130
nonlocal pending_count, pending_timestamps

Lib/test/test_profiling/test_sampling_profiler/test_control.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,12 @@ def test_dispatch_basic_commands(self):
110110
self.assertEqual(server.control.enabled, expected_enabled)
111111

112112
def test_dispatch_status_format(self):
113-
"""status reply exposes enabled and rate_usec."""
113+
"""status reply exposes the enabled flag."""
114114
server = self.start_server()
115-
server.control.sample_interval_usec = 1000
116115
client = self.connect()
117116
self.assertEqual(
118117
self.request(server, client, b"status\n"),
119-
b"ok enabled=True rate_usec=1000\n",
118+
b"ok enabled=True\n",
120119
)
121120

122121
def test_dispatch_quit_sets_running_and_closes(self):
@@ -163,8 +162,11 @@ def test_close_listener_preserves_replaced_path(self):
163162
def test_cli_rejects_control_with_subprocesses(self):
164163
"""--control and --subprocesses are mutually exclusive."""
165164
argv = [
166-
"profiling.sampling.cli", "attach",
167-
"--subprocesses", "--control", "unix:/tmp/x.sock",
165+
"profiling.sampling.cli",
166+
"attach",
167+
"--subprocesses",
168+
"--control",
169+
"unix:/tmp/x.sock",
168170
"123",
169171
]
170172
with (
@@ -181,8 +183,11 @@ def test_cli_rejects_control_with_subprocesses(self):
181183
def test_cli_rejects_bad_uri(self):
182184
"""An unsupported control URI scheme is rejected during validation."""
183185
argv = [
184-
"profiling.sampling.cli", "attach",
185-
"--control", "fifo:/tmp/x", "123",
186+
"profiling.sampling.cli",
187+
"attach",
188+
"--control",
189+
"fifo:/tmp/x",
190+
"123",
186191
]
187192
with (
188193
mock.patch("sys.argv", argv),

Lib/test/test_profiling/test_sampling_profiler/test_profiler.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -436,30 +436,11 @@ def test_sample_profiler_keyboard_interrupt(self):
436436
@staticmethod
437437
def _fake_control_server(*, enabled=True, running=True):
438438
"""Build a minimal control_server stub for sample() integration."""
439-
control = types.SimpleNamespace(
440-
enabled=enabled, running=running, sample_interval_usec=0,
441-
)
439+
control = types.SimpleNamespace(enabled=enabled, running=running)
442440
server = mock.MagicMock()
443441
server.control = control
444442
return server
445443

446-
def test_sample_passes_interval_to_control_server(self):
447-
"""Test that sample() copies its interval into control.sample_interval_usec."""
448-
control_server = self._fake_control_server(running=False)
449-
with self._patched_unwinder() as u:
450-
u.instance.get_stack_trace.return_value = []
451-
profiler = SampleProfiler(
452-
pid=12345, sample_interval_usec=4242, all_threads=False
453-
)
454-
with io.StringIO() as output:
455-
with mock.patch("sys.stdout", output):
456-
profiler.sample(
457-
mock.MagicMock(),
458-
duration_sec=10,
459-
control_server=control_server,
460-
)
461-
self.assertEqual(control_server.control.sample_interval_usec, 4242)
462-
463444
def test_sample_polls_control_server_periodically(self):
464445
"""Test that sample() drives control_server.poll() during the loop."""
465446
control_server = self._fake_control_server()
@@ -523,9 +504,7 @@ def test_sample_pauses_when_control_disabled(self):
523504

524505
def test_sample_resumes_after_re_enable(self):
525506
"""Test that sampling resumes when control flips from disabled to enabled."""
526-
control = types.SimpleNamespace(
527-
enabled=False, running=True, sample_interval_usec=0,
528-
)
507+
control = types.SimpleNamespace(enabled=False, running=True)
529508
control_server = mock.MagicMock()
530509
control_server.control = control
531510

@@ -556,9 +535,7 @@ def poll_side_effect(timeout=0):
556535

557536
def test_sample_rate_reflects_enabled_time(self):
558537
"""Test that Sample rate divides by enabled time, not wall time."""
559-
control = types.SimpleNamespace(
560-
enabled=False, running=True, sample_interval_usec=0,
561-
)
538+
control = types.SimpleNamespace(enabled=False, running=True)
562539
control_server = mock.MagicMock()
563540
control_server.control = control
564541

0 commit comments

Comments
 (0)