| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewLoadingTaskRunner( | 192 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewLoadingTaskRunner( |
| 193 const char* name) { | 193 const char* name) { |
| 194 helper_.CheckOnValidThread(); | 194 helper_.CheckOnValidThread(); |
| 195 scoped_refptr<TaskQueue> loading_task_queue(helper_.NewTaskQueue( | 195 scoped_refptr<TaskQueue> loading_task_queue(helper_.NewTaskQueue( |
| 196 TaskQueue::Spec(name).SetShouldMonitorQuiescence(true))); | 196 TaskQueue::Spec(name).SetShouldMonitorQuiescence(true))); |
| 197 loading_task_runners_.insert(loading_task_queue); | 197 loading_task_runners_.insert(loading_task_queue); |
| 198 loading_task_queue->SetQueueEnabled( | 198 loading_task_queue->SetQueueEnabled( |
| 199 MainThreadOnly().current_policy.loading_queue_policy.is_enabled); | 199 MainThreadOnly().current_policy.loading_queue_policy.is_enabled); |
| 200 loading_task_queue->SetQueuePriority( | 200 loading_task_queue->SetQueuePriority( |
| 201 MainThreadOnly().current_policy.loading_queue_policy.priority); | 201 MainThreadOnly().current_policy.loading_queue_policy.priority); |
| 202 if (MainThreadOnly().current_policy.loading_queue_policy.time_domain_type == |
| 203 TimeDomainType::THROTTLED) { |
| 204 throttling_helper_->IncreaseThrottleRefCount(loading_task_queue.get()); |
| 205 } |
| 202 loading_task_queue->AddTaskObserver( | 206 loading_task_queue->AddTaskObserver( |
| 203 &MainThreadOnly().loading_task_cost_estimator); | 207 &MainThreadOnly().loading_task_cost_estimator); |
| 204 return loading_task_queue; | 208 return loading_task_queue; |
| 205 } | 209 } |
| 206 | 210 |
| 207 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewTimerTaskRunner( | 211 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewTimerTaskRunner( |
| 208 const char* name) { | 212 const char* name) { |
| 209 helper_.CheckOnValidThread(); | 213 helper_.CheckOnValidThread(); |
| 210 scoped_refptr<TaskQueue> timer_task_queue( | 214 scoped_refptr<TaskQueue> timer_task_queue( |
| 211 helper_.NewTaskQueue(TaskQueue::Spec(name) | 215 helper_.NewTaskQueue(TaskQueue::Spec(name) |
| 212 .SetShouldMonitorQuiescence(true) | 216 .SetShouldMonitorQuiescence(true) |
| 213 .SetShouldReportWhenExecutionBlocked(true))); | 217 .SetShouldReportWhenExecutionBlocked(true))); |
| 214 timer_task_runners_.insert(timer_task_queue); | 218 timer_task_runners_.insert(timer_task_queue); |
| 215 timer_task_queue->SetQueueEnabled( | 219 timer_task_queue->SetQueueEnabled( |
| 216 MainThreadOnly().current_policy.timer_queue_policy.is_enabled); | 220 MainThreadOnly().current_policy.timer_queue_policy.is_enabled); |
| 217 timer_task_queue->SetQueuePriority( | 221 timer_task_queue->SetQueuePriority( |
| 218 MainThreadOnly().current_policy.timer_queue_policy.priority); | 222 MainThreadOnly().current_policy.timer_queue_policy.priority); |
| 223 if (MainThreadOnly().current_policy.timer_queue_policy.time_domain_type == |
| 224 TimeDomainType::THROTTLED) { |
| 225 throttling_helper_->IncreaseThrottleRefCount(timer_task_queue.get()); |
| 226 } |
| 219 timer_task_queue->AddTaskObserver( | 227 timer_task_queue->AddTaskObserver( |
| 220 &MainThreadOnly().timer_task_cost_estimator); | 228 &MainThreadOnly().timer_task_cost_estimator); |
| 221 return timer_task_queue; | 229 return timer_task_queue; |
| 222 } | 230 } |
| 223 | 231 |
| 224 std::unique_ptr<RenderWidgetSchedulingState> | 232 std::unique_ptr<RenderWidgetSchedulingState> |
| 225 RendererSchedulerImpl::NewRenderWidgetSchedulingState() { | 233 RendererSchedulerImpl::NewRenderWidgetSchedulingState() { |
| 226 return render_widget_scheduler_signals_.NewRenderWidgetSchedulingState(); | 234 return render_widget_scheduler_signals_.NewRenderWidgetSchedulingState(); |
| 227 } | 235 } |
| 228 | 236 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 TimeDomainType::THROTTLED; | 831 TimeDomainType::THROTTLED; |
| 824 } | 832 } |
| 825 break; | 833 break; |
| 826 } | 834 } |
| 827 | 835 |
| 828 MainThreadOnly().expensive_task_policy = expensive_task_policy; | 836 MainThreadOnly().expensive_task_policy = expensive_task_policy; |
| 829 | 837 |
| 830 if (MainThreadOnly().timer_queue_suspend_count != 0 || | 838 if (MainThreadOnly().timer_queue_suspend_count != 0 || |
| 831 MainThreadOnly().timer_queue_suspended_when_backgrounded) { | 839 MainThreadOnly().timer_queue_suspended_when_backgrounded) { |
| 832 new_policy.timer_queue_policy.is_enabled = false; | 840 new_policy.timer_queue_policy.is_enabled = false; |
| 841 new_policy.timer_queue_policy.time_domain_type = TimeDomainType::REAL; |
| 833 } | 842 } |
| 834 | 843 |
| 835 // Tracing is done before the early out check, because it's quite possible we | 844 // Tracing is done before the early out check, because it's quite possible we |
| 836 // will otherwise miss this information in traces. | 845 // will otherwise miss this information in traces. |
| 837 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 846 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 838 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 847 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
| 839 this, AsValueLocked(now)); | 848 this, AsValueLocked(now)); |
| 840 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case", | 849 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case", |
| 841 use_case); | 850 use_case); |
| 842 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 851 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 new_policy.default_queue_policy); | 892 new_policy.default_queue_policy); |
| 884 | 893 |
| 885 DCHECK(compositor_task_runner_->IsQueueEnabled()); | 894 DCHECK(compositor_task_runner_->IsQueueEnabled()); |
| 886 MainThreadOnly().current_policy = new_policy; | 895 MainThreadOnly().current_policy = new_policy; |
| 887 } | 896 } |
| 888 | 897 |
| 889 void RendererSchedulerImpl::ApplyTaskQueuePolicy( | 898 void RendererSchedulerImpl::ApplyTaskQueuePolicy( |
| 890 TaskQueue* task_queue, | 899 TaskQueue* task_queue, |
| 891 const TaskQueuePolicy& old_task_queue_policy, | 900 const TaskQueuePolicy& old_task_queue_policy, |
| 892 const TaskQueuePolicy& new_task_queue_policy) const { | 901 const TaskQueuePolicy& new_task_queue_policy) const { |
| 893 // The ThrottlingHelper also calls SetQueueEnabled, so we can avoid calling | 902 if (old_task_queue_policy.is_enabled != new_task_queue_policy.is_enabled) { |
| 894 // this here. | 903 throttling_helper_->SetQueueEnabled(task_queue, |
| 895 if (new_task_queue_policy.time_domain_type != TimeDomainType::THROTTLED) | 904 new_task_queue_policy.is_enabled); |
| 896 task_queue->SetQueueEnabled(new_task_queue_policy.is_enabled); | 905 } |
| 906 |
| 897 if (old_task_queue_policy.priority != new_task_queue_policy.priority) | 907 if (old_task_queue_policy.priority != new_task_queue_policy.priority) |
| 898 task_queue->SetQueuePriority(new_task_queue_policy.priority); | 908 task_queue->SetQueuePriority(new_task_queue_policy.priority); |
| 899 | 909 |
| 900 if (old_task_queue_policy.time_domain_type != | 910 if (old_task_queue_policy.time_domain_type != |
| 901 new_task_queue_policy.time_domain_type) { | 911 new_task_queue_policy.time_domain_type) { |
| 902 if (new_task_queue_policy.time_domain_type == TimeDomainType::THROTTLED) { | 912 if (new_task_queue_policy.time_domain_type == TimeDomainType::THROTTLED) { |
| 903 throttling_helper_->IncreaseThrottleRefCount(task_queue); | 913 throttling_helper_->IncreaseThrottleRefCount(task_queue); |
| 904 } else if (old_task_queue_policy.time_domain_type == | 914 } else if (old_task_queue_policy.time_domain_type == |
| 905 TimeDomainType::THROTTLED) { | 915 TimeDomainType::THROTTLED) { |
| 906 throttling_helper_->DecreaseThrottleRefCount(task_queue); | 916 throttling_helper_->DecreaseThrottleRefCount(task_queue); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 IdleTimeEstimator* RendererSchedulerImpl::GetIdleTimeEstimatorForTesting() { | 1026 IdleTimeEstimator* RendererSchedulerImpl::GetIdleTimeEstimatorForTesting() { |
| 1017 return &MainThreadOnly().idle_time_estimator; | 1027 return &MainThreadOnly().idle_time_estimator; |
| 1018 } | 1028 } |
| 1019 | 1029 |
| 1020 void RendererSchedulerImpl::SuspendTimerQueue() { | 1030 void RendererSchedulerImpl::SuspendTimerQueue() { |
| 1021 MainThreadOnly().timer_queue_suspend_count++; | 1031 MainThreadOnly().timer_queue_suspend_count++; |
| 1022 ForceUpdatePolicy(); | 1032 ForceUpdatePolicy(); |
| 1023 #ifndef NDEBUG | 1033 #ifndef NDEBUG |
| 1024 DCHECK(!default_timer_task_runner_->IsQueueEnabled()); | 1034 DCHECK(!default_timer_task_runner_->IsQueueEnabled()); |
| 1025 for (const auto& runner : timer_task_runners_) { | 1035 for (const auto& runner : timer_task_runners_) { |
| 1026 DCHECK(!runner->IsQueueEnabled()); | 1036 DCHECK(!runner->IsQueueEnabled()); |
| 1027 } | 1037 } |
| 1028 #endif | 1038 #endif |
| 1029 } | 1039 } |
| 1030 | 1040 |
| 1031 void RendererSchedulerImpl::ResumeTimerQueue() { | 1041 void RendererSchedulerImpl::ResumeTimerQueue() { |
| 1032 MainThreadOnly().timer_queue_suspend_count--; | 1042 MainThreadOnly().timer_queue_suspend_count--; |
| 1033 DCHECK_GE(MainThreadOnly().timer_queue_suspend_count, 0); | 1043 DCHECK_GE(MainThreadOnly().timer_queue_suspend_count, 0); |
| 1034 ForceUpdatePolicy(); | 1044 ForceUpdatePolicy(); |
| 1035 } | 1045 } |
| 1036 | 1046 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 BroadcastConsoleWarning( | 1334 BroadcastConsoleWarning( |
| 1325 "Blink deferred a task in order to make scrolling smoother. " | 1335 "Blink deferred a task in order to make scrolling smoother. " |
| 1326 "Your timer and network tasks should take less than 50ms to run " | 1336 "Your timer and network tasks should take less than 50ms to run " |
| 1327 "to avoid this. Please see " | 1337 "to avoid this. Please see " |
| 1328 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" | 1338 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" |
| 1329 " and https://crbug.com/574343#c40 for more information."); | 1339 " and https://crbug.com/574343#c40 for more information."); |
| 1330 } | 1340 } |
| 1331 } | 1341 } |
| 1332 | 1342 |
| 1333 } // namespace scheduler | 1343 } // namespace scheduler |
| OLD | NEW |