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" |
| 11 #include "base/metrics/histogram.h" |
11 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
14 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
15 #include "cc/output/begin_frame_args.h" | 16 #include "cc/output/begin_frame_args.h" |
16 #include "platform/RuntimeEnabledFeatures.h" | 17 #include "platform/RuntimeEnabledFeatures.h" |
17 #include "platform/scheduler/base/real_time_domain.h" | 18 #include "platform/scheduler/base/real_time_domain.h" |
18 #include "platform/scheduler/base/task_queue_impl.h" | 19 #include "platform/scheduler/base/task_queue_impl.h" |
19 #include "platform/scheduler/base/task_queue_selector.h" | 20 #include "platform/scheduler/base/task_queue_selector.h" |
20 #include "platform/scheduler/base/time_converter.h" | 21 #include "platform/scheduler/base/time_converter.h" |
(...skipping 24 matching lines...) Expand all Loading... |
45 const double kFastCompositingIdleTimeThreshold = .2; | 46 const double kFastCompositingIdleTimeThreshold = .2; |
46 constexpr base::TimeDelta kThreadLoadTrackerReportingInterval = | 47 constexpr base::TimeDelta kThreadLoadTrackerReportingInterval = |
47 base::TimeDelta::FromMinutes(1); | 48 base::TimeDelta::FromMinutes(1); |
48 constexpr base::TimeDelta kThreadLoadTrackerWaitingPeriodBeforeReporting = | 49 constexpr base::TimeDelta kThreadLoadTrackerWaitingPeriodBeforeReporting = |
49 base::TimeDelta::FromMinutes(2); | 50 base::TimeDelta::FromMinutes(2); |
50 // 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. |
51 constexpr base::TimeDelta kThrottlingDelayAfterAudioIsPlayed = | 52 constexpr base::TimeDelta kThrottlingDelayAfterAudioIsPlayed = |
52 base::TimeDelta::FromSeconds(5); | 53 base::TimeDelta::FromSeconds(5); |
53 constexpr base::TimeDelta kQueueingTimeWindowDuration = | 54 constexpr base::TimeDelta kQueueingTimeWindowDuration = |
54 base::TimeDelta::FromSeconds(1); | 55 base::TimeDelta::FromSeconds(1); |
| 56 // Maximal bound on task duration for reporting. |
| 57 constexpr base::TimeDelta kMaxTaskDurationForReporting = |
| 58 base::TimeDelta::FromMinutes(1); |
55 | 59 |
56 void ReportForegroundRendererTaskLoad(base::TimeTicks time, double load) { | 60 void ReportForegroundRendererTaskLoad(base::TimeTicks time, double load) { |
57 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) | 61 if (!blink::RuntimeEnabledFeatures::timerThrottlingForBackgroundTabsEnabled()) |
58 return; | 62 return; |
59 | 63 |
60 int load_percentage = static_cast<int>(load * 100); | 64 int load_percentage = static_cast<int>(load * 100); |
61 DCHECK_LE(load_percentage, 100); | 65 DCHECK_LE(load_percentage, 100); |
62 | 66 |
63 UMA_HISTOGRAM_PERCENTAGE("RendererScheduler.ForegroundRendererMainThreadLoad", | 67 UMA_HISTOGRAM_PERCENTAGE("RendererScheduler.ForegroundRendererMainThreadLoad", |
64 load_percentage); | 68 load_percentage); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 touchstart_expected_soon(false), | 211 touchstart_expected_soon(false), |
208 have_seen_a_begin_main_frame(false), | 212 have_seen_a_begin_main_frame(false), |
209 have_reported_blocking_intervention_in_current_policy(false), | 213 have_reported_blocking_intervention_in_current_policy(false), |
210 have_reported_blocking_intervention_since_navigation(false), | 214 have_reported_blocking_intervention_since_navigation(false), |
211 has_visible_render_widget_with_touch_handler(false), | 215 has_visible_render_widget_with_touch_handler(false), |
212 begin_frame_not_expected_soon(false), | 216 begin_frame_not_expected_soon(false), |
213 in_idle_period_for_testing(false), | 217 in_idle_period_for_testing(false), |
214 use_virtual_time(false), | 218 use_virtual_time(false), |
215 is_audio_playing(false), | 219 is_audio_playing(false), |
216 rail_mode_observer(nullptr), | 220 rail_mode_observer(nullptr), |
217 wake_up_budget_pool(nullptr) { | 221 wake_up_budget_pool(nullptr), |
| 222 task_duration_per_queue_type_histogram(base::Histogram::FactoryGet( |
| 223 "RendererScheduler.TaskDurationPerQueueType", |
| 224 1, |
| 225 static_cast<int>(TaskQueue::QueueType::COUNT), |
| 226 static_cast<int>(TaskQueue::QueueType::COUNT) + 1, |
| 227 base::HistogramBase::kUmaTargetedHistogramFlag)) { |
218 foreground_main_thread_load_tracker.Resume(now); | 228 foreground_main_thread_load_tracker.Resume(now); |
219 } | 229 } |
220 | 230 |
221 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} | 231 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} |
222 | 232 |
223 RendererSchedulerImpl::AnyThread::AnyThread() | 233 RendererSchedulerImpl::AnyThread::AnyThread() |
224 : awaiting_touch_start_response(false), | 234 : awaiting_touch_start_response(false), |
225 in_idle_period(false), | 235 in_idle_period(false), |
226 begin_main_frame_on_critical_path(false), | 236 begin_main_frame_on_critical_path(false), |
227 last_gesture_was_compositor_driven(false), | 237 last_gesture_was_compositor_driven(false), |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 | 1833 |
1824 task_queue_throttler()->OnTaskRunTimeReported(task_queue, start_time_ticks, | 1834 task_queue_throttler()->OnTaskRunTimeReported(task_queue, start_time_ticks, |
1825 end_time_ticks); | 1835 end_time_ticks); |
1826 | 1836 |
1827 // We want to measure thread time here, but for efficiency reasons | 1837 // We want to measure thread time here, but for efficiency reasons |
1828 // we stick with wall time. | 1838 // we stick with wall time. |
1829 GetMainThreadOnly().foreground_main_thread_load_tracker.RecordTaskTime( | 1839 GetMainThreadOnly().foreground_main_thread_load_tracker.RecordTaskTime( |
1830 start_time_ticks, end_time_ticks); | 1840 start_time_ticks, end_time_ticks); |
1831 GetMainThreadOnly().background_main_thread_load_tracker.RecordTaskTime( | 1841 GetMainThreadOnly().background_main_thread_load_tracker.RecordTaskTime( |
1832 start_time_ticks, end_time_ticks); | 1842 start_time_ticks, end_time_ticks); |
| 1843 |
1833 // TODO(altimin): Per-page metrics should also be considered. | 1844 // TODO(altimin): Per-page metrics should also be considered. |
1834 UMA_HISTOGRAM_CUSTOM_COUNTS( | 1845 RecordTaskMetrics(task_queue->GetQueueType(), |
1835 "RendererScheduler.TaskTime", | 1846 end_time_ticks - start_time_ticks); |
1836 (end_time_ticks - start_time_ticks).InMicroseconds(), 1, 1000000, 50); | 1847 } |
| 1848 |
| 1849 void RendererSchedulerImpl::RecordTaskMetrics(TaskQueue::QueueType queue_type, |
| 1850 base::TimeDelta duration) { |
| 1851 UMA_HISTOGRAM_CUSTOM_COUNTS("RendererScheduler.TaskTime", |
| 1852 duration.InMicroseconds(), 1, 1000 * 1000, 50); |
| 1853 |
| 1854 // TODO(altimin): See whether this metric is still useful after |
| 1855 // adding RendererScheduler.TaskDurationPerQueueType. |
1837 UMA_HISTOGRAM_ENUMERATION("RendererScheduler.NumberOfTasksPerQueueType", | 1856 UMA_HISTOGRAM_ENUMERATION("RendererScheduler.NumberOfTasksPerQueueType", |
1838 static_cast<int>(task_queue->GetQueueType()), | 1857 static_cast<int>(queue_type), |
1839 static_cast<int>(TaskQueue::QueueType::COUNT)); | 1858 static_cast<int>(TaskQueue::QueueType::COUNT)); |
| 1859 |
| 1860 RecordTaskDurationPerQueueType(queue_type, duration); |
| 1861 } |
| 1862 |
| 1863 void RendererSchedulerImpl::RecordTaskDurationPerQueueType( |
| 1864 TaskQueue::QueueType queue_type, |
| 1865 base::TimeDelta duration) { |
| 1866 duration = std::min(duration, kMaxTaskDurationForReporting); |
| 1867 |
| 1868 // Report only whole milliseconds to avoid overflow. |
| 1869 base::TimeDelta& unreported_duration = |
| 1870 GetMainThreadOnly() |
| 1871 .unreported_task_duration[static_cast<int>(queue_type)]; |
| 1872 unreported_duration += duration; |
| 1873 int64_t milliseconds = unreported_duration.InMilliseconds(); |
| 1874 if (milliseconds > 0) { |
| 1875 unreported_duration -= base::TimeDelta::FromMilliseconds(milliseconds); |
| 1876 GetMainThreadOnly().task_duration_per_queue_type_histogram->AddCount( |
| 1877 static_cast<int>(queue_type), static_cast<int>(milliseconds)); |
| 1878 } |
1840 } | 1879 } |
1841 | 1880 |
1842 void RendererSchedulerImpl::OnBeginNestedRunLoop() { | 1881 void RendererSchedulerImpl::OnBeginNestedRunLoop() { |
1843 seqlock_queueing_time_estimator_.seqlock.WriteBegin(); | 1882 seqlock_queueing_time_estimator_.seqlock.WriteBegin(); |
1844 seqlock_queueing_time_estimator_.data.OnBeginNestedRunLoop(); | 1883 seqlock_queueing_time_estimator_.data.OnBeginNestedRunLoop(); |
1845 seqlock_queueing_time_estimator_.seqlock.WriteEnd(); | 1884 seqlock_queueing_time_estimator_.seqlock.WriteEnd(); |
1846 } | 1885 } |
1847 | 1886 |
1848 void RendererSchedulerImpl::AddTaskTimeObserver( | 1887 void RendererSchedulerImpl::AddTaskTimeObserver( |
1849 TaskTimeObserver* task_time_observer) { | 1888 TaskTimeObserver* task_time_observer) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 case TimeDomainType::VIRTUAL: | 2047 case TimeDomainType::VIRTUAL: |
2009 return "virtual"; | 2048 return "virtual"; |
2010 default: | 2049 default: |
2011 NOTREACHED(); | 2050 NOTREACHED(); |
2012 return nullptr; | 2051 return nullptr; |
2013 } | 2052 } |
2014 } | 2053 } |
2015 | 2054 |
2016 } // namespace scheduler | 2055 } // namespace scheduler |
2017 } // namespace blink | 2056 } // namespace blink |
OLD | NEW |