Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2843373004: Record renderer's memory growth 30min, 60min and 90min after purging separately. (Closed)
Patch Set: Updated Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 GetConnector()->BindInterface(mojom::kBrowserServiceName, 894 GetConnector()->BindInterface(mojom::kBrowserServiceName,
895 mojo::MakeRequest(&storage_partition_service_)); 895 mojo::MakeRequest(&storage_partition_service_));
896 896
897 #if defined(OS_LINUX) 897 #if defined(OS_LINUX)
898 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); 898 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY);
899 ChildThreadImpl::current()->SetThreadPriority( 899 ChildThreadImpl::current()->SetThreadPriority(
900 categorized_worker_pool_->background_worker_thread_id(), 900 categorized_worker_pool_->background_worker_thread_id(),
901 base::ThreadPriority::BACKGROUND); 901 base::ThreadPriority::BACKGROUND);
902 #endif 902 #endif
903 903
904 record_purge_suspend_growth_metric_closure_.Reset( 904 process_foregrounded_count_ = 0;
905 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
906 base::Unretained(this)));
907 needs_to_record_first_active_paint_ = false; 905 needs_to_record_first_active_paint_ = false;
908 906
909 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); 907 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
910 908
911 // If this renderer doesn't run inside the browser process, enable 909 // If this renderer doesn't run inside the browser process, enable
912 // SequencedWorkerPool. Otherwise, it should already have been enabled. 910 // SequencedWorkerPool. Otherwise, it should already have been enabled.
913 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler 911 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler
914 // redirection experiment concludes https://crbug.com/622400. 912 // redirection experiment concludes https://crbug.com/622400.
915 if (!command_line.HasSwitch(switches::kSingleProcess)) 913 if (!command_line.HasSwitch(switches::kSingleProcess))
916 base::SequencedWorkerPool::EnableForProcess(); 914 base::SequencedWorkerPool::EnableForProcess();
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 } 1649 }
1652 1650
1653 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { 1651 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) {
1654 ChildThreadImpl::OnProcessBackgrounded(backgrounded); 1652 ChildThreadImpl::OnProcessBackgrounded(backgrounded);
1655 1653
1656 if (backgrounded) { 1654 if (backgrounded) {
1657 renderer_scheduler_->OnRendererBackgrounded(); 1655 renderer_scheduler_->OnRendererBackgrounded();
1658 needs_to_record_first_active_paint_ = false; 1656 needs_to_record_first_active_paint_ = false;
1659 } else { 1657 } else {
1660 renderer_scheduler_->OnRendererForegrounded(); 1658 renderer_scheduler_->OnRendererForegrounded();
1661 1659 process_foregrounded_count_++;
1662 record_purge_suspend_growth_metric_closure_.Cancel();
1663 record_purge_suspend_growth_metric_closure_.Reset(
1664 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1665 base::Unretained(this)));
1666 } 1660 }
1667 } 1661 }
1668 1662
1669 void RenderThreadImpl::OnProcessPurgeAndSuspend() { 1663 void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1670 ChildThreadImpl::OnProcessPurgeAndSuspend(); 1664 ChildThreadImpl::OnProcessPurgeAndSuspend();
1671 if (!RendererIsHidden()) 1665 if (!RendererIsHidden())
1672 return; 1666 return;
1673 1667
1674 if (!base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) 1668 if (!base::FeatureList::IsEnabled(features::kPurgeAndSuspend))
1675 return; 1669 return;
1676 1670
1677 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); 1671 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
1678 needs_to_record_first_active_paint_ = true; 1672 needs_to_record_first_active_paint_ = true;
1679 1673
1680 RendererMemoryMetrics memory_metrics; 1674 RendererMemoryMetrics memory_metrics;
1681 if (!GetRendererMemoryMetrics(&memory_metrics)) 1675 if (!GetRendererMemoryMetrics(&memory_metrics))
1682 return; 1676 return;
1683 1677
1684 purge_and_suspend_memory_metrics_ = memory_metrics; 1678 purge_and_suspend_memory_metrics_ = memory_metrics;
1685 // record how many memory usage increases after purged. 1679 // record how many memory usage increases after purged.
1686 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( 1680 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1687 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), 1681 FROM_HERE,
1688 base::TimeDelta::FromMinutes(5)); 1682 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1683 base::Unretained(this), "30min", process_foregrounded_count_),
1684 base::TimeDelta::FromMinutes(30));
1689 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( 1685 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1690 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), 1686 FROM_HERE,
1691 base::TimeDelta::FromMinutes(10)); 1687 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1688 base::Unretained(this), "60min", process_foregrounded_count_),
1689 base::TimeDelta::FromMinutes(60));
1692 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( 1690 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1693 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), 1691 FROM_HERE,
1694 base::TimeDelta::FromMinutes(15)); 1692 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1693 base::Unretained(this), "90min", process_foregrounded_count_),
1694 base::TimeDelta::FromMinutes(90));
1695 } 1695 }
1696 1696
1697 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra 1697 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra
1698 // when it is possible to run memory-infra without tracing. 1698 // when it is possible to run memory-infra without tracing.
1699 #if defined(OS_WIN) 1699 #if defined(OS_WIN)
1700 namespace { 1700 namespace {
1701 1701
1702 static size_t GetMallocUsage() { 1702 static size_t GetMallocUsage() {
1703 // Iterate through whichever heap the CRT is using. 1703 // Iterate through whichever heap the CRT is using.
1704 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); 1704 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 total_allocated / render_view_count / 1024 / 1024; 1786 total_allocated / render_view_count / 1024 / 1024;
1787 1787
1788 return true; 1788 return true;
1789 } 1789 }
1790 1790
1791 #define GET_MEMORY_GROWTH(current, previous, allocator) \ 1791 #define GET_MEMORY_GROWTH(current, previous, allocator) \
1792 (current.allocator > previous.allocator \ 1792 (current.allocator > previous.allocator \
1793 ? current.allocator - previous.allocator \ 1793 ? current.allocator - previous.allocator \
1794 : 0) 1794 : 0)
1795 1795
1796 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics() const { 1796 #define UMA_HISTOGRAM_MEMORY_GROWTH_KB(basename, suffix, memory_usage) \
1797 { \
1798 std::string histogram_name = \
1799 base::StringPrintf("%s.%s", basename, suffix); \
1800 UMA_HISTOGRAM_MEMORY_KB(histogram_name, memory_usage); \
1801 }
1802
1803 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics(
1804 const char* suffix,
1805 int foregrounded_count_when_purged) {
1797 // If this renderer is resumed, we should not update UMA. 1806 // If this renderer is resumed, we should not update UMA.
1798 if (!RendererIsHidden()) 1807 if (!RendererIsHidden())
1799 return; 1808 return;
1809 if (foregrounded_count_when_purged != process_foregrounded_count_)
1810 return;
1800 1811
1801 RendererMemoryMetrics memory_metrics; 1812 RendererMemoryMetrics memory_metrics;
1802 if (!GetRendererMemoryMetrics(&memory_metrics)) 1813 if (!GetRendererMemoryMetrics(&memory_metrics))
1803 return; 1814 return;
1804 1815
1805 UMA_HISTOGRAM_MEMORY_KB( 1816 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1806 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", 1817 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix,
1807 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1818 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1808 partition_alloc_kb)); 1819 partition_alloc_kb));
1809 UMA_HISTOGRAM_MEMORY_KB( 1820 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1810 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", 1821 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix,
1811 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1822 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1812 blink_gc_kb)); 1823 blink_gc_kb));
1813 UMA_HISTOGRAM_MEMORY_KB( 1824 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1814 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", 1825 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix,
1815 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1826 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1816 malloc_mb) * 1024); 1827 malloc_mb) *
1817 UMA_HISTOGRAM_MEMORY_KB( 1828 1024);
1818 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", 1829 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1830 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix,
1819 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1831 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1820 discardable_kb)); 1832 discardable_kb));
1821 UMA_HISTOGRAM_MEMORY_KB( 1833 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1822 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", 1834 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix,
1823 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1835 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1824 v8_main_thread_isolate_mb) * 1024); 1836 v8_main_thread_isolate_mb) *
1825 UMA_HISTOGRAM_MEMORY_KB( 1837 1024);
1826 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", 1838 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1839 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix,
1827 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1840 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1828 total_allocated_mb) * 1024); 1841 total_allocated_mb) *
1842 1024);
1829 } 1843 }
1830 1844
1831 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { 1845 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
1832 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); 1846 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1833 1847
1834 if (gpu_channel_) { 1848 if (gpu_channel_) {
1835 // Do nothing if we already have a GPU channel or are already 1849 // Do nothing if we already have a GPU channel or are already
1836 // establishing one. 1850 // establishing one.
1837 if (!gpu_channel_->IsLost()) 1851 if (!gpu_channel_->IsLost())
1838 return gpu_channel_; 1852 return gpu_channel_;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 } 2455 }
2442 } 2456 }
2443 2457
2444 void RenderThreadImpl::OnRendererInterfaceRequest( 2458 void RenderThreadImpl::OnRendererInterfaceRequest(
2445 mojom::RendererAssociatedRequest request) { 2459 mojom::RendererAssociatedRequest request) {
2446 DCHECK(!renderer_binding_.is_bound()); 2460 DCHECK(!renderer_binding_.is_bound());
2447 renderer_binding_.Bind(std::move(request)); 2461 renderer_binding_.Bind(std::move(request));
2448 } 2462 }
2449 2463
2450 } // namespace content 2464 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698