Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Unified Diff: components/scheduler/renderer/idle_time_estimator.cc

Issue 1381273002: A better idle time estimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to feedback Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/scheduler/renderer/idle_time_estimator.cc
diff --git a/components/scheduler/renderer/idle_time_estimator.cc b/components/scheduler/renderer/idle_time_estimator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b2b4f13d511fa6d28d124af189d5cdaf36e8507b
--- /dev/null
+++ b/components/scheduler/renderer/idle_time_estimator.cc
@@ -0,0 +1,69 @@
+// 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 "components/scheduler/renderer/idle_time_estimator.h"
+
+#include "base/time/default_tick_clock.h"
+
+namespace scheduler {
+
+IdleTimeEstimator::IdleTimeEstimator(
+ const scoped_refptr<TaskQueue>& compositor_task_runner,
+ int sample_count,
+ double estimation_percentile)
+ : compositor_task_runner_(compositor_task_runner),
+ per_frame_compositor_task_runtime_(sample_count),
+ time_source_(new base::DefaultTickClock),
+ estimation_percentile_(estimation_percentile),
+ did_commit_(false) {
+ compositor_task_runner_->AddTaskObserver(this);
+}
+
+IdleTimeEstimator::~IdleTimeEstimator() {
+ compositor_task_runner_->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.
+ 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::SetTimeSourceForTesting(
+ scoped_ptr<base::TickClock> time_source) {
+ time_source_ = time_source.Pass();
+}
+
+void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) {
+ 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.
+}
+
+void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) {
+ 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.
+
+ if (did_commit_) {
+ per_frame_compositor_task_runtime_.InsertSample(
+ cumulative_compositor_runtime_);
+ cumulative_compositor_runtime_ = base::TimeDelta();
+ did_commit_ = false;
+ }
+}
+
+} // namespace scheduler

Powered by Google App Engine
This is Rietveld 408576698