Skip to content

Commit 1231afe

Browse files
committed
=Q, move const to the base, not self.running
1 parent aecf40d commit 1231afe

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

Lib/profiling/sampling/binary_collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def collect(self, stack_frames, timestamp_us=None):
8181
timestamp_us: Optional timestamp in microseconds. If not provided,
8282
uses time.monotonic() to generate one.
8383
"""
84+
if not self.running:
85+
return
8486
if timestamp_us is None:
8587
timestamp_us = int(time.monotonic() * 1_000_000)
8688
try:

Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ def samples_to_by_thread(samples):
145145
class BinaryFormatTestBase(unittest.TestCase):
146146
"""Base class with common setup/teardown for binary format tests."""
147147

148+
HDR_OFF_SAMPLES = 28
149+
HDR_OFF_THREADS = 36
150+
HDR_OFF_STR_TABLE = 40
151+
HDR_OFF_FRAME_TABLE = 48
152+
FILE_HEADER_PLACEHOLDER_SIZE = 64
153+
148154
def setUp(self):
149155
self.temp_files = []
150156

@@ -1035,11 +1041,13 @@ def write_sample(self, stack_frames, timestamp_us):
10351041
collector.export(None)
10361042

10371043
with open(filename, "rb") as f:
1038-
header = f.read(32)
1044+
header = f.read(self.FILE_HEADER_PLACEHOLDER_SIZE)
10391045
magic, version = struct.unpack_from("=II", header, 0)
10401046
self.assertEqual(magic, 0x54414348) # "TACH"
10411047
self.assertEqual(version, 1)
1042-
(sample_count,) = struct.unpack_from("=I", header, 28)
1048+
(sample_count,) = struct.unpack_from(
1049+
"=Q", header, self.HDR_OFF_SAMPLES
1050+
)
10431051
self.assertEqual(sample_count, 3)
10441052

10451053
reader_collector = RawCollector()
@@ -1077,11 +1085,6 @@ def test_interpreter_id_overflow_rejected(self):
10771085
class TestBinaryFormatValidation(BinaryFormatTestBase):
10781086
"""Tests for malformed binary files."""
10791087

1080-
HDR_OFF_SAMPLES = 28
1081-
HDR_OFF_THREADS = 36
1082-
HDR_OFF_STR_TABLE = 40
1083-
HDR_OFF_FRAME_TABLE = 48
1084-
FILE_HEADER_PLACEHOLDER_SIZE = 64
10851088
FILE_FOOTER_SIZE = 32
10861089
FTR_OFF_STRINGS = 0
10871090
FTR_OFF_FRAMES = 4

0 commit comments

Comments
 (0)