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 nesting_level_(0), | |
| 20 did_commit_(false) { | |
| 21 compositor_task_runner_->AddTaskObserver(this); | |
| 22 } | |
| 23 | |
| 24 IdleTimeEstimator::~IdleTimeEstimator() { | |
| 25 compositor_task_runner_->RemoveTaskObserver(this); | |
| 26 } | |
| 27 | |
| 28 base::TimeDelta IdleTimeEstimator::GetExpectedIdleDuration( | |
| 29 base::TimeDelta compositor_frame_interval) const { | |
| 30 base::TimeDelta expected_compositor_task_runtime_ = | |
| 31 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); | |
| 32 return std::max(base::TimeDelta(), compositor_frame_interval - | |
| 33 expected_compositor_task_runtime_); | |
| 34 } | |
| 35 | |
| 36 void IdleTimeEstimator::DidCommitFrameToCompositor() { | |
| 37 // This will run inside of a WillProcessTask / DidProcessTask pair, let | |
| 38 // DidProcessTask know a frame was comitted. | |
| 39 did_commit_ = true; | |
| 40 } | |
| 41 | |
| 42 void IdleTimeEstimator::Clear() { | |
| 43 task_start_time_ = base::TimeTicks(); | |
| 44 prev_commit_time_ = base::TimeTicks(); | |
| 45 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 46 per_frame_compositor_task_runtime_.Clear(); | |
| 47 did_commit_ = false; | |
| 48 } | |
| 49 | |
| 50 void IdleTimeEstimator::SetTimeSourceForTesting( | |
| 51 scoped_ptr<base::TickClock> time_source) { | |
| 52 time_source_ = time_source.Pass(); | |
| 53 } | |
| 54 | |
| 55 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { | |
| 56 nesting_level_++; | |
| 57 task_start_time_ = time_source_->NowTicks(); | |
| 58 } | |
| 59 | |
| 60 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { | |
| 61 DCHECK_EQ(nesting_level_, 1); | |
|
yurys
2015/10/20 21:11:19
This DCHECK keeps failing when pausing on JS break
| |
| 62 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; | |
| 63 | |
| 64 if (did_commit_) { | |
| 65 per_frame_compositor_task_runtime_.InsertSample( | |
| 66 cumulative_compositor_runtime_); | |
| 67 cumulative_compositor_runtime_ = base::TimeDelta(); | |
| 68 did_commit_ = false; | |
| 69 } | |
| 70 nesting_level_--; | |
| 71 } | |
| 72 | |
| 73 } // namespace scheduler | |
| OLD | NEW |