| 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 "platform/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "platform/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 const double kFastCompositingIdleTimeThreshold = .2; | 46 const double kFastCompositingIdleTimeThreshold = .2; |
| 47 constexpr base::TimeDelta kThreadLoadTrackerReportingInterval = | 47 constexpr base::TimeDelta kThreadLoadTrackerReportingInterval = |
| 48 base::TimeDelta::FromMinutes(1); | 48 base::TimeDelta::FromMinutes(1); |
| 49 constexpr base::TimeDelta kThreadLoadTrackerWaitingPeriodBeforeReporting = | 49 constexpr base::TimeDelta kThreadLoadTrackerWaitingPeriodBeforeReporting = |
| 50 base::TimeDelta::FromMinutes(2); | 50 base::TimeDelta::FromMinutes(2); |
| 51 // We do not throttle anything while audio is played and shortly after that. | 51 // We do not throttle anything while audio is played and shortly after that. |
| 52 constexpr base::TimeDelta kThrottlingDelayAfterAudioIsPlayed = | 52 constexpr base::TimeDelta kThrottlingDelayAfterAudioIsPlayed = |
| 53 base::TimeDelta::FromSeconds(5); | 53 base::TimeDelta::FromSeconds(5); |
| 54 constexpr base::TimeDelta kQueueingTimeWindowDuration = | 54 constexpr base::TimeDelta kQueueingTimeWindowDuration = |
| 55 base::TimeDelta::FromSeconds(1); | 55 base::TimeDelta::FromSeconds(1); |
| 56 // Maximal bound on task duration for reporting. | 56 // Threshold for discarding ultra-long tasks. It is assumed that ultra-long |
| 57 constexpr base::TimeDelta kMaxTaskDurationForReporting = | 57 // tasks are reporting glitches (e.g. system falling asleep in the middle |
| 58 base::TimeDelta::FromMinutes(1); | 58 // of the task). |
| 59 constexpr base::TimeDelta kLongTaskDiscardingThreshold = |
| 60 base::TimeDelta::FromSeconds(30); |
| 59 | 61 |
| 60 void ReportForegroundRendererTaskLoad(base::TimeTicks time, double load) { | 62 void ReportForegroundRendererTaskLoad(base::TimeTicks time, double load) { |
| 61 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) | 63 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) |
| 62 return; | 64 return; |
| 63 | 65 |
| 64 int load_percentage = static_cast<int>(load * 100); | 66 int load_percentage = static_cast<int>(load * 100); |
| 65 DCHECK_LE(load_percentage, 100); | 67 DCHECK_LE(load_percentage, 100); |
| 66 | 68 |
| 67 UMA_HISTOGRAM_PERCENTAGE("RendererScheduler.ForegroundRendererMainThreadLoad", | 69 UMA_HISTOGRAM_PERCENTAGE( |
| 68 load_percentage); | 70 "RendererScheduler.ForegroundRendererMainThreadLoad2", load_percentage); |
| 69 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 71 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 70 "RendererScheduler.ForegroundRendererLoad", load_percentage); | 72 "RendererScheduler.ForegroundRendererLoad", load_percentage); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void ReportBackgroundRendererTaskLoad(base::TimeTicks time, double load) { | 75 void ReportBackgroundRendererTaskLoad(base::TimeTicks time, double load) { |
| 74 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) | 76 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) |
| 75 return; | 77 return; |
| 76 | 78 |
| 77 int load_percentage = static_cast<int>(load * 100); | 79 int load_percentage = static_cast<int>(load * 100); |
| 78 DCHECK_LE(load_percentage, 100); | 80 DCHECK_LE(load_percentage, 100); |
| 79 | 81 |
| 80 UMA_HISTOGRAM_PERCENTAGE("RendererScheduler.BackgroundRendererMainThreadLoad", | 82 UMA_HISTOGRAM_PERCENTAGE( |
| 81 load_percentage); | 83 "RendererScheduler.BackgroundRendererMainThreadLoad2", load_percentage); |
| 82 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 84 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 83 "RendererScheduler.BackgroundRendererLoad", load_percentage); | 85 "RendererScheduler.BackgroundRendererLoad", load_percentage); |
| 84 } | 86 } |
| 85 | 87 |
| 86 } // namespace | 88 } // namespace |
| 87 | 89 |
| 88 RendererSchedulerImpl::RendererSchedulerImpl( | 90 RendererSchedulerImpl::RendererSchedulerImpl( |
| 89 scoped_refptr<SchedulerTqmDelegate> main_task_runner) | 91 scoped_refptr<SchedulerTqmDelegate> main_task_runner) |
| 90 : helper_(main_task_runner), | 92 : helper_(main_task_runner), |
| 91 idle_helper_(&helper_, | 93 idle_helper_(&helper_, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 have_reported_blocking_intervention_in_current_policy(false), | 215 have_reported_blocking_intervention_in_current_policy(false), |
| 214 have_reported_blocking_intervention_since_navigation(false), | 216 have_reported_blocking_intervention_since_navigation(false), |
| 215 has_visible_render_widget_with_touch_handler(false), | 217 has_visible_render_widget_with_touch_handler(false), |
| 216 begin_frame_not_expected_soon(false), | 218 begin_frame_not_expected_soon(false), |
| 217 in_idle_period_for_testing(false), | 219 in_idle_period_for_testing(false), |
| 218 use_virtual_time(false), | 220 use_virtual_time(false), |
| 219 is_audio_playing(false), | 221 is_audio_playing(false), |
| 220 rail_mode_observer(nullptr), | 222 rail_mode_observer(nullptr), |
| 221 wake_up_budget_pool(nullptr), | 223 wake_up_budget_pool(nullptr), |
| 222 task_duration_per_queue_type_histogram(base::Histogram::FactoryGet( | 224 task_duration_per_queue_type_histogram(base::Histogram::FactoryGet( |
| 223 "RendererScheduler.TaskDurationPerQueueType", | 225 "RendererScheduler.TaskDurationPerQueueType2", |
| 224 1, | 226 1, |
| 225 static_cast<int>(TaskQueue::QueueType::COUNT), | 227 static_cast<int>(TaskQueue::QueueType::COUNT), |
| 226 static_cast<int>(TaskQueue::QueueType::COUNT) + 1, | 228 static_cast<int>(TaskQueue::QueueType::COUNT) + 1, |
| 227 base::HistogramBase::kUmaTargetedHistogramFlag)) { | 229 base::HistogramBase::kUmaTargetedHistogramFlag)) { |
| 228 foreground_main_thread_load_tracker.Resume(now); | 230 foreground_main_thread_load_tracker.Resume(now); |
| 229 } | 231 } |
| 230 | 232 |
| 231 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} | 233 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} |
| 232 | 234 |
| 233 RendererSchedulerImpl::AnyThread::AnyThread() | 235 RendererSchedulerImpl::AnyThread::AnyThread() |
| (...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 MonotonicTimeInSecondsToTimeTicks(start_time); | 1836 MonotonicTimeInSecondsToTimeTicks(start_time); |
| 1835 base::TimeTicks end_time_ticks = MonotonicTimeInSecondsToTimeTicks(end_time); | 1837 base::TimeTicks end_time_ticks = MonotonicTimeInSecondsToTimeTicks(end_time); |
| 1836 | 1838 |
| 1837 seqlock_queueing_time_estimator_.seqlock.WriteBegin(); | 1839 seqlock_queueing_time_estimator_.seqlock.WriteBegin(); |
| 1838 seqlock_queueing_time_estimator_.data.OnTopLevelTaskCompleted(end_time_ticks); | 1840 seqlock_queueing_time_estimator_.data.OnTopLevelTaskCompleted(end_time_ticks); |
| 1839 seqlock_queueing_time_estimator_.seqlock.WriteEnd(); | 1841 seqlock_queueing_time_estimator_.seqlock.WriteEnd(); |
| 1840 | 1842 |
| 1841 task_queue_throttler()->OnTaskRunTimeReported(task_queue, start_time_ticks, | 1843 task_queue_throttler()->OnTaskRunTimeReported(task_queue, start_time_ticks, |
| 1842 end_time_ticks); | 1844 end_time_ticks); |
| 1843 | 1845 |
| 1846 // TODO(altimin): Per-page metrics should also be considered. |
| 1847 RecordTaskMetrics(task_queue->GetQueueType(), start_time_ticks, |
| 1848 end_time_ticks); |
| 1849 } |
| 1850 |
| 1851 void RendererSchedulerImpl::RecordTaskMetrics(TaskQueue::QueueType queue_type, |
| 1852 base::TimeTicks start_time, |
| 1853 base::TimeTicks end_time) { |
| 1854 base::TimeDelta duration = end_time - start_time; |
| 1855 if (duration > kLongTaskDiscardingThreshold) |
| 1856 return; |
| 1857 |
| 1858 UMA_HISTOGRAM_CUSTOM_COUNTS("RendererScheduler.TaskTime2", |
| 1859 duration.InMicroseconds(), 1, 1000 * 1000, 50); |
| 1860 |
| 1844 // We want to measure thread time here, but for efficiency reasons | 1861 // We want to measure thread time here, but for efficiency reasons |
| 1845 // we stick with wall time. | 1862 // we stick with wall time. |
| 1846 GetMainThreadOnly().foreground_main_thread_load_tracker.RecordTaskTime( | 1863 GetMainThreadOnly().foreground_main_thread_load_tracker.RecordTaskTime( |
| 1847 start_time_ticks, end_time_ticks); | 1864 start_time, end_time); |
| 1848 GetMainThreadOnly().background_main_thread_load_tracker.RecordTaskTime( | 1865 GetMainThreadOnly().background_main_thread_load_tracker.RecordTaskTime( |
| 1849 start_time_ticks, end_time_ticks); | 1866 start_time, end_time); |
| 1850 | |
| 1851 // TODO(altimin): Per-page metrics should also be considered. | |
| 1852 RecordTaskMetrics(task_queue->GetQueueType(), | |
| 1853 end_time_ticks - start_time_ticks); | |
| 1854 } | |
| 1855 | |
| 1856 void RendererSchedulerImpl::RecordTaskMetrics(TaskQueue::QueueType queue_type, | |
| 1857 base::TimeDelta duration) { | |
| 1858 UMA_HISTOGRAM_CUSTOM_COUNTS("RendererScheduler.TaskTime", | |
| 1859 duration.InMicroseconds(), 1, 1000 * 1000, 50); | |
| 1860 | 1867 |
| 1861 // TODO(altimin): See whether this metric is still useful after | 1868 // TODO(altimin): See whether this metric is still useful after |
| 1862 // adding RendererScheduler.TaskDurationPerQueueType. | 1869 // adding RendererScheduler.TaskDurationPerQueueType. |
| 1863 UMA_HISTOGRAM_ENUMERATION("RendererScheduler.NumberOfTasksPerQueueType", | 1870 UMA_HISTOGRAM_ENUMERATION("RendererScheduler.NumberOfTasksPerQueueType2", |
| 1864 static_cast<int>(queue_type), | 1871 static_cast<int>(queue_type), |
| 1865 static_cast<int>(TaskQueue::QueueType::COUNT)); | 1872 static_cast<int>(TaskQueue::QueueType::COUNT)); |
| 1866 | 1873 |
| 1867 RecordTaskDurationPerQueueType(queue_type, duration); | 1874 RecordTaskDurationPerQueueType(queue_type, duration); |
| 1868 } | 1875 } |
| 1869 | 1876 |
| 1870 void RendererSchedulerImpl::RecordTaskDurationPerQueueType( | 1877 void RendererSchedulerImpl::RecordTaskDurationPerQueueType( |
| 1871 TaskQueue::QueueType queue_type, | 1878 TaskQueue::QueueType queue_type, |
| 1872 base::TimeDelta duration) { | 1879 base::TimeDelta duration) { |
| 1873 duration = std::min(duration, kMaxTaskDurationForReporting); | |
| 1874 | |
| 1875 // Report only whole milliseconds to avoid overflow. | 1880 // Report only whole milliseconds to avoid overflow. |
| 1876 base::TimeDelta& unreported_duration = | 1881 base::TimeDelta& unreported_duration = |
| 1877 GetMainThreadOnly() | 1882 GetMainThreadOnly() |
| 1878 .unreported_task_duration[static_cast<int>(queue_type)]; | 1883 .unreported_task_duration[static_cast<int>(queue_type)]; |
| 1879 unreported_duration += duration; | 1884 unreported_duration += duration; |
| 1880 int64_t milliseconds = unreported_duration.InMilliseconds(); | 1885 int64_t milliseconds = unreported_duration.InMilliseconds(); |
| 1881 if (milliseconds > 0) { | 1886 if (milliseconds > 0) { |
| 1882 unreported_duration -= base::TimeDelta::FromMilliseconds(milliseconds); | 1887 unreported_duration -= base::TimeDelta::FromMilliseconds(milliseconds); |
| 1883 GetMainThreadOnly().task_duration_per_queue_type_histogram->AddCount( | 1888 GetMainThreadOnly().task_duration_per_queue_type_histogram->AddCount( |
| 1884 static_cast<int>(queue_type), static_cast<int>(milliseconds)); | 1889 static_cast<int>(queue_type), static_cast<int>(milliseconds)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2054 case TimeDomainType::VIRTUAL: | 2059 case TimeDomainType::VIRTUAL: |
| 2055 return "virtual"; | 2060 return "virtual"; |
| 2056 default: | 2061 default: |
| 2057 NOTREACHED(); | 2062 NOTREACHED(); |
| 2058 return nullptr; | 2063 return nullptr; |
| 2059 } | 2064 } |
| 2060 } | 2065 } |
| 2061 | 2066 |
| 2062 } // namespace scheduler | 2067 } // namespace scheduler |
| 2063 } // namespace blink | 2068 } // namespace blink |
| OLD | NEW |