OLD | NEW |
| (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 | |
OLD | NEW |