OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/scheduler/compositor_timing_history.h" | 5 #include "cc/scheduler/compositor_timing_history.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "cc/debug/rendering_stats_instrumentation.h" | 9 #include "cc/debug/rendering_stats_instrumentation.h" |
10 | 10 |
11 // The estimates that affect the compositors deadline use the 100th percentile | |
12 // to avoid missing the Browser's deadline. | |
13 // The estimates related to main-thread responsiveness affect whether | |
14 // we attempt to recovery latency or not and use the 50th percentile. | |
15 // TODO(brianderson): Fine tune the percentiles below. | |
16 const size_t kDurationHistorySize = 60; | 11 const size_t kDurationHistorySize = 60; |
17 const double kBeginMainFrameToCommitEstimationPercentile = 50.0; | 12 const double kCommitAndActivationDurationEstimationPercentile = 50.0; |
18 const double kCommitToReadyToActivateEstimationPercentile = 50.0; | 13 const double kDrawDurationEstimationPercentile = 100.0; |
19 const double kPrepareTilesEstimationPercentile = 100.0; | 14 const int kDrawDurationEstimatePaddingInMicroseconds = 0; |
20 const double kActivateEstimationPercentile = 100.0; | |
21 const double kDrawEstimationPercentile = 100.0; | |
22 | 15 |
23 namespace cc { | 16 namespace cc { |
24 | 17 |
25 CompositorTimingHistory::CompositorTimingHistory( | 18 CompositorTimingHistory::CompositorTimingHistory( |
26 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 19 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
27 : enabled_(false), | 20 : draw_duration_history_(kDurationHistorySize), |
28 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), | 21 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), |
29 commit_to_ready_to_activate_duration_history_(kDurationHistorySize), | 22 commit_to_activate_duration_history_(kDurationHistorySize), |
30 prepare_tiles_duration_history_(kDurationHistorySize), | |
31 activate_duration_history_(kDurationHistorySize), | |
32 draw_duration_history_(kDurationHistorySize), | |
33 rendering_stats_instrumentation_(rendering_stats_instrumentation) { | 23 rendering_stats_instrumentation_(rendering_stats_instrumentation) { |
34 } | 24 } |
35 | 25 |
36 CompositorTimingHistory::~CompositorTimingHistory() { | 26 CompositorTimingHistory::~CompositorTimingHistory() { |
37 } | 27 } |
38 | 28 |
39 void CompositorTimingHistory::AsValueInto( | 29 void CompositorTimingHistory::AsValueInto( |
40 base::trace_event::TracedValue* state) const { | 30 base::trace_event::TracedValue* state) const { |
41 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms", | 31 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms", |
42 BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); | 32 BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); |
43 state->SetDouble("commit_to_ready_to_activate_duration_estimate_ms", | 33 state->SetDouble("commit_to_activate_duration_estimate_ms", |
44 CommitToReadyToActivateDurationEstimate().InMillisecondsF()); | 34 CommitToActivateDurationEstimate().InMillisecondsF()); |
45 state->SetDouble("prepare_tiles_duration_estimate_ms", | |
46 PrepareTilesDurationEstimate().InMillisecondsF()); | |
47 state->SetDouble("activate_duration_estimate_ms", | |
48 ActivateDurationEstimate().InMillisecondsF()); | |
49 state->SetDouble("draw_duration_estimate_ms", | 35 state->SetDouble("draw_duration_estimate_ms", |
50 DrawDurationEstimate().InMillisecondsF()); | 36 DrawDurationEstimate().InMillisecondsF()); |
51 } | 37 } |
52 | 38 |
53 base::TimeTicks CompositorTimingHistory::Now() const { | 39 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const { |
54 return base::TimeTicks::Now(); | 40 base::TimeDelta historical_estimate = |
55 } | 41 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); |
56 | 42 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( |
57 void CompositorTimingHistory::SetRecordingEnabled(bool enabled) { | 43 kDrawDurationEstimatePaddingInMicroseconds); |
58 enabled_ = enabled; | 44 return historical_estimate + padding; |
59 | |
60 if (enabled) { | |
61 begin_main_frame_sent_time_ = base::TimeTicks(); | |
62 commit_time_ = base::TimeTicks(); | |
63 start_prepare_tiles_time_ = base::TimeTicks(); | |
64 start_activate_time_ = base::TimeTicks(); | |
65 start_draw_time_ = base::TimeTicks(); | |
66 } | |
67 } | 45 } |
68 | 46 |
69 base::TimeDelta | 47 base::TimeDelta |
70 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { | 48 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { |
71 return begin_main_frame_to_commit_duration_history_.Percentile( | 49 return begin_main_frame_to_commit_duration_history_.Percentile( |
72 kBeginMainFrameToCommitEstimationPercentile); | 50 kCommitAndActivationDurationEstimationPercentile); |
73 } | 51 } |
74 | 52 |
75 base::TimeDelta | 53 base::TimeDelta CompositorTimingHistory::CommitToActivateDurationEstimate() |
76 CompositorTimingHistory::CommitToReadyToActivateDurationEstimate() const { | 54 const { |
77 return commit_to_ready_to_activate_duration_history_.Percentile( | 55 return commit_to_activate_duration_history_.Percentile( |
78 kCommitToReadyToActivateEstimationPercentile); | 56 kCommitAndActivationDurationEstimationPercentile); |
79 } | |
80 | |
81 base::TimeDelta CompositorTimingHistory::PrepareTilesDurationEstimate() const { | |
82 return prepare_tiles_duration_history_.Percentile( | |
83 kPrepareTilesEstimationPercentile); | |
84 } | |
85 | |
86 base::TimeDelta CompositorTimingHistory::ActivateDurationEstimate() const { | |
87 return activate_duration_history_.Percentile(kActivateEstimationPercentile); | |
88 } | |
89 | |
90 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const { | |
91 return draw_duration_history_.Percentile(kDrawEstimationPercentile); | |
92 } | 57 } |
93 | 58 |
94 void CompositorTimingHistory::WillBeginMainFrame() { | 59 void CompositorTimingHistory::WillBeginMainFrame() { |
95 DCHECK_EQ(base::TimeTicks(), begin_main_frame_sent_time_); | 60 begin_main_frame_sent_time_ = base::TimeTicks::Now(); |
96 begin_main_frame_sent_time_ = Now(); | |
97 } | |
98 | |
99 void CompositorTimingHistory::BeginMainFrameAborted() { | |
100 DidCommit(); | |
101 } | 61 } |
102 | 62 |
103 void CompositorTimingHistory::DidCommit() { | 63 void CompositorTimingHistory::DidCommit() { |
104 DCHECK_NE(base::TimeTicks(), begin_main_frame_sent_time_); | 64 commit_complete_time_ = base::TimeTicks::Now(); |
105 | |
106 commit_time_ = Now(); | |
107 | |
108 base::TimeDelta begin_main_frame_to_commit_duration = | 65 base::TimeDelta begin_main_frame_to_commit_duration = |
109 commit_time_ - begin_main_frame_sent_time_; | 66 commit_complete_time_ - begin_main_frame_sent_time_; |
110 | 67 |
111 // Before adding the new data point to the timing history, see what we would | 68 // Before adding the new data point to the timing history, see what we would |
112 // have predicted for this frame. This allows us to keep track of the accuracy | 69 // have predicted for this frame. This allows us to keep track of the accuracy |
113 // of our predictions. | 70 // of our predictions. |
114 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( | 71 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( |
115 begin_main_frame_to_commit_duration, | 72 begin_main_frame_to_commit_duration, |
116 BeginMainFrameToCommitDurationEstimate()); | 73 BeginMainFrameToCommitDurationEstimate()); |
117 | 74 |
118 if (enabled_) { | 75 begin_main_frame_to_commit_duration_history_.InsertSample( |
119 begin_main_frame_to_commit_duration_history_.InsertSample( | 76 begin_main_frame_to_commit_duration); |
120 begin_main_frame_to_commit_duration); | |
121 } | |
122 | |
123 begin_main_frame_sent_time_ = base::TimeTicks(); | |
124 } | 77 } |
125 | 78 |
126 void CompositorTimingHistory::WillPrepareTiles() { | 79 void CompositorTimingHistory::DidActivateSyncTree() { |
127 DCHECK_EQ(base::TimeTicks(), start_prepare_tiles_time_); | 80 base::TimeDelta commit_to_activate_duration = |
128 start_prepare_tiles_time_ = Now(); | 81 base::TimeTicks::Now() - commit_complete_time_; |
129 } | |
130 | |
131 void CompositorTimingHistory::DidPrepareTiles() { | |
132 DCHECK_NE(base::TimeTicks(), start_prepare_tiles_time_); | |
133 | |
134 if (enabled_) { | |
135 base::TimeDelta prepare_tiles_duration = Now() - start_prepare_tiles_time_; | |
136 prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration); | |
137 } | |
138 | |
139 start_prepare_tiles_time_ = base::TimeTicks(); | |
140 } | |
141 | |
142 void CompositorTimingHistory::ReadyToActivate() { | |
143 // We only care about the first ready to activate signal | |
144 // after a commit. | |
145 if (commit_time_ == base::TimeTicks()) | |
146 return; | |
147 | |
148 base::TimeDelta time_since_commit = Now() - commit_time_; | |
149 | 82 |
150 // Before adding the new data point to the timing history, see what we would | 83 // Before adding the new data point to the timing history, see what we would |
151 // have predicted for this frame. This allows us to keep track of the accuracy | 84 // have predicted for this frame. This allows us to keep track of the accuracy |
152 // of our predictions. | 85 // of our predictions. |
153 rendering_stats_instrumentation_->AddCommitToActivateDuration( | 86 rendering_stats_instrumentation_->AddCommitToActivateDuration( |
154 time_since_commit, CommitToReadyToActivateDurationEstimate()); | 87 commit_to_activate_duration, CommitToActivateDurationEstimate()); |
155 | 88 |
156 if (enabled_) { | 89 commit_to_activate_duration_history_.InsertSample( |
157 commit_to_ready_to_activate_duration_history_.InsertSample( | 90 commit_to_activate_duration); |
158 time_since_commit); | |
159 } | |
160 | |
161 commit_time_ = base::TimeTicks(); | |
162 } | 91 } |
163 | 92 |
164 void CompositorTimingHistory::WillActivate() { | 93 void CompositorTimingHistory::DidStartDrawing() { |
165 DCHECK_EQ(base::TimeTicks(), start_activate_time_); | 94 start_draw_time_ = base::TimeTicks::Now(); |
166 start_activate_time_ = Now(); | |
167 } | 95 } |
168 | 96 |
169 void CompositorTimingHistory::DidActivate() { | 97 void CompositorTimingHistory::DidFinishDrawing() { |
170 DCHECK_NE(base::TimeTicks(), start_activate_time_); | 98 base::TimeDelta draw_duration = base::TimeTicks::Now() - start_draw_time_; |
171 if (enabled_) { | |
172 base::TimeDelta activate_duration = Now() - start_activate_time_; | |
173 activate_duration_history_.InsertSample(activate_duration); | |
174 } | |
175 start_activate_time_ = base::TimeTicks(); | |
176 } | |
177 | |
178 void CompositorTimingHistory::WillDraw() { | |
179 DCHECK_EQ(base::TimeTicks(), start_draw_time_); | |
180 start_draw_time_ = Now(); | |
181 } | |
182 | |
183 void CompositorTimingHistory::DidDraw() { | |
184 DCHECK_NE(base::TimeTicks(), start_draw_time_); | |
185 base::TimeDelta draw_duration = Now() - start_draw_time_; | |
186 | 99 |
187 // Before adding the new data point to the timing history, see what we would | 100 // Before adding the new data point to the timing history, see what we would |
188 // have predicted for this frame. This allows us to keep track of the accuracy | 101 // have predicted for this frame. This allows us to keep track of the accuracy |
189 // of our predictions. | 102 // of our predictions. |
190 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 103 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
191 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, | 104 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, |
192 draw_duration_estimate); | 105 draw_duration_estimate); |
193 | 106 |
194 AddDrawDurationUMA(draw_duration, draw_duration_estimate); | 107 AddDrawDurationUMA(draw_duration, draw_duration_estimate); |
195 | 108 |
196 if (enabled_) { | 109 draw_duration_history_.InsertSample(draw_duration); |
197 draw_duration_history_.InsertSample(draw_duration); | |
198 } | |
199 | |
200 start_draw_time_ = base::TimeTicks(); | |
201 } | 110 } |
202 | 111 |
203 void CompositorTimingHistory::AddDrawDurationUMA( | 112 void CompositorTimingHistory::AddDrawDurationUMA( |
204 base::TimeDelta draw_duration, | 113 base::TimeDelta draw_duration, |
205 base::TimeDelta draw_duration_estimate) { | 114 base::TimeDelta draw_duration_estimate) { |
206 base::TimeDelta draw_duration_overestimate; | 115 base::TimeDelta draw_duration_overestimate; |
207 base::TimeDelta draw_duration_underestimate; | 116 base::TimeDelta draw_duration_underestimate; |
208 if (draw_duration > draw_duration_estimate) | 117 if (draw_duration > draw_duration_estimate) |
209 draw_duration_underestimate = draw_duration - draw_duration_estimate; | 118 draw_duration_underestimate = draw_duration - draw_duration_estimate; |
210 else | 119 else |
211 draw_duration_overestimate = draw_duration_estimate - draw_duration; | 120 draw_duration_overestimate = draw_duration_estimate - draw_duration; |
212 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration, | 121 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration, |
213 base::TimeDelta::FromMilliseconds(1), | 122 base::TimeDelta::FromMilliseconds(1), |
214 base::TimeDelta::FromMilliseconds(100), 50); | 123 base::TimeDelta::FromMilliseconds(100), 50); |
215 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", | 124 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", |
216 draw_duration_underestimate, | 125 draw_duration_underestimate, |
217 base::TimeDelta::FromMilliseconds(1), | 126 base::TimeDelta::FromMilliseconds(1), |
218 base::TimeDelta::FromMilliseconds(100), 50); | 127 base::TimeDelta::FromMilliseconds(100), 50); |
219 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", | 128 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", |
220 draw_duration_overestimate, | 129 draw_duration_overestimate, |
221 base::TimeDelta::FromMilliseconds(1), | 130 base::TimeDelta::FromMilliseconds(1), |
222 base::TimeDelta::FromMilliseconds(100), 50); | 131 base::TimeDelta::FromMilliseconds(100), 50); |
223 } | 132 } |
224 | 133 |
225 } // namespace cc | 134 } // namespace cc |
OLD | NEW |