FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-158550: `_remote_debugging`: Do not advance `prev_timestamp` when `write_sample` fails by maurycy · Pull Request #158551 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL