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 | |
| 9 namespace scheduler { | |
| 10 | |
| 11 IdleTimeEstimator::IdleTimeEstimator( | |
| 12 const scoped_refptr<TaskQueue>& compositor_task_runner, | |
| 13 int sample_count, | |
| 14 double estimation_percentile) | |
| 15 : compositor_task_runner_(compositor_task_runner), | |
| 16 per_frame_compositor_task_runtime_(sample_count), | |
| 17 time_source_(new base::DefaultTickClock), | |
| 18 estimation_percentile_(estimation_percentile), | |
| 19 did_commit_(false) { | |
| 20 compositor_task_runner_->AddTaskObserver(this); | |
| 21 } | |
| 22 | |
| 23 IdleTimeEstimator::~IdleTimeEstimator() { | |
| 24 compositor_task_runner_->RemoveTaskObserver(this); | |
| 25 } | |
| 26 | |
| 27 base::TimeDelta IdleTimeEstimator::GetExpectedIdleDuration( | |
| 28 base::TimeDelta compositor_frame_interval) const { | |
| 29 base::TimeDelta expected_compositor_task_runtime_ = | |
| 30 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); | |
| 31 return std::max(base::TimeDelta(), compositor_frame_interval - | |
| 32 expected_compositor_task_runtime_); | |
| 33 } | |
| 34 | |
| 35 void IdleTimeEstimator::DidCommitFrameToCompositor() { | |
| 36 // This will run inside of a WillProcessTask / DidProcessTask pair, let | |
| 37 // DidProcessTask know a frame was comitted. | |
| 38 did_commit_ = true; | |
| 39 } | |
| 40 | |
| 41 void IdleTimeEstimator::Clear() { | |
| 42 task_start_time_ = base::TimeTicks(); | |
| 43 prev_commit_time_ = base::TimeTicks(); | |
| 44 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 45 per_frame_compositor_task_runtime_.Clear(); | |
| 46 did_commit_ = false; | |
| 47 } | |
| 48 | |
| 49 void IdleTimeEstimator::SetTimeSourceForTesting( | |
| 50 scoped_ptr<base::TickClock> time_source) { | |
| 51 time_source_ = time_source.Pass(); | |
| 52 } | |
| 53 | |
| 54 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { | |
| 55 task_start_time_ = time_source_->NowTicks(); | |
|
Sami
2015/10/15 14:43:04
By the way we now have thread time support on all
alex clarke (OOO till 29th)
2015/10/15 16:07:52
Yeah I think that would be best.
| |
| 56 } | |
| 57 | |
| 58 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { | |
| 59 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; | |
|
Sami
2015/10/15 14:43:04
Could you add a DCHECK() here that we're not runni
alex clarke (OOO till 29th)
2015/10/15 16:07:52
Done.
| |
| 60 | |
| 61 if (did_commit_) { | |
| 62 per_frame_compositor_task_runtime_.InsertSample( | |
| 63 cumulative_compositor_runtime_); | |
| 64 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 65 did_commit_ = false; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 } // namespace scheduler | |
| OLD | NEW |