| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/cpu_time_budget_pool.h" | 5 #include "platform/scheduler/renderer/cpu_time_budget_pool.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 #include "base/optional.h" | 11 #include "base/optional.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "platform/scheduler/base/trace_helper.h" |
| 14 #include "platform/scheduler/renderer/task_queue_throttler.h" | 13 #include "platform/scheduler/renderer/task_queue_throttler.h" |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 namespace scheduler { | 16 namespace scheduler { |
| 18 | 17 |
| 19 namespace { | |
| 20 | |
| 21 std::string PointerToId(void* pointer) { | |
| 22 return base::StringPrintf( | |
| 23 "0x%" PRIx64, | |
| 24 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(pointer))); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 CPUTimeBudgetPool::CPUTimeBudgetPool( | 18 CPUTimeBudgetPool::CPUTimeBudgetPool( |
| 30 const char* name, | 19 const char* name, |
| 31 BudgetPoolController* budget_pool_controller, | 20 BudgetPoolController* budget_pool_controller, |
| 32 base::TimeTicks now) | 21 base::TimeTicks now) |
| 33 : BudgetPool(name, budget_pool_controller), | 22 : BudgetPool(name, budget_pool_controller), |
| 34 last_checkpoint_(now), | 23 last_checkpoint_(now), |
| 35 cpu_percentage_(1) {} | 24 cpu_percentage_(1) {} |
| 36 | 25 |
| 37 CPUTimeBudgetPool::~CPUTimeBudgetPool() {} | 26 CPUTimeBudgetPool::~CPUTimeBudgetPool() {} |
| 38 | 27 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 state->SetDouble("max_throttling_delay_in_seconds", | 135 state->SetDouble("max_throttling_delay_in_seconds", |
| 147 max_throttling_delay_.value().InSecondsF()); | 136 max_throttling_delay_.value().InSecondsF()); |
| 148 } | 137 } |
| 149 if (max_budget_level_) { | 138 if (max_budget_level_) { |
| 150 state->SetDouble("max_budget_level_in_seconds", | 139 state->SetDouble("max_budget_level_in_seconds", |
| 151 max_budget_level_.value().InSecondsF()); | 140 max_budget_level_.value().InSecondsF()); |
| 152 } | 141 } |
| 153 | 142 |
| 154 state->BeginArray("task_queues"); | 143 state->BeginArray("task_queues"); |
| 155 for (TaskQueue* queue : associated_task_queues_) { | 144 for (TaskQueue* queue : associated_task_queues_) { |
| 156 state->AppendString(PointerToId(queue)); | 145 state->AppendString(trace_helper::PointerToString(queue)); |
| 157 } | 146 } |
| 158 state->EndArray(); | 147 state->EndArray(); |
| 159 | 148 |
| 160 state->EndDictionary(); | 149 state->EndDictionary(); |
| 161 } | 150 } |
| 162 | 151 |
| 163 void CPUTimeBudgetPool::Advance(base::TimeTicks now) { | 152 void CPUTimeBudgetPool::Advance(base::TimeTicks now) { |
| 164 if (now > last_checkpoint_) { | 153 if (now > last_checkpoint_) { |
| 165 if (is_enabled_) { | 154 if (is_enabled_) { |
| 166 current_budget_level_ += cpu_percentage_ * (now - last_checkpoint_); | 155 current_budget_level_ += cpu_percentage_ * (now - last_checkpoint_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 178 if (max_throttling_delay_) { | 167 if (max_throttling_delay_) { |
| 179 // Current budget level may be negative. | 168 // Current budget level may be negative. |
| 180 current_budget_level_ = | 169 current_budget_level_ = |
| 181 std::max(current_budget_level_, | 170 std::max(current_budget_level_, |
| 182 -max_throttling_delay_.value() * cpu_percentage_); | 171 -max_throttling_delay_.value() * cpu_percentage_); |
| 183 } | 172 } |
| 184 } | 173 } |
| 185 | 174 |
| 186 } // namespace scheduler | 175 } // namespace scheduler |
| 187 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |