| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,8 @@ def collect(self, stack_frames, timestamp_us=None): | |||
| 81 | 81 | timestamp_us: Optional timestamp in microseconds. If not provided, | |
| 82 | 82 | uses time.monotonic() to generate one. | |
| 83 | 83 | """ | |
| 84 | + if not self.running: | ||
| 85 | + return | ||
| 84 | 86 | if timestamp_us is None: | |
| 85 | 87 | timestamp_us = int(time.monotonic() * 1_000_000) | |
| 86 | 88 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,6 +145,12 @@ def samples_to_by_thread(samples): | |||
| 145 | 145 | class BinaryFormatTestBase(unittest.TestCase): | |
| 146 | 146 | """Base class with common setup/teardown for binary format tests.""" | |
| 147 | 147 | ||
| 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 | + | ||
| 148 | 154 | def setUp(self): | |
| 149 | 155 | self.temp_files = [] | |
| 150 | 156 | ||
@@ -1035,11 +1041,13 @@ def write_sample(self, stack_frames, timestamp_us): | |||
| 1035 | 1041 | collector.export(None) | |
| 1036 | 1042 | ||
| 1037 | 1043 | with open(filename, "rb") as f: | |
| 1038 | - header = f.read(32) | ||
| 1044 | + header = f.read(self.FILE_HEADER_PLACEHOLDER_SIZE) | ||
| 1039 | 1045 | magic, version = struct.unpack_from("=II", header, 0) | |
| 1040 | 1046 | self.assertEqual(magic, 0x54414348) # "TACH" | |
| 1041 | 1047 | 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 | + ) | ||
| 1043 | 1051 | self.assertEqual(sample_count, 3) | |
| 1044 | 1052 | ||
| 1045 | 1053 | reader_collector = RawCollector() | |
@@ -1077,11 +1085,6 @@ def test_interpreter_id_overflow_rejected(self): | |||
| 1077 | 1085 | class TestBinaryFormatValidation(BinaryFormatTestBase): | |
| 1078 | 1086 | """Tests for malformed binary files.""" | |
| 1079 | 1087 | ||
| 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 | ||
| 1085 | 1088 | FILE_FOOTER_SIZE = 32 | |
| 1086 | 1089 | FTR_OFF_STRINGS = 0 | |
| 1087 | 1090 | FTR_OFF_FRAMES = 4 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments