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) R=zra@google.com Review URL: https://codereview.chromium.org/1657843003 .
This commit is contained in:
+23
-4
@@ -721,6 +721,7 @@ void TimelineBeginEndScope::EmitBegin() {
|
||||
TimelineEvent* event = stream()->StartEvent();
|
||||
if (event == NULL) {
|
||||
// Stream is now disabled.
|
||||
set_enabled(false);
|
||||
return;
|
||||
}
|
||||
ASSERT(event != NULL);
|
||||
@@ -737,6 +738,7 @@ void TimelineBeginEndScope::EmitEnd() {
|
||||
TimelineEvent* event = stream()->StartEvent();
|
||||
if (event == NULL) {
|
||||
// Stream is now disabled.
|
||||
set_enabled(false);
|
||||
return;
|
||||
}
|
||||
ASSERT(event != NULL);
|
||||
@@ -1160,17 +1162,35 @@ TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlockLocked() {
|
||||
return head_;
|
||||
}
|
||||
|
||||
static int TimelineEventBlockCompare(TimelineEventBlock* const* a,
|
||||
TimelineEventBlock* const* b) {
|
||||
return (*a)->LowerTimeBound() - (*b)->LowerTimeBound();
|
||||
}
|
||||
|
||||
|
||||
void TimelineEventEndlessRecorder::PrintJSONEvents(
|
||||
JSONArray* events,
|
||||
TimelineEventFilter* filter) {
|
||||
MutexLocker ml(&lock_);
|
||||
// Collect all interesting blocks.
|
||||
MallocGrowableArray<TimelineEventBlock*> blocks(8);
|
||||
TimelineEventBlock* current = head_;
|
||||
while (current != NULL) {
|
||||
if (!filter->IncludeBlock(current)) {
|
||||
current = current->next();
|
||||
continue;
|
||||
if (filter->IncludeBlock(current)) {
|
||||
blocks.Add(current);
|
||||
}
|
||||
current = current->next();
|
||||
}
|
||||
// Bail early.
|
||||
if (blocks.length() == 0) {
|
||||
return;
|
||||
}
|
||||
// Sort the interesting blocks so that blocks with earlier events are
|
||||
// outputted first.
|
||||
blocks.Sort(TimelineEventBlockCompare);
|
||||
// Output blocks in sorted order.
|
||||
for (intptr_t block_idx = 0; block_idx < blocks.length(); block_idx++) {
|
||||
current = blocks[block_idx];
|
||||
intptr_t length = current->length();
|
||||
for (intptr_t i = 0; i < length; i++) {
|
||||
TimelineEvent* event = current->At(i);
|
||||
@@ -1180,7 +1200,6 @@ void TimelineEventEndlessRecorder::PrintJSONEvents(
|
||||
events->AddValue(event);
|
||||
}
|
||||
}
|
||||
current = current->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ class TimelineEvent {
|
||||
// Keep in sync with StateBits below.
|
||||
enum EventType {
|
||||
kNone,
|
||||
kSerializedJSON, // Events from Dart code.
|
||||
kBegin,
|
||||
kEnd,
|
||||
kDuration,
|
||||
@@ -387,6 +386,10 @@ class TimelineEventScope : public StackResource {
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
void set_enabled(bool enabled) {
|
||||
enabled_ = enabled;
|
||||
}
|
||||
|
||||
const char* label() const {
|
||||
return label_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user