Index: runtime/vm/timeline.cc |
diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc |
index d29b057d87380267231fe153c4830eb2cbccdc51..d2cb26cef0fe24204917450c541f5c673491651c 100644 |
--- a/runtime/vm/timeline.cc |
+++ b/runtime/vm/timeline.cc |
@@ -420,10 +420,14 @@ TimelineEventRingRecorder::~TimelineEventRingRecorder() { |
void TimelineEventRingRecorder::PrintJSONEvents(JSONArray* events) const { |
- // TODO(johnmccutchan): This output needs to start with the oldest block |
- // first. |
+ intptr_t block_offset = FindOldestBlockIndex(); |
+ if (block_offset == -1) { |
+ // All blocks are empty. |
+ return; |
+ } |
for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { |
- TimelineEventBlock* block = blocks_[block_idx]; |
+ TimelineEventBlock* block = |
+ blocks_[(block_idx + block_offset) % num_blocks_]; |
if (block->IsEmpty()) { |
// Skip empty blocks. |
continue; |
@@ -471,6 +475,24 @@ TimelineEventBlock* TimelineEventRingRecorder::GetNewBlockLocked() { |
} |
+intptr_t TimelineEventRingRecorder::FindOldestBlockIndex() const { |
+ int64_t earliest_time = kMaxInt64; |
+ 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. |
+ continue; |
+ } |
+ if (block->LowerTimeBound() < earliest_time) { |
+ earliest_time = block->LowerTimeBound(); |
+ earliest_index = block_idx; |
+ } |
+ } |
+ return earliest_index; |
+} |
+ |
+ |
void TimelineEventRingRecorder::VisitObjectPointers( |
ObjectPointerVisitor* visitor) { |
visitor->VisitPointer(reinterpret_cast<RawObject**>(&event_objects_)); |