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

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

Issue 1284263002: Start TimelineAnalysis utility (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/timeline_analysis.h"
6
7 #include "vm/flags.h"
8
9 namespace dart {
10
11 DECLARE_FLAG(bool, trace_timeline);
12
13
14 TimelineAnalysisThread::TimelineAnalysisThread(ThreadId id)
15 : id_(id) {
16 }
17
18
19 TimelineAnalysisThread::~TimelineAnalysisThread() {
20 }
21
22
23 void TimelineAnalysisThread::AddBlock(TimelineEventBlock* block) {
24 blocks_.Add(block);
25 }
26
27
28 static int CompareBlocksLowerTimeBound(TimelineEventBlock* const* a,
29 TimelineEventBlock* const* b) {
30 ASSERT(a != NULL);
31 ASSERT(*a != NULL);
32 ASSERT(b != NULL);
33 ASSERT(*b != NULL);
34 return (*a)->LowerTimeBound() - (*b)->LowerTimeBound();
35 }
36
37
38 void TimelineAnalysisThread::Finalize() {
39 blocks_.Sort(CompareBlocksLowerTimeBound);
40 }
41
42
43 TimelineAnalysis::TimelineAnalysis(Zone* zone,
44 Isolate* isolate,
45 TimelineEventEndlessRecorder* recorder)
46 : zone_(zone),
47 isolate_(isolate),
48 recorder_(recorder),
49 has_error_(false),
50 error_msg_(NULL) {
51 ASSERT(zone_ != NULL);
52 ASSERT(isolate_ != NULL);
53 ASSERT(recorder_ != NULL);
54 }
55
56
57 TimelineAnalysis::~TimelineAnalysis() {
58 }
59
60
61 void TimelineAnalysis::BuildThreads() {
62 DiscoverThreads();
63 FinalizeThreads();
64 }
65
66
67 TimelineAnalysisThread* TimelineAnalysis::GetThread(ThreadId tid) {
68 // Linear lookup because we expect N (# of threads in an isolate) to be small.
69 for (intptr_t i = 0; i < threads_.length(); i++) {
70 TimelineAnalysisThread* thread = threads_.At(i);
71 ASSERT(thread != NULL);
72 if (thread->id() == tid) {
73 return thread;
74 }
75 }
76 return NULL;
77 }
78
79
80 TimelineAnalysisThread* TimelineAnalysis::GetOrAddThread(ThreadId tid) {
81 TimelineAnalysisThread* thread = GetThread(tid);
82 if (thread != NULL) {
83 return thread;
84 }
85 // New thread.
86 thread = new TimelineAnalysisThread(tid);
87 threads_.Add(thread);
88 return thread;
89 }
90
91
92 void TimelineAnalysis::DiscoverThreads() {
93 TimelineEventBlockIterator it(recorder_);
94 while (it.Next()) {
95 TimelineEventBlock* block = it.current();
96 ASSERT(block != NULL);
97 if (block->IsEmpty()) {
98 // Skip empty blocks.
99 continue;
100 }
101 if (!block->CheckBlock()) {
102 // Skip bad blocks.
103 // TODO(johnmccutchan): Make this into an error?
104 continue;
105 }
106 TimelineAnalysisThread* thread = GetOrAddThread(block->thread());
107 ASSERT(thread != NULL);
108 thread->AddBlock(block);
109 }
110 }
111
112
113 void TimelineAnalysis::FinalizeThreads() {
114 for (intptr_t i = 0; i < threads_.length(); i++) {
115 TimelineAnalysisThread* thread = threads_.At(i);
116 ASSERT(thread != NULL);
117 thread->Finalize();
118 }
119 }
120
121
122 void TimelineAnalysis::SetError(const char* format, ...) {
123 ASSERT(!has_error_);
124 ASSERT(error_msg_ == NULL);
125 has_error_ = true;
126 va_list args;
127 va_start(args, format);
128 error_msg_ = zone_->VPrint(format, args);
129 ASSERT(error_msg_ != NULL);
130 }
131
132
133 TimelinePauses::TimelinePauses(Zone* zone,
134 Isolate* isolate,
135 TimelineEventEndlessRecorder* recorder)
136 : TimelineAnalysis(zone, isolate, recorder) {
137 }
138
139 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698