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

Side by Side Diff: components/scheduler/renderer/task_cost_estimator.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 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 unified diff | Download patch
OLDNEW
(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/task_cost_estimator.h"
6
7 #include "base/time/default_tick_clock.h"
8
9 namespace scheduler {
10
11 TaskCostEstimator::TaskCostEstimator(base::TickClock* time_source,
12 int sample_count,
13 double estimation_percentile)
14 : rolling_time_delta_history_(sample_count),
15 time_source_(time_source),
16 outstanding_task_count_(0),
17 estimation_percentile_(estimation_percentile) {}
18
19 TaskCostEstimator::~TaskCostEstimator() {}
20
21 void TaskCostEstimator::WillProcessTask(const base::PendingTask& pending_task) {
22 // Avoid measuring the duration in nested run loops.
23 if (++outstanding_task_count_ == 1)
24 task_start_time_ = time_source_->NowTicks();
25 }
26
27 void TaskCostEstimator::DidProcessTask(const base::PendingTask& pending_task) {
28 if (--outstanding_task_count_ == 0) {
29 base::TimeDelta duration = time_source_->NowTicks() - task_start_time_;
30 rolling_time_delta_history_.InsertSample(duration);
31 }
32 }
33
34 base::TimeDelta TaskCostEstimator::expected_task_duration() const {
35 return rolling_time_delta_history_.Percentile(estimation_percentile_);
36 }
37
38 void TaskCostEstimator::Clear() {
39 rolling_time_delta_history_.Clear();
40 expected_task_duration_ = base::TimeDelta();
41 }
42
43 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/task_cost_estimator.h ('k') | components/scheduler/renderer/task_cost_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698