Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/scheduler/compositor_timing_history.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "cc/debug/rendering_stats_instrumentation.h" | |
| 9 | |
| 10 const size_t kDurationHistorySize = 60; | |
| 11 const double kCommitAndActivationDurationEstimationPercentile = 50.0; | |
| 12 const double kActivateDurationEstimationPercentile = 100.0; | |
| 13 const double kDrawDurationEstimationPercentile = 100.0; | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 CompositorTimingHistory::CompositorTimingHistory( | |
| 18 RenderingStatsInstrumentation* rendering_stats_instrumentation) | |
| 19 : begin_main_frame_to_commit_duration_history_(kDurationHistorySize), | |
| 20 commit_to_ready_to_activate_duration_history_(kDurationHistorySize), | |
| 21 prepare_tiles_duration_history_(kDurationHistorySize), | |
| 22 activate_duration_history_(kDurationHistorySize), | |
| 23 draw_duration_history_(kDurationHistorySize), | |
| 24 rendering_stats_instrumentation_(rendering_stats_instrumentation) { | |
| 25 } | |
| 26 | |
| 27 CompositorTimingHistory::~CompositorTimingHistory() { | |
| 28 } | |
| 29 | |
| 30 void CompositorTimingHistory::PipelineReset() { | |
| 31 begin_main_frame_sent_time_ = base::TimeTicks(); | |
| 32 start_prepare_tiles_time_ = base::TimeTicks(); | |
| 33 start_activate_time_ = base::TimeTicks(); | |
| 34 start_draw_time_ = base::TimeTicks(); | |
| 35 } | |
| 36 | |
| 37 base::TimeDelta | |
| 38 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { | |
| 39 return begin_main_frame_to_commit_duration_history_.Percentile( | |
| 40 kCommitAndActivationDurationEstimationPercentile); | |
| 41 } | |
| 42 | |
| 43 base::TimeDelta CompositorTimingHistory::PrepareTilesDurationEstimate() const { | |
| 44 return prepare_tiles_duration_history_.Percentile( | |
| 45 kActivateDurationEstimationPercentile); | |
| 46 } | |
| 47 | |
| 48 base::TimeDelta | |
| 49 CompositorTimingHistory::PrepareTilesToReadyToActivateDurationEstimate() const { | |
| 50 return commit_to_ready_to_activate_duration_history_.Percentile( | |
| 51 kCommitAndActivationDurationEstimationPercentile); | |
| 52 } | |
| 53 | |
| 54 base::TimeDelta CompositorTimingHistory::ActivateDurationEstimate() const { | |
| 55 return activate_duration_history_.Percentile( | |
| 56 kActivateDurationEstimationPercentile); | |
| 57 } | |
| 58 | |
| 59 base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const { | |
| 60 return draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); | |
| 61 } | |
| 62 | |
| 63 void CompositorTimingHistory::WillBeginMainFrame() { | |
| 64 DCHECK_EQ(base::TimeTicks(), begin_main_frame_sent_time_); | |
| 65 begin_main_frame_sent_time_ = base::TimeTicks::Now(); | |
| 66 } | |
| 67 | |
| 68 void CompositorTimingHistory::BeginMainFrameAborted() { | |
| 69 DidCommit(); | |
| 70 } | |
| 71 | |
| 72 void CompositorTimingHistory::DidCommit() { | |
| 73 DCHECK_NE(base::TimeTicks(), begin_main_frame_sent_time_); | |
| 74 | |
| 75 base::TimeDelta begin_main_frame_to_commit_duration = | |
| 76 base::TimeTicks::Now() - begin_main_frame_sent_time_; | |
| 77 | |
| 78 // Before adding the new data point to the timing history, see what we would | |
| 79 // have predicted for this frame. This allows us to keep track of the accuracy | |
| 80 // of our predictions. | |
| 81 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( | |
| 82 begin_main_frame_to_commit_duration, | |
| 83 BeginMainFrameToCommitDurationEstimate()); | |
| 84 | |
| 85 begin_main_frame_to_commit_duration_history_.InsertSample( | |
| 86 begin_main_frame_to_commit_duration); | |
| 87 | |
| 88 begin_main_frame_sent_time_ = base::TimeTicks(); | |
| 89 } | |
| 90 | |
| 91 void CompositorTimingHistory::WillPrepareTiles() { | |
| 92 start_prepare_tiles_time_ = base::TimeTicks::Now(); | |
| 93 } | |
| 94 | |
| 95 void CompositorTimingHistory::DidPrepareTiles() { | |
| 96 DCHECK_NE(base::TimeTicks(), start_prepare_tiles_time_); | |
| 97 base::TimeDelta prepare_tiles_duration = | |
| 98 base::TimeTicks::Now() - start_prepare_tiles_time_; | |
| 99 prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration); | |
| 100 } | |
| 101 | |
| 102 void CompositorTimingHistory::ReadyToActivate() { | |
| 103 // If the start_prepare_tiles_time is 0, then a commit was ready to activate | |
| 104 // immediately. | |
| 105 base::TimeDelta time_since_prepare_tiles = base::TimeDelta(); | |
| 106 if (start_prepare_tiles_time_ != base::TimeTicks()) | |
| 107 base::TimeTicks::Now() - start_prepare_tiles_time_; | |
|
picksi
2015/06/19 13:04:28
Is there some C++ magic going on here that I'm mis
brianderson
2015/06/19 17:24:26
That would be pretty magical. I should add some si
| |
| 108 | |
| 109 // Before adding the new data point to the timing history, see what we would | |
| 110 // have predicted for this frame. This allows us to keep track of the accuracy | |
| 111 // of our predictions. | |
| 112 rendering_stats_instrumentation_->AddCommitToActivateDuration( | |
| 113 time_since_prepare_tiles, | |
| 114 PrepareTilesToReadyToActivateDurationEstimate()); | |
| 115 | |
| 116 commit_to_ready_to_activate_duration_history_.InsertSample( | |
| 117 time_since_prepare_tiles); | |
| 118 | |
| 119 start_prepare_tiles_time_ = base::TimeTicks(); | |
| 120 } | |
| 121 | |
| 122 void CompositorTimingHistory::WillActivate() { | |
| 123 start_activate_time_ = base::TimeTicks::Now(); | |
| 124 } | |
| 125 | |
| 126 void CompositorTimingHistory::DidActivate() { | |
| 127 base::TimeDelta activate_duration = | |
| 128 base::TimeTicks::Now() - start_activate_time_; | |
| 129 activate_duration_history_.InsertSample(activate_duration); | |
| 130 } | |
| 131 | |
| 132 void CompositorTimingHistory::WillDraw() { | |
| 133 start_draw_time_ = base::TimeTicks::Now(); | |
| 134 } | |
| 135 | |
| 136 void CompositorTimingHistory::DidDraw() { | |
| 137 base::TimeDelta draw_duration = base::TimeTicks::Now() - start_draw_time_; | |
| 138 | |
| 139 // Before adding the new data point to the timing history, see what we would | |
| 140 // have predicted for this frame. This allows us to keep track of the accuracy | |
| 141 // of our predictions. | |
| 142 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | |
| 143 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, | |
| 144 draw_duration_estimate); | |
| 145 | |
| 146 AddDrawDurationUMA(draw_duration, draw_duration_estimate); | |
| 147 | |
| 148 draw_duration_history_.InsertSample(draw_duration); | |
| 149 } | |
| 150 | |
| 151 void CompositorTimingHistory::AddDrawDurationUMA( | |
| 152 base::TimeDelta draw_duration, | |
| 153 base::TimeDelta draw_duration_estimate) { | |
| 154 base::TimeDelta draw_duration_overestimate; | |
| 155 base::TimeDelta draw_duration_underestimate; | |
| 156 if (draw_duration > draw_duration_estimate) | |
| 157 draw_duration_underestimate = draw_duration - draw_duration_estimate; | |
| 158 else | |
| 159 draw_duration_overestimate = draw_duration_estimate - draw_duration; | |
| 160 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", draw_duration, | |
| 161 base::TimeDelta::FromMilliseconds(1), | |
| 162 base::TimeDelta::FromMilliseconds(100), 50); | |
| 163 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", | |
| 164 draw_duration_underestimate, | |
| 165 base::TimeDelta::FromMilliseconds(1), | |
| 166 base::TimeDelta::FromMilliseconds(100), 50); | |
| 167 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", | |
| 168 draw_duration_overestimate, | |
| 169 base::TimeDelta::FromMilliseconds(1), | |
| 170 base::TimeDelta::FromMilliseconds(100), 50); | |
| 171 } | |
| 172 | |
| 173 } // namespace cc | |
| OLD | NEW |