Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,26 @@ def test_writer_handles_mixed_empty_and_real_first_sample(self):
self.assertIn((0, 1), reader_collector.by_thread)
self.assertEqual(len(reader_collector.by_thread[(0, 1)]), 2)

def test_writer_failed_sample_does_not_advance_timestamp(self):
"""A rejected frame must not shift later timestamps."""
with tempfile.NamedTemporaryFile(suffix=".bin", delete=False) as f:
filename = f.name
self.temp_files.append(filename)

good = [make_interpreter(0, [make_thread(1, [make_frame("a.py", 1, "f")])])]
bad = [make_interpreter(0, [make_thread(1, [make_frame(42, 1, "f")])])]

with _remote_debugging.BinaryWriter(filename, 1000, 0) as writer:
writer.write_sample(good, 1000)
with self.assertRaises(TypeError):
writer.write_sample(bad, 5000)
writer.write_sample(good, 6000)

collector = TimestampCollector()
with BinaryReader(filename) as reader:
reader.replay_samples(collector)
self.assertEqual(collector.all_timestamps, [1000, 6000])

def test_writer_total_samples_after_finalize_matches_reader(self):
"""BinaryWriter.total_samples after finalize() matches the reader's count."""
# Five IDENTICAL samples force every sample beyond the first into the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrect timestamps in Tachyon binary profiles after a sample fails to be
written. Patch by Maurycy Pawłowski-Wieronski.
2 changes: 1 addition & 1 deletion Modules/_remote_debugging/binary_io_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ process_thread_sample(BinaryWriter *writer, PyObject *thread_info,

/* Calculate timestamp delta */
uint64_t delta = timestamp_us - entry->prev_timestamp;
entry->prev_timestamp = timestamp_us;

/* Process frames and build current stack */
uint32_t curr_stack[MAX_STACK_DEPTH];
Expand Down Expand Up @@ -1006,6 +1005,7 @@ process_thread_sample(BinaryWriter *writer, PyObject *thread_info,
entry->prev_stack_depth = curr_depth;
}

entry->prev_timestamp = timestamp_us;
writer->total_samples++;
return 0;
}
Expand Down
Loading