Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "platform/scheduler/renderer/task_queue_throttler.h" | 5 #include "platform/scheduler/renderer/task_queue_throttler.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 151 } |
| 152 | 152 |
| 153 // TODO(altimin): We need to disable TimeBudgetQueues here or they will | 153 // TODO(altimin): We need to disable TimeBudgetQueues here or they will |
| 154 // regenerate extra time budget when they are disabled. | 154 // regenerate extra time budget when they are disabled. |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool TaskQueueThrottler::TimeBudgetPool::IsThrottlingEnabled() const { | 157 bool TaskQueueThrottler::TimeBudgetPool::IsThrottlingEnabled() const { |
| 158 return is_enabled_; | 158 return is_enabled_; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void TaskQueueThrottler::TimeBudgetPool::SetReportingCallback( | |
| 162 base::Callback<void(base::TimeDelta)> reporting_callback) { | |
| 163 reporting_callback_ = reporting_callback; | |
| 164 } | |
| 165 | |
| 161 void TaskQueueThrottler::TimeBudgetPool::Close() { | 166 void TaskQueueThrottler::TimeBudgetPool::Close() { |
| 162 DCHECK_EQ(0u, associated_task_queues_.size()); | 167 DCHECK_EQ(0u, associated_task_queues_.size()); |
| 163 | 168 |
| 164 task_queue_throttler_->time_budget_pools_.erase(this); | 169 task_queue_throttler_->time_budget_pools_.erase(this); |
| 165 } | 170 } |
| 166 | 171 |
| 167 bool TaskQueueThrottler::TimeBudgetPool::HasEnoughBudgetToRun( | 172 bool TaskQueueThrottler::TimeBudgetPool::HasEnoughBudgetToRun( |
| 168 base::TimeTicks now) { | 173 base::TimeTicks now) { |
| 169 Advance(now); | 174 Advance(now); |
| 170 return !is_enabled_ || current_budget_level_.InMicroseconds() >= 0; | 175 return !is_enabled_ || current_budget_level_.InMicroseconds() >= 0; |
| 171 } | 176 } |
| 172 | 177 |
| 173 base::TimeTicks TaskQueueThrottler::TimeBudgetPool::GetNextAllowedRunTime() { | 178 base::TimeTicks TaskQueueThrottler::TimeBudgetPool::GetNextAllowedRunTime() { |
| 174 if (!is_enabled_ || current_budget_level_.InMicroseconds() >= 0) { | 179 if (!is_enabled_ || current_budget_level_.InMicroseconds() >= 0) { |
| 175 return last_checkpoint_; | 180 return last_checkpoint_; |
| 176 } else { | 181 } else { |
| 177 // Subtract because current_budget is negative. | 182 // Subtract because current_budget is negative. |
| 178 return last_checkpoint_ - current_budget_level_ / cpu_percentage_; | 183 return last_checkpoint_ - current_budget_level_ / cpu_percentage_; |
| 179 } | 184 } |
| 180 } | 185 } |
| 181 | 186 |
| 182 void TaskQueueThrottler::TimeBudgetPool::RecordTaskRunTime( | 187 void TaskQueueThrottler::TimeBudgetPool::RecordTaskRunTime( |
| 183 base::TimeTicks start_time, | 188 base::TimeTicks start_time, |
| 184 base::TimeTicks end_time) { | 189 base::TimeTicks end_time) { |
| 185 DCHECK_LE(start_time, end_time); | 190 DCHECK_LE(start_time, end_time); |
| 186 Advance(end_time); | 191 Advance(end_time); |
| 187 if (is_enabled_) { | 192 if (is_enabled_) { |
| 193 base::TimeDelta old_budget_level = current_budget_level_; | |
| 188 current_budget_level_ -= (end_time - start_time); | 194 current_budget_level_ -= (end_time - start_time); |
| 189 EnforceBudgetLevelRestrictions(); | 195 EnforceBudgetLevelRestrictions(); |
| 196 | |
| 197 if (!reporting_callback_.is_null() && old_budget_level.InSecondsF() > 0 && | |
| 198 current_budget_level_.InSecondsF() < 0) { | |
| 199 reporting_callback_.Run(-current_budget_level_ / cpu_percentage_); | |
|
Sami
2016/11/08 19:05:08
nit: Is forgot if calling a null callback is a no-
altimin
2016/11/08 19:08:47
It's a failure, unfortunately.
| |
| 200 } | |
| 190 } | 201 } |
| 191 } | 202 } |
| 192 | 203 |
| 193 const char* TaskQueueThrottler::TimeBudgetPool::Name() const { | 204 const char* TaskQueueThrottler::TimeBudgetPool::Name() const { |
| 194 return name_; | 205 return name_; |
| 195 } | 206 } |
| 196 | 207 |
| 197 void TaskQueueThrottler::TimeBudgetPool::AsValueInto( | 208 void TaskQueueThrottler::TimeBudgetPool::AsValueInto( |
| 198 base::trace_event::TracedValue* state, | 209 base::trace_event::TracedValue* state, |
| 199 base::TimeTicks now) const { | 210 base::TimeTicks now) const { |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 | 626 |
| 616 queue->SetQueueEnabled(false); | 627 queue->SetQueueEnabled(false); |
| 617 queue->SetTimeDomain(time_domain_.get()); | 628 queue->SetTimeDomain(time_domain_.get()); |
| 618 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, | 629 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, |
| 619 GetNextAllowedRunTime(lazy_now.Now(), queue)); | 630 GetNextAllowedRunTime(lazy_now.Now(), queue)); |
| 620 } | 631 } |
| 621 } | 632 } |
| 622 | 633 |
| 623 } // namespace scheduler | 634 } // namespace scheduler |
| 624 } // namespace blink | 635 } // namespace blink |
| OLD | NEW |