Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/scheduler/renderer/idle_time_estimator.h" | 5 #include "components/scheduler/renderer/idle_time_estimator.h" |
| 6 | 6 |
| 7 #include "base/time/default_tick_clock.h" | 7 #include "base/time/default_tick_clock.h" |
| 8 | 8 |
| 9 namespace scheduler { | 9 namespace scheduler { |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 base::TimeDelta compositor_frame_interval) const { | 29 base::TimeDelta compositor_frame_interval) const { |
| 30 base::TimeDelta expected_compositor_task_runtime_ = | 30 base::TimeDelta expected_compositor_task_runtime_ = |
| 31 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); | 31 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); |
| 32 return std::max(base::TimeDelta(), compositor_frame_interval - | 32 return std::max(base::TimeDelta(), compositor_frame_interval - |
| 33 expected_compositor_task_runtime_); | 33 expected_compositor_task_runtime_); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void IdleTimeEstimator::DidCommitFrameToCompositor() { | 36 void IdleTimeEstimator::DidCommitFrameToCompositor() { |
| 37 // This will run inside of a WillProcessTask / DidProcessTask pair, let | 37 // This will run inside of a WillProcessTask / DidProcessTask pair, let |
| 38 // DidProcessTask know a frame was comitted. | 38 // DidProcessTask know a frame was comitted. |
| 39 did_commit_ = true; | 39 if (nesting_level_ == 1) |
| 40 did_commit_ = true; | |
| 40 } | 41 } |
| 41 | 42 |
| 42 void IdleTimeEstimator::Clear() { | 43 void IdleTimeEstimator::Clear() { |
| 43 task_start_time_ = base::TimeTicks(); | 44 task_start_time_ = base::TimeTicks(); |
| 44 prev_commit_time_ = base::TimeTicks(); | 45 prev_commit_time_ = base::TimeTicks(); |
| 45 cumulative_compositor_runtime_ = base::TimeDelta(); | 46 cumulative_compositor_runtime_ = base::TimeDelta(); |
| 46 per_frame_compositor_task_runtime_.Clear(); | 47 per_frame_compositor_task_runtime_.Clear(); |
| 47 did_commit_ = false; | 48 did_commit_ = false; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void IdleTimeEstimator::SetTimeSourceForTesting( | 51 void IdleTimeEstimator::SetTimeSourceForTesting( |
| 51 scoped_ptr<base::TickClock> time_source) { | 52 scoped_ptr<base::TickClock> time_source) { |
| 52 time_source_ = time_source.Pass(); | 53 time_source_ = time_source.Pass(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { | 56 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { |
| 56 nesting_level_++; | 57 nesting_level_++; |
| 57 task_start_time_ = time_source_->NowTicks(); | 58 if (nesting_level_ == 1) |
| 59 task_start_time_ = time_source_->NowTicks(); | |
| 58 } | 60 } |
| 59 | 61 |
| 60 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { | 62 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { |
| 61 DCHECK_EQ(nesting_level_, 1); | 63 nesting_level_--; |
|
Sami
2015/10/16 10:52:11
nit: DCHECK_GT(nesting_level_, 0);
alex clarke (OOO till 29th)
2015/10/16 10:54:46
Done.
| |
| 64 if (nesting_level_ != 0) | |
| 65 return; | |
| 66 | |
| 62 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; | 67 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; |
| 63 | 68 |
| 64 if (did_commit_) { | 69 if (did_commit_) { |
| 65 per_frame_compositor_task_runtime_.InsertSample( | 70 per_frame_compositor_task_runtime_.InsertSample( |
| 66 cumulative_compositor_runtime_); | 71 cumulative_compositor_runtime_); |
| 67 cumulative_compositor_runtime_ = base::TimeDelta(); | 72 cumulative_compositor_runtime_ = base::TimeDelta(); |
| 68 did_commit_ = false; | 73 did_commit_ = false; |
| 69 } | 74 } |
| 70 nesting_level_--; | |
| 71 } | 75 } |
| 72 | 76 |
| 73 } // namespace scheduler | 77 } // namespace scheduler |
| OLD | NEW |