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

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

Issue 2636873002: memory metrics: record growth after purging BG renderer's cache (Closed)
Patch Set: Added label to PurgeAndSuspendExperiment. Created 3 years, 11 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
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 884
885 #if defined(OS_LINUX) 885 #if defined(OS_LINUX)
886 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); 886 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY);
887 ChildThreadImpl::current()->SetThreadPriority( 887 ChildThreadImpl::current()->SetThreadPriority(
888 categorized_worker_pool_->background_worker_thread_id(), 888 categorized_worker_pool_->background_worker_thread_id(),
889 base::ThreadPriority::BACKGROUND); 889 base::ThreadPriority::BACKGROUND);
890 #endif 890 #endif
891 891
892 record_purge_suspend_metric_closure_.Reset(base::Bind( 892 record_purge_suspend_metric_closure_.Reset(base::Bind(
893 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); 893 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this)));
894 record_purge_suspend_growth_metric_closure_.Reset(
895 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
896 base::Unretained(this)));
894 897
895 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); 898 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
896 899
897 // If this renderer doesn't run inside the browser process, enable 900 // If this renderer doesn't run inside the browser process, enable
898 // SequencedWorkerPool. Otherwise, it should already have been enabled. 901 // SequencedWorkerPool. Otherwise, it should already have been enabled.
899 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler 902 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler
900 // redirection experiment concludes https://crbug.com/622400. 903 // redirection experiment concludes https://crbug.com/622400.
901 if (!command_line.HasSwitch(switches::kSingleProcess)) 904 if (!command_line.HasSwitch(switches::kSingleProcess))
902 base::SequencedWorkerPool::EnableForProcess(); 905 base::SequencedWorkerPool::EnableForProcess();
903 } 906 }
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify 1642 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify
1640 // and follow MemoryCoordinator's request. 1643 // and follow MemoryCoordinator's request.
1641 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) 1644 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend))
1642 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( 1645 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(
1643 base::MemoryState::NORMAL); 1646 base::MemoryState::NORMAL);
1644 1647
1645 record_purge_suspend_metric_closure_.Cancel(); 1648 record_purge_suspend_metric_closure_.Cancel();
1646 record_purge_suspend_metric_closure_.Reset( 1649 record_purge_suspend_metric_closure_.Reset(
1647 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, 1650 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics,
1648 base::Unretained(this))); 1651 base::Unretained(this)));
1652 record_purge_suspend_growth_metric_closure_.Cancel();
1653 record_purge_suspend_growth_metric_closure_.Reset(
1654 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1655 base::Unretained(this)));
1649 } 1656 }
1650 } 1657 }
1651 1658
1652 void RenderThreadImpl::OnProcessPurgeAndSuspend() { 1659 void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1653 ChildThreadImpl::OnProcessPurgeAndSuspend(); 1660 ChildThreadImpl::OnProcessPurgeAndSuspend();
1654 if (!RendererIsHidden()) 1661 if (!RendererIsHidden())
1655 return; 1662 return;
1656 1663
1657 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. 1664 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled.
1658 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) 1665 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator))
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 memory_metrics->non_discardable_total_allocated_mb = 1760 memory_metrics->non_discardable_total_allocated_mb =
1754 (total_allocated - discardable_usage) / 1024 / 1024; 1761 (total_allocated - discardable_usage) / 1024 / 1024;
1755 memory_metrics->total_allocated_per_render_view_mb = 1762 memory_metrics->total_allocated_per_render_view_mb =
1756 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024; 1763 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024;
1757 } 1764 }
1758 1765
1759 // TODO(tasak): Once it is possible to use memory-infra without tracing, 1766 // TODO(tasak): Once it is possible to use memory-infra without tracing,
1760 // we should collect the metrics using memory-infra. 1767 // we should collect the metrics using memory-infra.
1761 // TODO(tasak): We should also report a difference between the memory usages 1768 // TODO(tasak): We should also report a difference between the memory usages
1762 // before and after purging by using memory-infra. 1769 // before and after purging by using memory-infra.
1763 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { 1770 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() {
1764 // If this renderer is resumed, we should not update UMA. 1771 // If this renderer is resumed, we should not update UMA.
1765 if (!RendererIsHidden()) 1772 if (!RendererIsHidden())
1766 return; 1773 return;
1767 1774
1768 // TODO(tasak): Compare memory metrics between purge-enabled renderers and 1775 // TODO(tasak): Compare memory metrics between purge-enabled renderers and
1769 // purge-disabled renderers (A/B testing). 1776 // purge-disabled renderers (A/B testing).
1770 RendererMemoryMetrics memory_metrics; 1777 RendererMemoryMetrics memory_metrics;
1771 GetRendererMemoryMetrics(&memory_metrics); 1778 GetRendererMemoryMetrics(&memory_metrics);
1772 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", 1779 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB",
1773 memory_metrics.partition_alloc_kb); 1780 memory_metrics.partition_alloc_kb);
1774 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", 1781 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB",
1775 memory_metrics.blink_gc_kb); 1782 memory_metrics.blink_gc_kb);
1776 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", 1783 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB",
1777 memory_metrics.malloc_mb); 1784 memory_metrics.malloc_mb);
1778 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", 1785 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB",
1779 memory_metrics.discardable_kb); 1786 memory_metrics.discardable_kb);
1780 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", 1787 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB",
1781 memory_metrics.v8_main_thread_isolate_mb); 1788 memory_metrics.v8_main_thread_isolate_mb);
1782 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", 1789 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB",
1783 memory_metrics.total_allocated_mb); 1790 memory_metrics.total_allocated_mb);
1791 purge_and_suspend_memory_metrics_ = memory_metrics;
1792
1793 // record how many memory usage increases after purged.
1794 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1795 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(),
1796 base::TimeDelta::FromMinutes(5));
1797 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1798 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(),
1799 base::TimeDelta::FromMinutes(10));
1800 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1801 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(),
1802 base::TimeDelta::FromMinutes(15));
1803 }
1804
1805 #define GET_MEMORY_GROWTH(current, previous, allocator) \
1806 (current.allocator > previous.allocator \
1807 ? current.allocator - previous.allocator \
1808 : 0)
1809
1810 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics() const {
1811 // If this renderer is resumed, we should not update UMA.
1812 if (!RendererIsHidden())
1813 return;
1814
1815 RendererMemoryMetrics memory_metrics;
1816 GetRendererMemoryMetrics(&memory_metrics);
1817 UMA_HISTOGRAM_MEMORY_KB(
1818 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB",
1819 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1820 partition_alloc_kb));
1821 UMA_HISTOGRAM_MEMORY_KB(
1822 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB",
1823 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1824 blink_gc_kb));
1825 UMA_HISTOGRAM_MEMORY_MB(
1826 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB",
1827 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1828 malloc_mb) * 1024);
1829 UMA_HISTOGRAM_MEMORY_KB(
1830 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB",
1831 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1832 discardable_kb));
1833 UMA_HISTOGRAM_MEMORY_MB(
1834 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB",
1835 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1836 v8_main_thread_isolate_mb) * 1024);
1837 UMA_HISTOGRAM_MEMORY_MB(
1838 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB",
1839 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1840 total_allocated_mb) * 1024);
1784 } 1841 }
1785 1842
1786 void RenderThreadImpl::OnProcessResume() { 1843 void RenderThreadImpl::OnProcessResume() {
1787 ChildThreadImpl::OnProcessResume(); 1844 ChildThreadImpl::OnProcessResume();
1788 1845
1789 if (!RendererIsHidden()) 1846 if (!RendererIsHidden())
1790 return; 1847 return;
1791 1848
1792 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. 1849 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled.
1793 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) 1850 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator))
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 } 2435 }
2379 } 2436 }
2380 2437
2381 void RenderThreadImpl::OnRendererInterfaceRequest( 2438 void RenderThreadImpl::OnRendererInterfaceRequest(
2382 mojom::RendererAssociatedRequest request) { 2439 mojom::RendererAssociatedRequest request) {
2383 DCHECK(!renderer_binding_.is_bound()); 2440 DCHECK(!renderer_binding_.is_bound());
2384 renderer_binding_.Bind(std::move(request)); 2441 renderer_binding_.Bind(std::move(request));
2385 } 2442 }
2386 2443
2387 } // namespace content 2444 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698