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.
5 #include "components/scheduler/renderer/task_cost_estimator.h"
9 TaskCostEstimator::TaskCostEstimator(int sample_count
,
10 double estimation_percentile
)
11 : rolling_time_delta_history_(sample_count
),
12 outstanding_task_count_(0),
13 estimation_percentile_(estimation_percentile
) {}
15 TaskCostEstimator::~TaskCostEstimator() {}
17 void TaskCostEstimator::WillProcessTask(const base::PendingTask
& pending_task
) {
18 // Avoid measuring the duration in nested run loops.
19 if (++outstanding_task_count_
== 1)
20 task_start_time_
= Now();
23 void TaskCostEstimator::DidProcessTask(const base::PendingTask
& pending_task
) {
24 if (--outstanding_task_count_
== 0) {
25 base::TimeDelta duration
= Now() - task_start_time_
;
26 rolling_time_delta_history_
.InsertSample(duration
);
28 // TODO(skyostil): Should we do this less often?
29 expected_task_duration_
=
30 rolling_time_delta_history_
.Percentile(estimation_percentile_
);
34 base::TimeTicks
TaskCostEstimator::Now() {
35 return base::TimeTicks::Now();
38 } // namespace scheduler