| 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 18 matching lines...) Expand all Loading... |
| 29 // the cost of loading tasks. | 29 // the cost of loading tasks. |
| 30 const int kLoadingTaskEstimationSampleCount = 1000; | 30 const int kLoadingTaskEstimationSampleCount = 1000; |
| 31 const double kLoadingTaskEstimationPercentile = 99; | 31 const double kLoadingTaskEstimationPercentile = 99; |
| 32 const int kTimerTaskEstimationSampleCount = 1000; | 32 const int kTimerTaskEstimationSampleCount = 1000; |
| 33 const double kTimerTaskEstimationPercentile = 99; | 33 const double kTimerTaskEstimationPercentile = 99; |
| 34 const int kShortIdlePeriodDurationSampleCount = 10; | 34 const int kShortIdlePeriodDurationSampleCount = 10; |
| 35 const double kShortIdlePeriodDurationPercentile = 50; | 35 const double kShortIdlePeriodDurationPercentile = 50; |
| 36 // Amount of idle time left in a frame (as a ratio of the vsync interval) above | 36 // Amount of idle time left in a frame (as a ratio of the vsync interval) above |
| 37 // which main thread compositing can be considered fast. | 37 // which main thread compositing can be considered fast. |
| 38 const double kFastCompositingIdleTimeThreshold = .2; | 38 const double kFastCompositingIdleTimeThreshold = .2; |
| 39 |
| 40 base::TimeTicks MonotonicTimeInSecondsToTimeTicks( |
| 41 double monotonicTimeInSeconds) { |
| 42 return base::TimeTicks::FromInternalValue(monotonicTimeInSeconds * |
| 43 base::Time::kMicrosecondsPerSecond); |
| 44 } |
| 45 |
| 39 } // namespace | 46 } // namespace |
| 40 | 47 |
| 41 RendererSchedulerImpl::RendererSchedulerImpl( | 48 RendererSchedulerImpl::RendererSchedulerImpl( |
| 42 scoped_refptr<SchedulerTqmDelegate> main_task_runner) | 49 scoped_refptr<SchedulerTqmDelegate> main_task_runner) |
| 43 : helper_(main_task_runner, | 50 : helper_(main_task_runner, |
| 44 "renderer.scheduler", | 51 "renderer.scheduler", |
| 45 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 52 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 46 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")), | 53 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")), |
| 47 idle_helper_(&helper_, | 54 idle_helper_(&helper_, |
| 48 this, | 55 this, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 weak_factory_.GetWeakPtr())); | 81 weak_factory_.GetWeakPtr())); |
| 75 | 82 |
| 76 default_loading_task_runner_ = NewLoadingTaskRunner("default_loading_tq"); | 83 default_loading_task_runner_ = NewLoadingTaskRunner("default_loading_tq"); |
| 77 default_timer_task_runner_ = NewTimerTaskRunner("default_timer_tq"); | 84 default_timer_task_runner_ = NewTimerTaskRunner("default_timer_tq"); |
| 78 | 85 |
| 79 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 86 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
| 80 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 87 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
| 81 this); | 88 this); |
| 82 | 89 |
| 83 helper_.SetObserver(this); | 90 helper_.SetObserver(this); |
| 84 helper_.SetTaskTimeTracker(this); | 91 helper_.AddTaskTimeTracker(this); |
| 85 } | 92 } |
| 86 | 93 |
| 87 RendererSchedulerImpl::~RendererSchedulerImpl() { | 94 RendererSchedulerImpl::~RendererSchedulerImpl() { |
| 88 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 95 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
| 89 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 96 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
| 90 this); | 97 this); |
| 91 | 98 |
| 92 for (const scoped_refptr<TaskQueue>& loading_queue : loading_task_runners_) { | 99 for (const scoped_refptr<TaskQueue>& loading_queue : loading_task_runners_) { |
| 93 loading_queue->RemoveTaskObserver( | 100 loading_queue->RemoveTaskObserver( |
| 94 &MainThreadOnly().loading_task_cost_estimator); | 101 &MainThreadOnly().loading_task_cost_estimator); |
| 95 } | 102 } |
| 96 for (const scoped_refptr<TaskQueue>& timer_queue : timer_task_runners_) { | 103 for (const scoped_refptr<TaskQueue>& timer_queue : timer_task_runners_) { |
| 97 timer_queue->RemoveTaskObserver( | 104 timer_queue->RemoveTaskObserver( |
| 98 &MainThreadOnly().timer_task_cost_estimator); | 105 &MainThreadOnly().timer_task_cost_estimator); |
| 99 } | 106 } |
| 100 | 107 |
| 101 if (virtual_time_domain_) | 108 if (virtual_time_domain_) |
| 102 UnregisterTimeDomain(virtual_time_domain_.get()); | 109 UnregisterTimeDomain(virtual_time_domain_.get()); |
| 103 | 110 |
| 111 helper_.RemoveTaskTimeTracker(this); |
| 112 |
| 104 // Ensure the renderer scheduler was shut down explicitly, because otherwise | 113 // Ensure the renderer scheduler was shut down explicitly, because otherwise |
| 105 // we could end up having stale pointers to the Blink heap which has been | 114 // we could end up having stale pointers to the Blink heap which has been |
| 106 // terminated by this point. | 115 // terminated by this point. |
| 107 DCHECK(MainThreadOnly().was_shutdown); | 116 DCHECK(MainThreadOnly().was_shutdown); |
| 108 } | 117 } |
| 109 | 118 |
| 110 RendererSchedulerImpl::MainThreadOnly::MainThreadOnly( | 119 RendererSchedulerImpl::MainThreadOnly::MainThreadOnly( |
| 111 RendererSchedulerImpl* renderer_scheduler_impl, | 120 RendererSchedulerImpl* renderer_scheduler_impl, |
| 112 const scoped_refptr<TaskQueue>& compositor_task_runner, | 121 const scoped_refptr<TaskQueue>& compositor_task_runner, |
| 113 base::TickClock* time_source) | 122 base::TickClock* time_source) |
| (...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 true; | 1417 true; |
| 1409 BroadcastIntervention( | 1418 BroadcastIntervention( |
| 1410 "Blink deferred a task in order to make scrolling smoother. " | 1419 "Blink deferred a task in order to make scrolling smoother. " |
| 1411 "Your timer and network tasks should take less than 50ms to run " | 1420 "Your timer and network tasks should take less than 50ms to run " |
| 1412 "to avoid this. Please see " | 1421 "to avoid this. Please see " |
| 1413 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" | 1422 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" |
| 1414 " and https://crbug.com/574343#c40 for more information."); | 1423 " and https://crbug.com/574343#c40 for more information."); |
| 1415 } | 1424 } |
| 1416 } | 1425 } |
| 1417 | 1426 |
| 1418 void RendererSchedulerImpl::ReportTaskTime(base::TimeTicks start_time, | 1427 void RendererSchedulerImpl::ReportTaskTime(double start_time, double end_time) { |
| 1419 base::TimeTicks end_time) { | 1428 base::TimeTicks start_time_ticks = |
| 1420 MainThreadOnly().queueing_time_estimator.OnToplevelTaskCompleted(start_time, | 1429 MonotonicTimeInSecondsToTimeTicks(start_time); |
| 1421 end_time); | 1430 base::TimeTicks end_time_ticks = MonotonicTimeInSecondsToTimeTicks(end_time); |
| 1422 MainThreadOnly().long_task_tracker.RecordLongTask( | 1431 |
| 1423 start_time, end_time - start_time); | 1432 MainThreadOnly().queueing_time_estimator.OnToplevelTaskCompleted( |
| 1424 UMA_HISTOGRAM_CUSTOM_COUNTS("RendererScheduler.TaskTime", | 1433 start_time_ticks, end_time_ticks); |
| 1425 (end_time - start_time).InMicroseconds(), 1, | 1434 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1426 1000000, 50); | 1435 "RendererScheduler.TaskTime", |
| 1436 (end_time_ticks - start_time_ticks).InMicroseconds(), 1, 1000000, 50); |
| 1427 } | 1437 } |
| 1428 | 1438 |
| 1429 LongTaskTracker::LongTaskTiming RendererSchedulerImpl::GetLongTaskTiming() { | 1439 void RendererSchedulerImpl::AddTaskTimeTracker( |
| 1430 return MainThreadOnly().long_task_tracker.GetLongTaskTiming(); | 1440 TaskTimeTracker* task_time_tracker) { |
| 1441 helper_.AddTaskTimeTracker(task_time_tracker); |
| 1442 } |
| 1443 |
| 1444 void RendererSchedulerImpl::RemoveTaskTimeTracker( |
| 1445 TaskTimeTracker* task_time_tracker) { |
| 1446 helper_.RemoveTaskTimeTracker(task_time_tracker); |
| 1431 } | 1447 } |
| 1432 | 1448 |
| 1433 void RendererSchedulerImpl::OnQueueingTimeForWindowEstimated( | 1449 void RendererSchedulerImpl::OnQueueingTimeForWindowEstimated( |
| 1434 base::TimeDelta queueing_time) { | 1450 base::TimeDelta queueing_time) { |
| 1435 UMA_HISTOGRAM_TIMES("RendererScheduler.ExpectedTaskQueueingDuration", | 1451 UMA_HISTOGRAM_TIMES("RendererScheduler.ExpectedTaskQueueingDuration", |
| 1436 queueing_time); | 1452 queueing_time); |
| 1437 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 1453 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 1438 "estimated_queueing_time_for_window", | 1454 "estimated_queueing_time_for_window", |
| 1439 queueing_time.InMillisecondsF()); | 1455 queueing_time.InMillisecondsF()); |
| 1440 } | 1456 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 case v8::PERFORMANCE_LOAD: | 1512 case v8::PERFORMANCE_LOAD: |
| 1497 return "load"; | 1513 return "load"; |
| 1498 default: | 1514 default: |
| 1499 NOTREACHED(); | 1515 NOTREACHED(); |
| 1500 return nullptr; | 1516 return nullptr; |
| 1501 } | 1517 } |
| 1502 } | 1518 } |
| 1503 | 1519 |
| 1504 } // namespace scheduler | 1520 } // namespace scheduler |
| 1505 } // namespace blink | 1521 } // namespace blink |
| OLD | NEW |