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

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

Issue 1303353003: scheduler: Disable expensive timers during main thread user input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed hardcoding. Created 5 years, 4 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/task_cost_estimator.cc
diff --git a/components/scheduler/renderer/task_cost_estimator.cc b/components/scheduler/renderer/task_cost_estimator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a806ec20fe38663bc69892cb73da6106407852ac
--- /dev/null
+++ b/components/scheduler/renderer/task_cost_estimator.cc
@@ -0,0 +1,34 @@
+// 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/task_cost_estimator.h"
+
+namespace scheduler {
+
+TaskCostEstimator::TaskCostEstimator(int sample_count,
+ double estimation_percentile)
+ : rolling_time_delta_history_(sample_count),
+ outstanding_task_count_(0),
+ estimation_percentile_(estimation_percentile) {}
+
+TaskCostEstimator::~TaskCostEstimator() {}
+
+void TaskCostEstimator::WillProcessTask(const base::PendingTask& pending_task) {
+ // Avoid measuring the duration in nested run loops.
+ if (++outstanding_task_count_ == 1)
alex clarke (OOO till 29th) 2015/08/21 17:56:46 Ack nested loops, we need a test sorry ;)
Sami 2015/08/21 18:14:42 Agreed, bane of my existence, done.
+ task_start_time_ = base::TimeTicks::Now();
+}
+
+void TaskCostEstimator::DidProcessTask(const base::PendingTask& pending_task) {
+ if (--outstanding_task_count_ == 0) {
+ base::TimeDelta duration = base::TimeTicks::Now() - task_start_time_;
+ rolling_time_delta_history_.InsertSample(duration);
+
+ // TODO(skyostil): Should we do this less often?
+ expected_task_duration_ =
+ rolling_time_delta_history_.Percentile(estimation_percentile_);
+ }
+}
+
+} // namespace scheduler

Powered by Google App Engine
This is Rietveld 408576698