Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "components/scheduler/renderer/idle_time_estimator.h" | |
| 6 | |
| 7 #include "base/time/default_tick_clock.h" | |
| 8 #include "cc/output/begin_frame_args.h" | |
| 9 | |
| 10 namespace scheduler { | |
| 11 | |
| 12 IdleTimeEstimator::IdleTimeEstimator(int sample_count, | |
| 13 double estimation_percentile) | |
| 14 : frame_length_(sample_count), | |
| 15 per_frame_compositor_task_runtime_(sample_count), | |
| 16 time_source_(new base::DefaultTickClock), | |
| 17 estimation_percentile_(estimation_percentile), | |
| 18 did_commit_(false) { | |
| 19 // Make sure that we don't initially assume there is no idle time. | |
| 20 frame_length_.InsertSample(cc::BeginFrameArgs::DefaultInterval()); | |
| 21 } | |
| 22 | |
| 23 IdleTimeEstimator::~IdleTimeEstimator() {} | |
| 24 | |
| 25 base::TimeDelta IdleTimeEstimator::GetExpectedIdleDuration( | |
| 26 base::TimeDelta max_frame_length) const { | |
| 27 base::TimeDelta expected_frame_length = std::min( | |
|
Sami
2015/10/09 02:32:18
Are we getting any information out of this frame l
alex clarke (OOO till 29th)
2015/10/15 13:24:01
Done.
| |
| 28 frame_length_.Percentile(estimation_percentile_), max_frame_length); | |
| 29 base::TimeDelta expected_compositor_task_runtime_ = | |
| 30 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); | |
| 31 return std::max(base::TimeDelta(), | |
| 32 expected_frame_length - expected_compositor_task_runtime_); | |
| 33 } | |
| 34 | |
| 35 void IdleTimeEstimator::DidCommitFrameToCompositor() { | |
| 36 base::TimeTicks commit_time = time_source_->NowTicks(); | |
| 37 if (!prev_commit_time_.is_null()) | |
| 38 frame_length_.InsertSample(commit_time - prev_commit_time_); | |
| 39 prev_commit_time_ = commit_time; | |
| 40 | |
| 41 // This will run inside of a WillProcessTask / DidProcessTask pair, let | |
| 42 // DidProcessTask know a frame was comitted. | |
| 43 did_commit_ = true; | |
| 44 } | |
| 45 | |
| 46 void IdleTimeEstimator::Clear() { | |
| 47 task_start_time_ = base::TimeTicks(); | |
| 48 prev_commit_time_ = base::TimeTicks(); | |
| 49 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 50 frame_length_.Clear(); | |
| 51 per_frame_compositor_task_runtime_.Clear(); | |
| 52 did_commit_ = false; | |
| 53 | |
| 54 // Make sure that we don't initially assume there is no idle time. | |
| 55 frame_length_.InsertSample(cc::BeginFrameArgs::DefaultInterval()); | |
| 56 } | |
| 57 | |
| 58 void IdleTimeEstimator::SetTimeSourceForTesting( | |
| 59 scoped_ptr<base::TickClock> time_source) { | |
| 60 time_source_ = time_source.Pass(); | |
| 61 } | |
| 62 | |
| 63 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { | |
| 64 task_start_time_ = time_source_->NowTicks(); | |
| 65 } | |
| 66 | |
| 67 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { | |
| 68 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; | |
| 69 | |
| 70 if (did_commit_) { | |
| 71 per_frame_compositor_task_runtime_.InsertSample( | |
| 72 cumulative_compositor_runtime_); | |
| 73 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 74 did_commit_ = false; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace scheduler | |
| OLD | NEW |