Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: runtime/vm/timeline.cc

Issue 1657843003: Output TimelineEventBlocks in sorted order (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <cstdlib> 5 #include <cstdlib>
6 6
7 #include "vm/atomic.h" 7 #include "vm/atomic.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 } 714 }
715 715
716 716
717 void TimelineBeginEndScope::EmitBegin() { 717 void TimelineBeginEndScope::EmitBegin() {
718 if (!ShouldEmitEvent()) { 718 if (!ShouldEmitEvent()) {
719 return; 719 return;
720 } 720 }
721 TimelineEvent* event = stream()->StartEvent(); 721 TimelineEvent* event = stream()->StartEvent();
722 if (event == NULL) { 722 if (event == NULL) {
723 // Stream is now disabled. 723 // Stream is now disabled.
724 set_enabled(false);
724 return; 725 return;
725 } 726 }
726 ASSERT(event != NULL); 727 ASSERT(event != NULL);
727 // Emit a begin event. 728 // Emit a begin event.
728 event->Begin(label()); 729 event->Begin(label());
729 event->Complete(); 730 event->Complete();
730 } 731 }
731 732
732 733
733 void TimelineBeginEndScope::EmitEnd() { 734 void TimelineBeginEndScope::EmitEnd() {
734 if (!ShouldEmitEvent()) { 735 if (!ShouldEmitEvent()) {
735 return; 736 return;
736 } 737 }
737 TimelineEvent* event = stream()->StartEvent(); 738 TimelineEvent* event = stream()->StartEvent();
738 if (event == NULL) { 739 if (event == NULL) {
739 // Stream is now disabled. 740 // Stream is now disabled.
741 set_enabled(false);
740 return; 742 return;
741 } 743 }
742 ASSERT(event != NULL); 744 ASSERT(event != NULL);
743 // Emit an end event. 745 // Emit an end event.
744 event->End(label()); 746 event->End(label());
745 StealArguments(event); 747 StealArguments(event);
746 event->Complete(); 748 event->Complete();
747 } 749 }
748 750
749 751
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 TimelineEventBlock* block = new TimelineEventBlock(block_index_++); 1155 TimelineEventBlock* block = new TimelineEventBlock(block_index_++);
1154 block->set_next(head_); 1156 block->set_next(head_);
1155 block->Open(); 1157 block->Open();
1156 head_ = block; 1158 head_ = block;
1157 if (FLAG_trace_timeline) { 1159 if (FLAG_trace_timeline) {
1158 OS::Print("Created new block %p\n", block); 1160 OS::Print("Created new block %p\n", block);
1159 } 1161 }
1160 return head_; 1162 return head_;
1161 } 1163 }
1162 1164
1165 static int TimelineEventBlockCompare(TimelineEventBlock* const* a,
1166 TimelineEventBlock* const* b) {
1167 return (*a)->LowerTimeBound() - (*b)->LowerTimeBound();
1168 }
1169
1163 1170
1164 void TimelineEventEndlessRecorder::PrintJSONEvents( 1171 void TimelineEventEndlessRecorder::PrintJSONEvents(
1165 JSONArray* events, 1172 JSONArray* events,
1166 TimelineEventFilter* filter) { 1173 TimelineEventFilter* filter) {
1167 MutexLocker ml(&lock_); 1174 MutexLocker ml(&lock_);
1175 // Collect all interesting blocks.
1176 MallocGrowableArray<TimelineEventBlock*> blocks(8);
1168 TimelineEventBlock* current = head_; 1177 TimelineEventBlock* current = head_;
1169 while (current != NULL) { 1178 while (current != NULL) {
1170 if (!filter->IncludeBlock(current)) { 1179 if (filter->IncludeBlock(current)) {
1171 current = current->next(); 1180 blocks.Add(current);
1172 continue;
1173 } 1181 }
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];
1174 intptr_t length = current->length(); 1194 intptr_t length = current->length();
1175 for (intptr_t i = 0; i < length; i++) { 1195 for (intptr_t i = 0; i < length; i++) {
1176 TimelineEvent* event = current->At(i); 1196 TimelineEvent* event = current->At(i);
1177 if (filter->IncludeEvent(event) && 1197 if (filter->IncludeEvent(event) &&
1178 event->Within(filter->time_origin_micros(), 1198 event->Within(filter->time_origin_micros(),
1179 filter->time_extent_micros())) { 1199 filter->time_extent_micros())) {
1180 events->AddValue(event); 1200 events->AddValue(event);
1181 } 1201 }
1182 } 1202 }
1183 current = current->next();
1184 } 1203 }
1185 } 1204 }
1186 1205
1187 1206
1188 void TimelineEventEndlessRecorder::Clear() { 1207 void TimelineEventEndlessRecorder::Clear() {
1189 TimelineEventBlock* current = head_; 1208 TimelineEventBlock* current = head_;
1190 while (current != NULL) { 1209 while (current != NULL) {
1191 TimelineEventBlock* next = current->next(); 1210 TimelineEventBlock* next = current->next();
1192 delete current; 1211 delete current;
1193 current = next; 1212 current = next;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 1341
1323 1342
1324 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1343 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1325 ASSERT(current_ != NULL); 1344 ASSERT(current_ != NULL);
1326 TimelineEventBlock* r = current_; 1345 TimelineEventBlock* r = current_;
1327 current_ = current_->next(); 1346 current_ = current_->next();
1328 return r; 1347 return r;
1329 } 1348 }
1330 1349
1331 } // namespace dart 1350 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698