[VM/Timeline] Correctly skip over blocks that are in use when serializing the timeline

TEST=TSAN, ASAN

Change-Id: I3b106c8f0bf3fef5fec8f9fd7146a13401ab9448
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299761
Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Derek Xu 2023-05-01 14:52:30 +00:00 committed by Commit Queue
parent c4f31a9108
commit 0606c58fde
2 changed files with 12 additions and 14 deletions

View file

@ -1592,7 +1592,7 @@ void TimelineEventFixedBufferRecorder::PrintEventsCommon(
ResetTimeTracking();
intptr_t block_offset = FindOldestBlockIndex();
if (block_offset == -1) {
// All blocks are empty.
// All blocks are in use or empty.
return;
}
for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) {
@ -1697,8 +1697,11 @@ intptr_t TimelineEventFixedBufferRecorder::FindOldestBlockIndex() const {
intptr_t earliest_index = -1;
for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) {
TimelineEventBlock* block = &blocks_[block_idx];
if (block->IsEmpty()) {
// Skip empty blocks.
if (block->in_use() || block->IsEmpty()) {
// Skip in use and empty blocks. |block->in_use()| must be checked first
// because we are only holding |lock_|. Holding |lock_| makes it safe to
// call |in_use()| on any block, but only makes it safe to call
// |IsEmpty()| on blocks that are not in use.
continue;
}
if (block->LowerTimeBound() < earliest_time) {

View file

@ -833,12 +833,15 @@ class TimelineEventFilter : public ValueObject {
virtual ~TimelineEventFilter();
virtual bool IncludeBlock(TimelineEventBlock* block) const {
bool IncludeBlock(TimelineEventBlock* block) const {
if (block == nullptr) {
return false;
}
// Not empty and not in use.
return !block->IsEmpty() && !block->in_use();
// Check that the block is not in use and not empty. |!block->in_use()| must
// be checked first because we are only holding |lock_|. Holding |lock_|
// makes it safe to call |in_use()| on any block, but only makes it safe to
// call |IsEmpty()| on blocks that are not in use.
return !block->in_use() && !block->IsEmpty();
}
virtual bool IncludeEvent(TimelineEvent* event) const {
@ -863,14 +866,6 @@ class IsolateTimelineEventFilter : public TimelineEventFilter {
int64_t time_origin_micros = -1,
int64_t time_extent_micros = -1);
bool IncludeBlock(TimelineEventBlock* block) const final {
if (block == nullptr) {
return false;
}
// Not empty, not in use, and isolate match.
return !block->IsEmpty() && !block->in_use();
}
bool IncludeEvent(TimelineEvent* event) const final {
return event->IsValid() && (event->isolate_id() == isolate_id_);
}