| 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 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_
H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_
H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_
H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_
H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Adds |queue| to given pool. If the pool restriction does not allow | 62 // Adds |queue| to given pool. If the pool restriction does not allow |
| 63 // a task to be run immediately and |queue| is throttled, |queue| becomes | 63 // a task to be run immediately and |queue| is throttled, |queue| becomes |
| 64 // disabled. | 64 // disabled. |
| 65 void AddQueue(base::TimeTicks now, TaskQueue* queue); | 65 void AddQueue(base::TimeTicks now, TaskQueue* queue); |
| 66 | 66 |
| 67 // Removes |queue| from given pool. If it is throttled, it does not | 67 // Removes |queue| from given pool. If it is throttled, it does not |
| 68 // become enabled immediately, but a call to |PumpThrottledTasks| | 68 // become enabled immediately, but a call to |PumpThrottledTasks| |
| 69 // is scheduled. | 69 // is scheduled. |
| 70 void RemoveQueue(base::TimeTicks now, TaskQueue* queue); | 70 void RemoveQueue(base::TimeTicks now, TaskQueue* queue); |
| 71 | 71 |
| 72 void RecordTaskRunTime(base::TimeDelta task_run_time); | 72 void RecordTaskRunTime(base::TimeTicks start_time, |
| 73 base::TimeTicks end_time); |
| 73 | 74 |
| 74 // Enables this time budget pool. Queues from this pool will be | 75 // Enables this time budget pool. Queues from this pool will be |
| 75 // throttled based on their run time. | 76 // throttled based on their run time. |
| 76 void EnableThrottling(LazyNow* now); | 77 void EnableThrottling(LazyNow* now); |
| 77 | 78 |
| 78 // Disables with time budget pool. Queues from this pool will not be | 79 // Disables with time budget pool. Queues from this pool will not be |
| 79 // throttled based on their run time. A call to |PumpThrottledTasks| | 80 // throttled based on their run time. A call to |PumpThrottledTasks| |
| 80 // will be scheduled to enable this queues back again and respect | 81 // will be scheduled to enable this queues back again and respect |
| 81 // timer alignment. Internal budget level will not regenerate with time. | 82 // timer alignment. Internal budget level will not regenerate with time. |
| 82 void DisableThrottling(LazyNow* now); | 83 void DisableThrottling(LazyNow* now); |
| 83 | 84 |
| 84 bool IsThrottlingEnabled() const; | 85 bool IsThrottlingEnabled() const; |
| 85 | 86 |
| 86 const char* Name() const; | 87 const char* Name() const; |
| 87 | 88 |
| 88 // All queues should be removed before calling Close(). | 89 // All queues should be removed before calling Close(). |
| 89 void Close(); | 90 void Close(); |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 friend class TaskQueueThrottler; | 93 friend class TaskQueueThrottler; |
| 93 | 94 |
| 94 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, TimeBudgetPool); | 95 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, TimeBudgetPool); |
| 95 | 96 |
| 96 TimeBudgetPool(const char* name, | 97 TimeBudgetPool(const char* name, |
| 97 TaskQueueThrottler* task_queue_throttler, | 98 TaskQueueThrottler* task_queue_throttler, |
| 98 base::TimeTicks now); | 99 base::TimeTicks now, |
| 100 base::Optional<base::TimeDelta> max_budget_level, |
| 101 base::Optional<base::TimeDelta> max_throttling_duration); |
| 99 | 102 |
| 100 bool HasEnoughBudgetToRun(base::TimeTicks now); | 103 bool HasEnoughBudgetToRun(base::TimeTicks now); |
| 101 base::TimeTicks GetNextAllowedRunTime(); | 104 base::TimeTicks GetNextAllowedRunTime(); |
| 102 | 105 |
| 103 // Advances |last_checkpoint_| to |now| if needed and recalculates | 106 // Advances |last_checkpoint_| to |now| if needed and recalculates |
| 104 // budget level. | 107 // budget level. |
| 105 void Advance(base::TimeTicks now); | 108 void Advance(base::TimeTicks now); |
| 106 | 109 |
| 107 // Returns state for tracing. | 110 // Returns state for tracing. |
| 108 void AsValueInto(base::trace_event::TracedValue* state, | 111 void AsValueInto(base::trace_event::TracedValue* state, |
| 109 base::TimeTicks now) const; | 112 base::TimeTicks now) const; |
| 110 | 113 |
| 111 // Disable all associated throttled queues. | 114 // Disable all associated throttled queues. |
| 112 void BlockThrottledQueues(base::TimeTicks now); | 115 void BlockThrottledQueues(base::TimeTicks now); |
| 113 | 116 |
| 117 // Increase current_budget_level_ to satisfy max throttling duration |
| 118 // condition if necessary. |
| 119 void EnforceMaximalThrottlingDuration(); |
| 120 |
| 114 const char* name_; // NOT OWNED | 121 const char* name_; // NOT OWNED |
| 115 | 122 |
| 116 TaskQueueThrottler* task_queue_throttler_; | 123 TaskQueueThrottler* task_queue_throttler_; |
| 117 | 124 |
| 125 // Max budget level which we can accrue. |
| 126 // Tasks will be allowed to run for this time before being throttled |
| 127 // after a very long period of inactivity. |
| 128 base::Optional<base::TimeDelta> max_budget_level_; |
| 129 // Max throttling duration places a lower limit on time budget level, |
| 130 // ensuring that one long task does not cause extremely long throttling. |
| 131 // Note that this is not the guarantee that every task will run |
| 132 // after desired run time + max throttling duration, but a guarantee |
| 133 // that at least one task will be run every max_throttling_duration. |
| 134 base::Optional<base::TimeDelta> max_throttling_duration_; |
| 135 |
| 118 base::TimeDelta current_budget_level_; | 136 base::TimeDelta current_budget_level_; |
| 119 base::TimeDelta max_budget_level_; | |
| 120 base::TimeTicks last_checkpoint_; | 137 base::TimeTicks last_checkpoint_; |
| 121 double cpu_percentage_; | 138 double cpu_percentage_; |
| 122 bool is_enabled_; | 139 bool is_enabled_; |
| 123 | 140 |
| 124 std::unordered_set<TaskQueue*> associated_task_queues_; | 141 std::unordered_set<TaskQueue*> associated_task_queues_; |
| 125 | 142 |
| 126 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); | 143 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); |
| 127 }; | 144 }; |
| 128 | 145 |
| 129 // TODO(altimin): Do not pass tracing category as const char*, | 146 // TODO(altimin): Do not pass tracing category as const char*, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); | 246 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); |
| 230 | 247 |
| 231 TaskQueueMap queue_details_; | 248 TaskQueueMap queue_details_; |
| 232 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; | 249 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; |
| 233 scoped_refptr<TaskQueue> task_runner_; | 250 scoped_refptr<TaskQueue> task_runner_; |
| 234 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 251 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
| 235 base::TickClock* tick_clock_; // NOT OWNED | 252 base::TickClock* tick_clock_; // NOT OWNED |
| 236 const char* tracing_category_; // NOT OWNED | 253 const char* tracing_category_; // NOT OWNED |
| 237 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 254 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
| 238 | 255 |
| 256 base::Optional<base::TimeDelta> max_budget_level_; |
| 257 base::Optional<base::TimeDelta> max_throttling_duration_; |
| 258 |
| 239 CancelableClosureHolder pump_throttled_tasks_closure_; | 259 CancelableClosureHolder pump_throttled_tasks_closure_; |
| 240 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; | 260 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
| 241 bool virtual_time_; | 261 bool virtual_time_; |
| 242 | 262 |
| 243 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> | 263 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> |
| 244 time_budget_pools_; | 264 time_budget_pools_; |
| 245 | 265 |
| 246 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; | 266 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
| 247 | 267 |
| 248 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); | 268 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); |
| 249 }; | 269 }; |
| 250 | 270 |
| 251 } // namespace scheduler | 271 } // namespace scheduler |
| 252 } // namespace blink | 272 } // namespace blink |
| 253 | 273 |
| 254 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP
ER_H_ | 274 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP
ER_H_ |
| OLD | NEW |