diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:20:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:28:57 +0000 |
commit | d17ea114e5ef69ad5d5d7413280a13e6428098aa (patch) | |
tree | 2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc | |
parent | 8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff) | |
download | qtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz |
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc b/chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc new file mode 100644 index 00000000000..4ee87d3e6cb --- /dev/null +++ b/chromium/third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.cc @@ -0,0 +1,76 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/platform/scheduler/renderer/idle_time_estimator.h" + +#include "base/time/default_tick_clock.h" + +namespace blink { +namespace scheduler { + +IdleTimeEstimator::IdleTimeEstimator( + const scoped_refptr<TaskQueue>& compositor_task_runner, + const base::TickClock* time_source, + int sample_count, + double estimation_percentile) + : compositor_task_queue_(compositor_task_runner), + per_frame_compositor_task_runtime_(sample_count), + time_source_(time_source), + estimation_percentile_(estimation_percentile), + nesting_level_(0), + did_commit_(false) { + compositor_task_queue_->AddTaskObserver(this); +} + +IdleTimeEstimator::~IdleTimeEstimator() { + compositor_task_queue_->RemoveTaskObserver(this); +} + +base::TimeDelta IdleTimeEstimator::GetExpectedIdleDuration( + base::TimeDelta compositor_frame_interval) const { + base::TimeDelta expected_compositor_task_runtime_ = + per_frame_compositor_task_runtime_.Percentile(estimation_percentile_); + return std::max(base::TimeDelta(), compositor_frame_interval - + expected_compositor_task_runtime_); +} + +void IdleTimeEstimator::DidCommitFrameToCompositor() { + // This will run inside of a WillProcessTask / DidProcessTask pair, let + // DidProcessTask know a frame was comitted. + if (nesting_level_ == 1) + did_commit_ = true; +} + +void IdleTimeEstimator::Clear() { + task_start_time_ = base::TimeTicks(); + prev_commit_time_ = base::TimeTicks(); + cumulative_compositor_runtime_ = base::TimeDelta(); + per_frame_compositor_task_runtime_.Clear(); + did_commit_ = false; +} + +void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { + nesting_level_++; + if (nesting_level_ == 1) + task_start_time_ = time_source_->NowTicks(); +} + +void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { + nesting_level_--; + DCHECK_GE(nesting_level_, 0); + if (nesting_level_ != 0) + return; + + cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; + + if (did_commit_) { + per_frame_compositor_task_runtime_.InsertSample( + cumulative_compositor_runtime_); + cumulative_compositor_runtime_ = base::TimeDelta(); + did_commit_ = false; + } +} + +} // namespace scheduler +} // namespace blink |