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

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

Issue 1424053002: Adds a flag to support "Virtual Time" to the blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 1 month 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
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/task_cost_estimator.h" 5 #include "components/scheduler/renderer/task_cost_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
11 TaskCostEstimator::TaskCostEstimator(int sample_count, 11 TaskCostEstimator::TaskCostEstimator(base::TickClock* time_source,
12 int sample_count,
12 double estimation_percentile) 13 double estimation_percentile)
13 : rolling_time_delta_history_(sample_count), 14 : rolling_time_delta_history_(sample_count),
14 time_source_(new base::DefaultTickClock), 15 time_source_(time_source),
15 outstanding_task_count_(0), 16 outstanding_task_count_(0),
16 estimation_percentile_(estimation_percentile) {} 17 estimation_percentile_(estimation_percentile) {}
17 18
18 TaskCostEstimator::~TaskCostEstimator() {} 19 TaskCostEstimator::~TaskCostEstimator() {}
19 20
20 void TaskCostEstimator::WillProcessTask(const base::PendingTask& pending_task) { 21 void TaskCostEstimator::WillProcessTask(const base::PendingTask& pending_task) {
21 // Avoid measuring the duration in nested run loops. 22 // Avoid measuring the duration in nested run loops.
22 if (++outstanding_task_count_ == 1) 23 if (++outstanding_task_count_ == 1)
23 task_start_time_ = time_source_->NowTicks(); 24 task_start_time_ = time_source_->NowTicks();
24 } 25 }
25 26
26 void TaskCostEstimator::DidProcessTask(const base::PendingTask& pending_task) { 27 void TaskCostEstimator::DidProcessTask(const base::PendingTask& pending_task) {
27 if (--outstanding_task_count_ == 0) { 28 if (--outstanding_task_count_ == 0) {
28 base::TimeDelta duration = time_source_->NowTicks() - task_start_time_; 29 base::TimeDelta duration = time_source_->NowTicks() - task_start_time_;
29 rolling_time_delta_history_.InsertSample(duration); 30 rolling_time_delta_history_.InsertSample(duration);
30 } 31 }
31 } 32 }
32 33
33 base::TimeDelta TaskCostEstimator::expected_task_duration() const { 34 base::TimeDelta TaskCostEstimator::expected_task_duration() const {
34 return rolling_time_delta_history_.Percentile(estimation_percentile_); 35 return rolling_time_delta_history_.Percentile(estimation_percentile_);
35 } 36 }
36 37
37 void TaskCostEstimator::Clear() { 38 void TaskCostEstimator::Clear() {
38 rolling_time_delta_history_.Clear(); 39 rolling_time_delta_history_.Clear();
39 expected_task_duration_ = base::TimeDelta(); 40 expected_task_duration_ = base::TimeDelta();
40 } 41 }
41 42
42 void TaskCostEstimator::SetTimeSourceForTesting(
43 scoped_ptr<base::TickClock> time_source) {
44 time_source_ = time_source.Pass();
45 }
46
47 } // namespace scheduler 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