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

Side by Side Diff: cc/scheduler/compositor_timing_history.cc

Issue 1192663005: cc: Measure compositor timing with finer granularity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@modeTimingHistory3
Patch Set: rebase Created 5 years, 5 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
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 const size_t kDurationHistorySize = 60; 11 const size_t kDurationHistorySize = 60;
12 const double kCommitAndActivationDurationEstimationPercentile = 50.0; 12 const double kBeginMainFrameToCommitEstimationPercentile = 50.0;
mithro-old 2015/06/30 07:55:49 Why are these percentiles set to these values? Can
brianderson 2015/06/30 17:35:15 These were picked somewhat arbitrarily a while bac
13 const double kDrawDurationEstimationPercentile = 100.0; 13 const double kCommitToReadyToActivateEstimationPercentile = 50.0;
14 const int kDrawDurationEstimatePaddingInMicroseconds = 0; 14 const double kPrepareTilesEstimationPercentile = 100.0;
15 const double kActivateEstimationPercentile = 100.0;
16 const double kDrawEstimationPercentile = 100.0;
15 17
16 namespace cc { 18 namespace cc {
17 19
18 CompositorTimingHistory::CompositorTimingHistory( 20 CompositorTimingHistory::CompositorTimingHistory(
19 RenderingStatsInstrumentation* rendering_stats_instrumentation) 21 RenderingStatsInstrumentation* rendering_stats_instrumentation)
20 : draw_duration_history_(kDurationHistorySize), 22 : enabled_(false),
21 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), 23 begin_main_frame_to_commit_duration_history_(kDurationHistorySize),
22 commit_to_activate_duration_history_(kDurationHistorySize), 24 commit_to_ready_to_activate_duration_history_(kDurationHistorySize),
25 prepare_tiles_duration_history_(kDurationHistorySize),
26 activate_duration_history_(kDurationHistorySize),
27 draw_duration_history_(kDurationHistorySize),
23 rendering_stats_instrumentation_(rendering_stats_instrumentation) { 28 rendering_stats_instrumentation_(rendering_stats_instrumentation) {
24 } 29 }
25 30
26 CompositorTimingHistory::~CompositorTimingHistory() { 31 CompositorTimingHistory::~CompositorTimingHistory() {
27 } 32 }
28 33
29 void CompositorTimingHistory::AsValueInto( 34 void CompositorTimingHistory::AsValueInto(
30 base::trace_event::TracedValue* state) const { 35 base::trace_event::TracedValue* state) const {
mithro-old 2015/06/30 07:55:49 Can you put these in the same order as they are de
brianderson 2015/06/30 17:35:15 Acknowledged.
31 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms", 36 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms",
32 BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); 37 BeginMainFrameToCommitDurationEstimate().InMillisecondsF());
33 state->SetDouble("commit_to_activate_duration_estimate_ms", 38 state->SetDouble("prepare_tiles_duration_estimate_ms",
34 CommitToActivateDurationEstimate().InMillisecondsF()); 39 PrepareTilesDurationEstimate().InMillisecondsF());
40 state->SetDouble("commit_to_ready_to_activate_duration_estimate_ms",
41 CommitToReadyToActivateDurationEstimate().InMillisecondsF());
42 state->SetDouble("activate_duration_estimate_ms",
43 ActivateDurationEstimate().InMillisecondsF());
35 state->SetDouble("draw_duration_estimate_ms", 44 state->SetDouble("draw_duration_estimate_ms",
36 DrawDurationEstimate().InMillisecondsF()); 45 DrawDurationEstimate().InMillisecondsF());
37 } 46 }
38 47
39 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const { 48 base::TimeTicks CompositorTimingHistory::Now() const {
40 base::TimeDelta historical_estimate = 49 return base::TimeTicks::Now();
41 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); 50 }
42 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( 51
43 kDrawDurationEstimatePaddingInMicroseconds); 52 void CompositorTimingHistory::SetRecordingEnabled(bool enabled) {
44 return historical_estimate + padding; 53 enabled_ = enabled;
54
55 if (enabled) {
56 begin_main_frame_sent_time_ = base::TimeTicks();
57 commit_time_ = base::TimeTicks();
58 start_prepare_tiles_time_ = base::TimeTicks();
59 start_activate_time_ = base::TimeTicks();
60 start_draw_time_ = base::TimeTicks();
61 }
45 } 62 }
46 63
47 base::TimeDelta 64 base::TimeDelta
48 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { 65 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const {
49 return begin_main_frame_to_commit_duration_history_.Percentile( 66 return begin_main_frame_to_commit_duration_history_.Percentile(
50 kCommitAndActivationDurationEstimationPercentile); 67 kBeginMainFrameToCommitEstimationPercentile);
51 } 68 }
52 69
53 base::TimeDelta CompositorTimingHistory::CommitToActivateDurationEstimate() 70 base::TimeDelta CompositorTimingHistory::PrepareTilesDurationEstimate() const {
54 const { 71 return prepare_tiles_duration_history_.Percentile(
55 return commit_to_activate_duration_history_.Percentile( 72 kPrepareTilesEstimationPercentile);
56 kCommitAndActivationDurationEstimationPercentile); 73 }
74
75 base::TimeDelta
76 CompositorTimingHistory::CommitToReadyToActivateDurationEstimate() const {
77 return commit_to_ready_to_activate_duration_history_.Percentile(
78 kCommitToReadyToActivateEstimationPercentile);
79 }
80
81 base::TimeDelta CompositorTimingHistory::ActivateDurationEstimate() const {
82 return activate_duration_history_.Percentile(kActivateEstimationPercentile);
83 }
84
85 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const {
86 return draw_duration_history_.Percentile(kDrawEstimationPercentile);
57 } 87 }
58 88
59 void CompositorTimingHistory::WillBeginMainFrame() { 89 void CompositorTimingHistory::WillBeginMainFrame() {
60 begin_main_frame_sent_time_ = base::TimeTicks::Now(); 90 DCHECK_EQ(base::TimeTicks(), begin_main_frame_sent_time_);
91 begin_main_frame_sent_time_ = Now();
92 }
93
94 void CompositorTimingHistory::BeginMainFrameAborted() {
mithro-old 2015/06/30 07:55:49 Does it make sense to include aborted commits in t
95 DidCommit();
61 } 96 }
62 97
63 void CompositorTimingHistory::DidCommit() { 98 void CompositorTimingHistory::DidCommit() {
64 commit_complete_time_ = base::TimeTicks::Now(); 99 DCHECK_NE(base::TimeTicks(), begin_main_frame_sent_time_);
100
101 commit_time_ = Now();
102
65 base::TimeDelta begin_main_frame_to_commit_duration = 103 base::TimeDelta begin_main_frame_to_commit_duration =
66 commit_complete_time_ - begin_main_frame_sent_time_; 104 commit_time_ - begin_main_frame_sent_time_;
67 105
68 // Before adding the new data point to the timing history, see what we would 106 // Before adding the new data point to the timing history, see what we would
69 // have predicted for this frame. This allows us to keep track of the accuracy 107 // have predicted for this frame. This allows us to keep track of the accuracy
70 // of our predictions. 108 // of our predictions.
71 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( 109 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration(
72 begin_main_frame_to_commit_duration, 110 begin_main_frame_to_commit_duration,
73 BeginMainFrameToCommitDurationEstimate()); 111 BeginMainFrameToCommitDurationEstimate());
74 112
75 begin_main_frame_to_commit_duration_history_.InsertSample( 113 if (enabled_) {
76 begin_main_frame_to_commit_duration); 114 begin_main_frame_to_commit_duration_history_.InsertSample(
115 begin_main_frame_to_commit_duration);
116 }
117
118 begin_main_frame_sent_time_ = base::TimeTicks();
77 } 119 }
78 120
79 void CompositorTimingHistory::DidActivateSyncTree() { 121 void CompositorTimingHistory::WillPrepareTiles() {
80 base::TimeDelta commit_to_activate_duration = 122 DCHECK_EQ(base::TimeTicks(), start_prepare_tiles_time_);
81 base::TimeTicks::Now() - commit_complete_time_; 123 start_prepare_tiles_time_ = Now();
124 }
125
126 void CompositorTimingHistory::DidPrepareTiles() {
127 DCHECK_NE(base::TimeTicks(), start_prepare_tiles_time_);
128
129 if (enabled_) {
130 base::TimeDelta prepare_tiles_duration = Now() - start_prepare_tiles_time_;
131 prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration);
132 }
133
134 start_prepare_tiles_time_ = base::TimeTicks();
135 }
136
137 void CompositorTimingHistory::ReadyToActivate() {
138 // We only care about the first ready to activate signal
139 // after a commit.
140 if (commit_time_ == base::TimeTicks())
141 return;
142
143 base::TimeDelta time_since_commit = Now() - commit_time_;
82 144
83 // Before adding the new data point to the timing history, see what we would 145 // Before adding the new data point to the timing history, see what we would
84 // have predicted for this frame. This allows us to keep track of the accuracy 146 // have predicted for this frame. This allows us to keep track of the accuracy
85 // of our predictions. 147 // of our predictions.
86 rendering_stats_instrumentation_->AddCommitToActivateDuration( 148 rendering_stats_instrumentation_->AddCommitToActivateDuration(
87 commit_to_activate_duration, CommitToActivateDurationEstimate()); 149 time_since_commit, CommitToReadyToActivateDurationEstimate());
88 150
89 commit_to_activate_duration_history_.InsertSample( 151 if (enabled_) {
90 commit_to_activate_duration); 152 commit_to_ready_to_activate_duration_history_.InsertSample(
153 time_since_commit);
154 }
155
156 commit_time_ = base::TimeTicks();
91 } 157 }
92 158
93 void CompositorTimingHistory::DidStartDrawing() { 159 void CompositorTimingHistory::WillActivate() {
94 start_draw_time_ = base::TimeTicks::Now(); 160 DCHECK_EQ(base::TimeTicks(), start_activate_time_);
161 start_activate_time_ = Now();
95 } 162 }
96 163
97 void CompositorTimingHistory::DidFinishDrawing() { 164 void CompositorTimingHistory::DidActivate() {
98 base::TimeDelta draw_duration = base::TimeTicks::Now() - start_draw_time_; 165 DCHECK_NE(base::TimeTicks(), start_activate_time_);
166 if (enabled_) {
167 base::TimeDelta activate_duration = Now() - start_activate_time_;
168 activate_duration_history_.InsertSample(activate_duration);
169 }
170 start_activate_time_ = base::TimeTicks();
171 }
172
173 void CompositorTimingHistory::WillDraw() {
174 DCHECK_EQ(base::TimeTicks(), start_draw_time_);
175 start_draw_time_ = Now();
176 }
177
178 void CompositorTimingHistory::DidDraw() {
179 DCHECK_NE(base::TimeTicks(), start_draw_time_);
180 base::TimeDelta draw_duration = Now() - start_draw_time_;
99 181
100 // Before adding the new data point to the timing history, see what we would 182 // Before adding the new data point to the timing history, see what we would
101 // have predicted for this frame. This allows us to keep track of the accuracy 183 // have predicted for this frame. This allows us to keep track of the accuracy
102 // of our predictions. 184 // of our predictions.
103 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 185 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
104 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, 186 rendering_stats_instrumentation_->AddDrawDuration(draw_duration,
105 draw_duration_estimate); 187 draw_duration_estimate);
106 188
107 AddDrawDurationUMA(draw_duration, draw_duration_estimate); 189 AddDrawDurationUMA(draw_duration, draw_duration_estimate);
108 190
109 draw_duration_history_.InsertSample(draw_duration); 191 if (enabled_) {
192 draw_duration_history_.InsertSample(draw_duration);
193 }
194
195 start_draw_time_ = base::TimeTicks();
110 } 196 }
111 197
112 void CompositorTimingHistory::AddDrawDurationUMA( 198 void CompositorTimingHistory::AddDrawDurationUMA(
mithro-old 2015/06/30 07:55:49 Are you planning on adding UMAs for the other ones
brianderson 2015/06/30 17:35:15 Yes. We are going to do it for PrepareTiles - will
113 base::TimeDelta draw_duration, 199 base::TimeDelta draw_duration,
114 base::TimeDelta draw_duration_estimate) { 200 base::TimeDelta draw_duration_estimate) {
115 base::TimeDelta draw_duration_overestimate; 201 base::TimeDelta draw_duration_overestimate;
116 base::TimeDelta draw_duration_underestimate; 202 base::TimeDelta draw_duration_underestimate;
117 if (draw_duration > draw_duration_estimate) 203 if (draw_duration > draw_duration_estimate)
118 draw_duration_underestimate = draw_duration - draw_duration_estimate; 204 draw_duration_underestimate = draw_duration - draw_duration_estimate;
119 else 205 else
120 draw_duration_overestimate = draw_duration_estimate - draw_duration; 206 draw_duration_overestimate = draw_duration_estimate - draw_duration;
121 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration, 207 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration,
122 base::TimeDelta::FromMilliseconds(1), 208 base::TimeDelta::FromMilliseconds(1),
123 base::TimeDelta::FromMilliseconds(100), 50); 209 base::TimeDelta::FromMilliseconds(100), 50);
124 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", 210 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate",
125 draw_duration_underestimate, 211 draw_duration_underestimate,
126 base::TimeDelta::FromMilliseconds(1), 212 base::TimeDelta::FromMilliseconds(1),
127 base::TimeDelta::FromMilliseconds(100), 50); 213 base::TimeDelta::FromMilliseconds(100), 50);
128 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", 214 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate",
129 draw_duration_overestimate, 215 draw_duration_overestimate,
130 base::TimeDelta::FromMilliseconds(1), 216 base::TimeDelta::FromMilliseconds(1),
131 base::TimeDelta::FromMilliseconds(100), 50); 217 base::TimeDelta::FromMilliseconds(100), 50);
132 } 218 }
133 219
134 } // namespace cc 220 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698