Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 ChildThreadImpl::current()->SetThreadPriority( | 889 ChildThreadImpl::current()->SetThreadPriority( |
| 890 categorized_worker_pool_->background_worker_thread_id(), | 890 categorized_worker_pool_->background_worker_thread_id(), |
| 891 base::ThreadPriority::BACKGROUND); | 891 base::ThreadPriority::BACKGROUND); |
| 892 #endif | 892 #endif |
| 893 | 893 |
| 894 record_purge_suspend_metric_closure_.Reset(base::Bind( | 894 record_purge_suspend_metric_closure_.Reset(base::Bind( |
| 895 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); | 895 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); |
| 896 record_purge_suspend_growth_metric_closure_.Reset( | 896 record_purge_suspend_growth_metric_closure_.Reset( |
| 897 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 897 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 898 base::Unretained(this))); | 898 base::Unretained(this))); |
| 899 record_first_active_paint_ = true; | |
| 900 foregrounded_time_ = base::TimeTicks::Now(); | |
| 899 | 901 |
| 900 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 902 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 901 | 903 |
| 902 // If this renderer doesn't run inside the browser process, enable | 904 // If this renderer doesn't run inside the browser process, enable |
| 903 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 905 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 904 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 906 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 905 // redirection experiment concludes https://crbug.com/622400. | 907 // redirection experiment concludes https://crbug.com/622400. |
| 906 if (!command_line.HasSwitch(switches::kSingleProcess)) | 908 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 907 base::SequencedWorkerPool::EnableForProcess(); | 909 base::SequencedWorkerPool::EnableForProcess(); |
| 908 } | 910 } |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1646 base::MemoryState::NORMAL); | 1648 base::MemoryState::NORMAL); |
| 1647 | 1649 |
| 1648 record_purge_suspend_metric_closure_.Cancel(); | 1650 record_purge_suspend_metric_closure_.Cancel(); |
| 1649 record_purge_suspend_metric_closure_.Reset( | 1651 record_purge_suspend_metric_closure_.Reset( |
| 1650 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1652 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1651 base::Unretained(this))); | 1653 base::Unretained(this))); |
| 1652 record_purge_suspend_growth_metric_closure_.Cancel(); | 1654 record_purge_suspend_growth_metric_closure_.Cancel(); |
| 1653 record_purge_suspend_growth_metric_closure_.Reset( | 1655 record_purge_suspend_growth_metric_closure_.Reset( |
| 1654 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 1656 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1655 base::Unretained(this))); | 1657 base::Unretained(this))); |
| 1658 foregrounded_time_ = base::TimeTicks::Now(); | |
| 1656 } | 1659 } |
| 1657 } | 1660 } |
| 1658 | 1661 |
| 1659 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1662 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1660 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1663 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1661 if (!RendererIsHidden()) | 1664 if (!RendererIsHidden()) |
| 1662 return; | 1665 return; |
| 1663 | 1666 |
| 1664 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1667 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 1665 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1668 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
| 1666 return; | 1669 return; |
| 1667 | 1670 |
| 1668 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1671 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1669 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1672 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1670 // and follow MemoryCoordinator's request. | 1673 // and follow MemoryCoordinator's request. |
| 1671 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1674 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1672 base::MemoryState::SUSPENDED); | 1675 base::MemoryState::SUSPENDED); |
| 1673 } | 1676 } |
| 1674 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1677 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1675 // we need to wait until the task is finished. So wait 15 seconds and | 1678 // we need to wait until the task is finished. So wait 15 seconds and |
| 1676 // update purge+suspend UMA histogram. | 1679 // update purge+suspend UMA histogram. |
| 1677 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1680 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1678 // UMA when MemoryCoordinator is available. | 1681 // UMA when MemoryCoordinator is available. |
| 1679 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1682 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1680 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1683 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1681 base::TimeDelta::FromSeconds(15)); | 1684 base::TimeDelta::FromSeconds(15)); |
| 1685 record_first_active_paint_ = false; | |
| 1682 } | 1686 } |
| 1683 | 1687 |
| 1684 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1688 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| 1685 // when it is possible to run memory-infra without tracing. | 1689 // when it is possible to run memory-infra without tracing. |
| 1686 #if defined(OS_WIN) | 1690 #if defined(OS_WIN) |
| 1687 namespace { | 1691 namespace { |
| 1688 | 1692 |
| 1689 static size_t GetMallocUsage() { | 1693 static size_t GetMallocUsage() { |
| 1690 // Iterate through whichever heap the CRT is using. | 1694 // Iterate through whichever heap the CRT is using. |
| 1691 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | 1695 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2435 v8::MemoryPressureLevel::kCritical); | 2439 v8::MemoryPressureLevel::kCritical); |
| 2436 } | 2440 } |
| 2437 } | 2441 } |
| 2438 | 2442 |
| 2439 void RenderThreadImpl::OnRendererInterfaceRequest( | 2443 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2440 mojom::RendererAssociatedRequest request) { | 2444 mojom::RendererAssociatedRequest request) { |
| 2441 DCHECK(!renderer_binding_.is_bound()); | 2445 DCHECK(!renderer_binding_.is_bound()); |
| 2442 renderer_binding_.Bind(std::move(request)); | 2446 renderer_binding_.Bind(std::move(request)); |
| 2443 } | 2447 } |
| 2444 | 2448 |
| 2449 void RenderThreadImpl::OnPostWidgetUpdateVisualState() { | |
| 2450 if (record_first_active_paint_) | |
|
esprehn
2017/01/25 03:22:17
Can we put all of this code into RenderWidget inst
tasak
2017/01/26 09:39:40
I moved the code into RenderWidget.
| |
| 2451 return; | |
| 2452 | |
| 2453 record_first_active_paint_ = true; | |
| 2454 base::TimeDelta sample = base::TimeTicks::Now() - foregrounded_time_; | |
| 2455 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint", | |
| 2456 sample); | |
| 2457 } | |
| 2458 | |
| 2445 } // namespace content | 2459 } // namespace content |
| OLD | NEW |