Skip to content

Commit 33aaf94

Browse files
committed
Output TimelineEventBlocks in sorted order
- Before outputting to JSON sort TimelineEventBlocks by earliest event time. - Output using sorted block order. - Works around a bug in mojo (https://github.com/domokit/mojo/issues/649) [email protected] Review URL: https://codereview.chromium.org/1657843003 .
1 parent b3e588e commit 33aaf94

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

runtime/vm/timeline.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ void TimelineBeginEndScope::EmitBegin() {
721721
TimelineEvent* event = stream()->StartEvent();
722722
if (event == NULL) {
723723
// Stream is now disabled.
724+
set_enabled(false);
724725
return;
725726
}
726727
ASSERT(event != NULL);
@@ -737,6 +738,7 @@ void TimelineBeginEndScope::EmitEnd() {
737738
TimelineEvent* event = stream()->StartEvent();
738739
if (event == NULL) {
739740
// Stream is now disabled.
741+
set_enabled(false);
740742
return;
741743
}
742744
ASSERT(event != NULL);
@@ -1160,17 +1162,35 @@ TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlockLocked() {
11601162
return head_;
11611163
}
11621164

1165+
static int TimelineEventBlockCompare(TimelineEventBlock* const* a,
1166+
TimelineEventBlock* const* b) {
1167+
return (*a)->LowerTimeBound() - (*b)->LowerTimeBound();
1168+
}
1169+
11631170

11641171
void TimelineEventEndlessRecorder::PrintJSONEvents(
11651172
JSONArray* events,
11661173
TimelineEventFilter* filter) {
11671174
MutexLocker ml(&lock_);
1175+
// Collect all interesting blocks.
1176+
MallocGrowableArray<TimelineEventBlock*> blocks(8);
11681177
TimelineEventBlock* current = head_;
11691178
while (current != NULL) {
1170-
if (!filter->IncludeBlock(current)) {
1171-
current = current->next();
1172-
continue;
1179+
if (filter->IncludeBlock(current)) {
1180+
blocks.Add(current);
11731181
}
1182+
current = current->next();
1183+
}
1184+
// Bail early.
1185+
if (blocks.length() == 0) {
1186+
return;
1187+
}
1188+
// Sort the interesting blocks so that blocks with earlier events are
1189+
// outputted first.
1190+
blocks.Sort(TimelineEventBlockCompare);
1191+
// Output blocks in sorted order.
1192+
for (intptr_t block_idx = 0; block_idx < blocks.length(); block_idx++) {
1193+
current = blocks[block_idx];
11741194
intptr_t length = current->length();
11751195
for (intptr_t i = 0; i < length; i++) {
11761196
TimelineEvent* event = current->At(i);
@@ -1180,7 +1200,6 @@ void TimelineEventEndlessRecorder::PrintJSONEvents(
11801200
events->AddValue(event);
11811201
}
11821202
}
1183-
current = current->next();
11841203
}
11851204
}
11861205

runtime/vm/timeline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class TimelineEvent {
9494
// Keep in sync with StateBits below.
9595
enum EventType {
9696
kNone,
97-
kSerializedJSON, // Events from Dart code.
9897
kBegin,
9998
kEnd,
10099
kDuration,
@@ -387,6 +386,10 @@ class TimelineEventScope : public StackResource {
387386
return enabled_;
388387
}
389388

389+
void set_enabled(bool enabled) {
390+
enabled_ = enabled;
391+
}
392+
390393
const char* label() const {
391394
return label_;
392395
}

0 commit comments

Comments
 (0)