Chromium Code Reviews| 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 namespace scheduler { | |
| 8 | |
| 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) {} | |
| 14 | |
| 15 TaskCostEstimator::~TaskCostEstimator() {} | |
| 16 | |
| 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_ = base::TimeTicks::Now(); | |
| 21 } | |
| 22 | |
| 23 void TaskCostEstimator::DidProcessTask(const base::PendingTask& pending_task) { | |
| 24 if (--outstanding_task_count_ == 0) { | |
| 25 base::TimeDelta duration = base::TimeTicks::Now() - task_start_time_; | |
| 26 rolling_time_delta_history_.InsertSample(duration); | |
| 27 | |
| 28 // TODO(skyostil): Should we do this less often? | |
|
alex clarke (OOO till 29th)
2015/08/21 17:13:30
I doubt it's terribly expensive.
Sami
2015/08/21 17:42:22
Yeah, let's see if it shows up in any profiles.
| |
| 29 expected_task_duration_ = | |
| 30 rolling_time_delta_history_.Percentile(estimation_percentile_); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 } // namespace scheduler | |
| OLD | NEW |