| 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 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 | 916 |
| 917 #if defined(OS_LINUX) | 917 #if defined(OS_LINUX) |
| 918 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); | 918 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); |
| 919 ChildThreadImpl::current()->SetThreadPriority( | 919 ChildThreadImpl::current()->SetThreadPriority( |
| 920 categorized_worker_pool_->background_worker_thread_id(), | 920 categorized_worker_pool_->background_worker_thread_id(), |
| 921 base::ThreadPriority::BACKGROUND); | 921 base::ThreadPriority::BACKGROUND); |
| 922 #endif | 922 #endif |
| 923 | 923 |
| 924 record_purge_suspend_metric_closure_.Reset(base::Bind( | 924 record_purge_suspend_metric_closure_.Reset(base::Bind( |
| 925 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); | 925 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); |
| 926 record_purge_suspend_growth_metric_closure_.Reset( |
| 927 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 928 base::Unretained(this))); |
| 926 | 929 |
| 927 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 930 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 928 | 931 |
| 929 // If this renderer doesn't run inside the browser process, enable | 932 // If this renderer doesn't run inside the browser process, enable |
| 930 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 933 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 931 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 934 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 932 // redirection experiment concludes https://crbug.com/622400. | 935 // redirection experiment concludes https://crbug.com/622400. |
| 933 if (!command_line.HasSwitch(switches::kSingleProcess)) | 936 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 934 base::SequencedWorkerPool::EnableForProcess(); | 937 base::SequencedWorkerPool::EnableForProcess(); |
| 935 } | 938 } |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1666 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1664 // and follow MemoryCoordinator's request. | 1667 // and follow MemoryCoordinator's request. |
| 1665 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | 1668 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1666 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1669 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1667 base::MemoryState::NORMAL); | 1670 base::MemoryState::NORMAL); |
| 1668 | 1671 |
| 1669 record_purge_suspend_metric_closure_.Cancel(); | 1672 record_purge_suspend_metric_closure_.Cancel(); |
| 1670 record_purge_suspend_metric_closure_.Reset( | 1673 record_purge_suspend_metric_closure_.Reset( |
| 1671 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1674 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1672 base::Unretained(this))); | 1675 base::Unretained(this))); |
| 1676 record_purge_suspend_growth_metric_closure_.Cancel(); |
| 1677 record_purge_suspend_growth_metric_closure_.Reset( |
| 1678 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1679 base::Unretained(this))); |
| 1673 } | 1680 } |
| 1674 } | 1681 } |
| 1675 | 1682 |
| 1676 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1683 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1677 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1684 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1678 if (!RendererIsHidden()) | 1685 if (!RendererIsHidden()) |
| 1679 return; | 1686 return; |
| 1680 | 1687 |
| 1681 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1688 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 1682 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1689 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 memory_metrics->non_discardable_total_allocated_mb = | 1784 memory_metrics->non_discardable_total_allocated_mb = |
| 1778 (total_allocated - discardable_usage) / 1024 / 1024; | 1785 (total_allocated - discardable_usage) / 1024 / 1024; |
| 1779 memory_metrics->total_allocated_per_render_view_mb = | 1786 memory_metrics->total_allocated_per_render_view_mb = |
| 1780 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024; | 1787 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024; |
| 1781 } | 1788 } |
| 1782 | 1789 |
| 1783 // TODO(tasak): Once it is possible to use memory-infra without tracing, | 1790 // TODO(tasak): Once it is possible to use memory-infra without tracing, |
| 1784 // we should collect the metrics using memory-infra. | 1791 // we should collect the metrics using memory-infra. |
| 1785 // TODO(tasak): We should also report a difference between the memory usages | 1792 // TODO(tasak): We should also report a difference between the memory usages |
| 1786 // before and after purging by using memory-infra. | 1793 // before and after purging by using memory-infra. |
| 1787 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { | 1794 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() { |
| 1788 // If this renderer is resumed, we should not update UMA. | 1795 // If this renderer is resumed, we should not update UMA. |
| 1789 if (!RendererIsHidden()) | 1796 if (!RendererIsHidden()) |
| 1790 return; | 1797 return; |
| 1791 | 1798 |
| 1792 // TODO(tasak): Compare memory metrics between purge-enabled renderers and | 1799 // TODO(tasak): Compare memory metrics between purge-enabled renderers and |
| 1793 // purge-disabled renderers (A/B testing). | 1800 // purge-disabled renderers (A/B testing). |
| 1794 RendererMemoryMetrics memory_metrics; | 1801 RendererMemoryMetrics memory_metrics; |
| 1795 GetRendererMemoryMetrics(&memory_metrics); | 1802 GetRendererMemoryMetrics(&memory_metrics); |
| 1796 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", | 1803 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", |
| 1797 memory_metrics.partition_alloc_kb); | 1804 memory_metrics.partition_alloc_kb); |
| 1798 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", | 1805 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", |
| 1799 memory_metrics.blink_gc_kb); | 1806 memory_metrics.blink_gc_kb); |
| 1800 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", | 1807 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", |
| 1801 memory_metrics.malloc_mb); | 1808 memory_metrics.malloc_mb); |
| 1802 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", | 1809 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", |
| 1803 memory_metrics.discardable_kb); | 1810 memory_metrics.discardable_kb); |
| 1804 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", | 1811 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", |
| 1805 memory_metrics.v8_main_thread_isolate_mb); | 1812 memory_metrics.v8_main_thread_isolate_mb); |
| 1806 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", | 1813 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", |
| 1807 memory_metrics.total_allocated_mb); | 1814 memory_metrics.total_allocated_mb); |
| 1815 purge_and_suspend_memory_metrics_ = memory_metrics; |
| 1816 |
| 1817 // record how many memory usage increases after purged. |
| 1818 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1819 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), |
| 1820 base::TimeDelta::FromMinutes(5)); |
| 1821 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1822 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), |
| 1823 base::TimeDelta::FromMinutes(10)); |
| 1824 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1825 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), |
| 1826 base::TimeDelta::FromMinutes(15)); |
| 1827 } |
| 1828 |
| 1829 #define GET_MEMORY_GROWTH(current, previous, allocator) \ |
| 1830 (current.allocator > previous.allocator \ |
| 1831 ? current.allocator - previous.allocator \ |
| 1832 : 0) |
| 1833 |
| 1834 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics() const { |
| 1835 // If this renderer is resumed, we should not update UMA. |
| 1836 if (!RendererIsHidden()) |
| 1837 return; |
| 1838 |
| 1839 RendererMemoryMetrics memory_metrics; |
| 1840 GetRendererMemoryMetrics(&memory_metrics); |
| 1841 UMA_HISTOGRAM_MEMORY_KB( |
| 1842 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", |
| 1843 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1844 partition_alloc_kb)); |
| 1845 UMA_HISTOGRAM_MEMORY_KB( |
| 1846 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", |
| 1847 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1848 blink_gc_kb)); |
| 1849 UMA_HISTOGRAM_MEMORY_MB( |
| 1850 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocMB", |
| 1851 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1852 malloc_mb)); |
| 1853 UMA_HISTOGRAM_MEMORY_KB( |
| 1854 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", |
| 1855 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1856 discardable_kb)); |
| 1857 UMA_HISTOGRAM_MEMORY_MB( |
| 1858 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateMB", |
| 1859 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1860 v8_main_thread_isolate_mb)); |
| 1861 UMA_HISTOGRAM_MEMORY_MB( |
| 1862 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedMB", |
| 1863 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1864 total_allocated_mb)); |
| 1808 } | 1865 } |
| 1809 | 1866 |
| 1810 void RenderThreadImpl::OnProcessResume() { | 1867 void RenderThreadImpl::OnProcessResume() { |
| 1811 ChildThreadImpl::OnProcessResume(); | 1868 ChildThreadImpl::OnProcessResume(); |
| 1812 | 1869 |
| 1813 if (!RendererIsHidden()) | 1870 if (!RendererIsHidden()) |
| 1814 return; | 1871 return; |
| 1815 | 1872 |
| 1816 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1873 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 1817 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1874 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 } | 2459 } |
| 2403 } | 2460 } |
| 2404 | 2461 |
| 2405 void RenderThreadImpl::OnRendererInterfaceRequest( | 2462 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2406 mojom::RendererAssociatedRequest request) { | 2463 mojom::RendererAssociatedRequest request) { |
| 2407 DCHECK(!renderer_binding_.is_bound()); | 2464 DCHECK(!renderer_binding_.is_bound()); |
| 2408 renderer_binding_.Bind(std::move(request)); | 2465 renderer_binding_.Bind(std::move(request)); |
| 2409 } | 2466 } |
| 2410 | 2467 |
| 2411 } // namespace content | 2468 } // namespace content |
| OLD | NEW |