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/trees/proxy_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" |
| 9 #include "cc/debug/rendering_stats_instrumentation.h" |
8 | 10 |
9 const size_t kDurationHistorySize = 60; | 11 const size_t kDurationHistorySize = 60; |
10 const double kCommitAndActivationDurationEstimationPercentile = 50.0; | 12 const double kCommitAndActivationDurationEstimationPercentile = 50.0; |
11 const double kDrawDurationEstimationPercentile = 100.0; | 13 const double kDrawDurationEstimationPercentile = 100.0; |
12 const int kDrawDurationEstimatePaddingInMicroseconds = 0; | 14 const int kDrawDurationEstimatePaddingInMicroseconds = 0; |
13 | 15 |
14 namespace cc { | 16 namespace cc { |
15 | 17 |
16 ProxyTimingHistory::ProxyTimingHistory( | 18 CompositorTimingHistory::CompositorTimingHistory( |
17 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 19 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
18 : draw_duration_history_(kDurationHistorySize), | 20 : draw_duration_history_(kDurationHistorySize), |
19 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), | 21 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), |
20 commit_to_activate_duration_history_(kDurationHistorySize), | 22 commit_to_activate_duration_history_(kDurationHistorySize), |
21 rendering_stats_instrumentation_(rendering_stats_instrumentation) { | 23 rendering_stats_instrumentation_(rendering_stats_instrumentation) { |
22 } | 24 } |
23 | 25 |
24 ProxyTimingHistory::~ProxyTimingHistory() {} | 26 CompositorTimingHistory::~CompositorTimingHistory() { |
| 27 } |
25 | 28 |
26 base::TimeDelta ProxyTimingHistory::DrawDurationEstimate() const { | 29 void CompositorTimingHistory::AsValueInto( |
| 30 base::trace_event::TracedValue* state) const { |
| 31 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms", |
| 32 BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); |
| 33 state->SetDouble("commit_to_activate_duration_estimate_ms", |
| 34 CommitToActivateDurationEstimate().InMillisecondsF()); |
| 35 state->SetDouble("draw_duration_estimate_ms", |
| 36 DrawDurationEstimate().InMillisecondsF()); |
| 37 } |
| 38 |
| 39 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const { |
27 base::TimeDelta historical_estimate = | 40 base::TimeDelta historical_estimate = |
28 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); | 41 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); |
29 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( | 42 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( |
30 kDrawDurationEstimatePaddingInMicroseconds); | 43 kDrawDurationEstimatePaddingInMicroseconds); |
31 return historical_estimate + padding; | 44 return historical_estimate + padding; |
32 } | 45 } |
33 | 46 |
34 base::TimeDelta ProxyTimingHistory::BeginMainFrameToCommitDurationEstimate() | 47 base::TimeDelta |
35 const { | 48 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { |
36 return begin_main_frame_to_commit_duration_history_.Percentile( | 49 return begin_main_frame_to_commit_duration_history_.Percentile( |
37 kCommitAndActivationDurationEstimationPercentile); | 50 kCommitAndActivationDurationEstimationPercentile); |
38 } | 51 } |
39 | 52 |
40 base::TimeDelta ProxyTimingHistory::CommitToActivateDurationEstimate() const { | 53 base::TimeDelta CompositorTimingHistory::CommitToActivateDurationEstimate() |
| 54 const { |
41 return commit_to_activate_duration_history_.Percentile( | 55 return commit_to_activate_duration_history_.Percentile( |
42 kCommitAndActivationDurationEstimationPercentile); | 56 kCommitAndActivationDurationEstimationPercentile); |
43 } | 57 } |
44 | 58 |
45 void ProxyTimingHistory::DidBeginMainFrame() { | 59 void CompositorTimingHistory::WillBeginMainFrame() { |
46 begin_main_frame_sent_time_ = base::TimeTicks::Now(); | 60 begin_main_frame_sent_time_ = base::TimeTicks::Now(); |
47 } | 61 } |
48 | 62 |
49 void ProxyTimingHistory::DidCommit() { | 63 void CompositorTimingHistory::DidCommit() { |
50 commit_complete_time_ = base::TimeTicks::Now(); | 64 commit_complete_time_ = base::TimeTicks::Now(); |
51 base::TimeDelta begin_main_frame_to_commit_duration = | 65 base::TimeDelta begin_main_frame_to_commit_duration = |
52 commit_complete_time_ - begin_main_frame_sent_time_; | 66 commit_complete_time_ - begin_main_frame_sent_time_; |
53 | 67 |
54 // 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 |
55 // 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 |
56 // of our predictions. | 70 // of our predictions. |
57 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( | 71 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( |
58 begin_main_frame_to_commit_duration, | 72 begin_main_frame_to_commit_duration, |
59 BeginMainFrameToCommitDurationEstimate()); | 73 BeginMainFrameToCommitDurationEstimate()); |
60 | 74 |
61 begin_main_frame_to_commit_duration_history_.InsertSample( | 75 begin_main_frame_to_commit_duration_history_.InsertSample( |
62 begin_main_frame_to_commit_duration); | 76 begin_main_frame_to_commit_duration); |
63 } | 77 } |
64 | 78 |
65 void ProxyTimingHistory::DidActivateSyncTree() { | 79 void CompositorTimingHistory::DidActivateSyncTree() { |
66 base::TimeDelta commit_to_activate_duration = | 80 base::TimeDelta commit_to_activate_duration = |
67 base::TimeTicks::Now() - commit_complete_time_; | 81 base::TimeTicks::Now() - commit_complete_time_; |
68 | 82 |
69 // 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 |
70 // 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 |
71 // of our predictions. | 85 // of our predictions. |
72 rendering_stats_instrumentation_->AddCommitToActivateDuration( | 86 rendering_stats_instrumentation_->AddCommitToActivateDuration( |
73 commit_to_activate_duration, CommitToActivateDurationEstimate()); | 87 commit_to_activate_duration, CommitToActivateDurationEstimate()); |
74 | 88 |
75 commit_to_activate_duration_history_.InsertSample( | 89 commit_to_activate_duration_history_.InsertSample( |
76 commit_to_activate_duration); | 90 commit_to_activate_duration); |
77 } | 91 } |
78 | 92 |
79 void ProxyTimingHistory::DidStartDrawing() { | 93 void CompositorTimingHistory::DidStartDrawing() { |
80 start_draw_time_ = base::TimeTicks::Now(); | 94 start_draw_time_ = base::TimeTicks::Now(); |
81 } | 95 } |
82 | 96 |
83 void ProxyTimingHistory::DidFinishDrawing() { | 97 void CompositorTimingHistory::DidFinishDrawing() { |
84 base::TimeDelta draw_duration = base::TimeTicks::Now() - start_draw_time_; | 98 base::TimeDelta draw_duration = base::TimeTicks::Now() - start_draw_time_; |
85 | 99 |
86 // 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 |
87 // 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 |
88 // of our predictions. | 102 // of our predictions. |
89 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 103 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
90 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, | 104 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, |
91 draw_duration_estimate); | 105 draw_duration_estimate); |
92 | 106 |
93 AddDrawDurationUMA(draw_duration, draw_duration_estimate); | 107 AddDrawDurationUMA(draw_duration, draw_duration_estimate); |
94 | 108 |
95 draw_duration_history_.InsertSample(draw_duration); | 109 draw_duration_history_.InsertSample(draw_duration); |
96 } | 110 } |
97 | 111 |
98 void ProxyTimingHistory::AddDrawDurationUMA( | 112 void CompositorTimingHistory::AddDrawDurationUMA( |
99 base::TimeDelta draw_duration, | 113 base::TimeDelta draw_duration, |
100 base::TimeDelta draw_duration_estimate) { | 114 base::TimeDelta draw_duration_estimate) { |
101 base::TimeDelta draw_duration_overestimate; | 115 base::TimeDelta draw_duration_overestimate; |
102 base::TimeDelta draw_duration_underestimate; | 116 base::TimeDelta draw_duration_underestimate; |
103 if (draw_duration > draw_duration_estimate) | 117 if (draw_duration > draw_duration_estimate) |
104 draw_duration_underestimate = draw_duration - draw_duration_estimate; | 118 draw_duration_underestimate = draw_duration - draw_duration_estimate; |
105 else | 119 else |
106 draw_duration_overestimate = draw_duration_estimate - draw_duration; | 120 draw_duration_overestimate = draw_duration_estimate - draw_duration; |
107 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", | 121 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration, |
108 draw_duration, | |
109 base::TimeDelta::FromMilliseconds(1), | 122 base::TimeDelta::FromMilliseconds(1), |
110 base::TimeDelta::FromMilliseconds(100), | 123 base::TimeDelta::FromMilliseconds(100), 50); |
111 50); | |
112 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", | 124 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", |
113 draw_duration_underestimate, | 125 draw_duration_underestimate, |
114 base::TimeDelta::FromMilliseconds(1), | 126 base::TimeDelta::FromMilliseconds(1), |
115 base::TimeDelta::FromMilliseconds(100), | 127 base::TimeDelta::FromMilliseconds(100), 50); |
116 50); | |
117 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", | 128 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", |
118 draw_duration_overestimate, | 129 draw_duration_overestimate, |
119 base::TimeDelta::FromMilliseconds(1), | 130 base::TimeDelta::FromMilliseconds(1), |
120 base::TimeDelta::FromMilliseconds(100), | 131 base::TimeDelta::FromMilliseconds(100), 50); |
121 50); | |
122 } | 132 } |
123 | 133 |
124 } // namespace cc | 134 } // namespace cc |
OLD | NEW |