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

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

Issue 2899683002: Reenable Purge+Suspend Memory Growth metrics. (Closed)
Patch Set: Fixed. 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
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/allocator/allocator_extension.h" 13 #include "base/allocator/allocator_extension.h"
14 #include "base/at_exit.h" 14 #include "base/at_exit.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/debug/crash_logging.h" 16 #include "base/debug/crash_logging.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/discardable_memory_allocator.h" 20 #include "base/memory/discardable_memory_allocator.h"
21 #include "base/memory/memory_coordinator_client_registry.h" 21 #include "base/memory/memory_coordinator_client_registry.h"
22 #include "base/memory/ptr_util.h" 22 #include "base/memory/ptr_util.h"
23 #include "base/memory/shared_memory.h" 23 #include "base/memory/shared_memory.h"
24 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
25 #include "base/metrics/field_trial.h" 25 #include "base/metrics/field_trial.h"
26 #include "base/metrics/histogram_functions.h"
26 #include "base/metrics/histogram_macros.h" 27 #include "base/metrics/histogram_macros.h"
27 #include "base/path_service.h" 28 #include "base/path_service.h"
28 #include "base/process/process_metrics.h" 29 #include "base/process/process_metrics.h"
29 #include "base/run_loop.h" 30 #include "base/run_loop.h"
30 #include "base/strings/string16.h" 31 #include "base/strings/string16.h"
31 #include "base/strings/string_number_conversions.h" 32 #include "base/strings/string_number_conversions.h"
32 #include "base/strings/string_split.h" 33 #include "base/strings/string_split.h"
33 #include "base/strings/sys_string_conversions.h" 34 #include "base/strings/sys_string_conversions.h"
34 #include "base/strings/utf_string_conversions.h" 35 #include "base/strings/utf_string_conversions.h"
35 #include "base/threading/sequenced_worker_pool.h" 36 #include "base/threading/sequenced_worker_pool.h"
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 return; 1689 return;
1689 1690
1690 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); 1691 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
1691 needs_to_record_first_active_paint_ = true; 1692 needs_to_record_first_active_paint_ = true;
1692 1693
1693 RendererMemoryMetrics memory_metrics; 1694 RendererMemoryMetrics memory_metrics;
1694 if (!GetRendererMemoryMetrics(&memory_metrics)) 1695 if (!GetRendererMemoryMetrics(&memory_metrics))
1695 return; 1696 return;
1696 1697
1697 purge_and_suspend_memory_metrics_ = memory_metrics; 1698 purge_and_suspend_memory_metrics_ = memory_metrics;
1699 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1700 FROM_HERE,
1701 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1702 base::Unretained(this), process_foregrounded_count_,
1703 RECORD_30MIN_AFTER_PURGE),
1704 base::TimeDelta::FromMinutes(30));
1705 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1706 FROM_HERE,
1707 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1708 base::Unretained(this), process_foregrounded_count_,
1709 RECORD_60MIN_AFTER_PURGE),
1710 base::TimeDelta::FromMinutes(60));
1711 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1712 FROM_HERE,
1713 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1714 base::Unretained(this), process_foregrounded_count_,
1715 RECORD_90MIN_AFTER_PURGE),
1716 base::TimeDelta::FromMinutes(90));
1698 } 1717 }
1699 1718
1700 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra 1719 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra
1701 // when it is possible to run memory-infra without tracing. 1720 // when it is possible to run memory-infra without tracing.
1702 #if defined(OS_WIN) 1721 #if defined(OS_WIN)
1703 namespace { 1722 namespace {
1704 1723
1705 static size_t GetMallocUsage() { 1724 static size_t GetMallocUsage() {
1706 // Iterate through whichever heap the CRT is using. 1725 // Iterate through whichever heap the CRT is using.
1707 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); 1726 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 total_allocated / render_view_count / 1024 / 1024; 1808 total_allocated / render_view_count / 1024 / 1024;
1790 1809
1791 return true; 1810 return true;
1792 } 1811 }
1793 1812
1794 #define GET_MEMORY_GROWTH(current, previous, allocator) \ 1813 #define GET_MEMORY_GROWTH(current, previous, allocator) \
1795 (current.allocator > previous.allocator \ 1814 (current.allocator > previous.allocator \
1796 ? current.allocator - previous.allocator \ 1815 ? current.allocator - previous.allocator \
1797 : 0) 1816 : 0)
1798 1817
1799 #define UMA_HISTOGRAM_MEMORY_GROWTH_KB(basename, suffix, memory_usage) \ 1818 #define UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH(suffix, memory_metrics) \
Ilya Sherman 2017/05/23 15:21:58 Rather than using a macro here, please revert to p
tasak 2017/05/24 05:08:19 I see. I misunderstood the previous comment. So by
1800 { \ 1819 base::UmaHistogramMemoryKB( \
1801 std::string histogram_name = \ 1820 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB" suffix, \
Ilya Sherman 2017/05/23 15:21:58 By the way, I think you lost the final dot in the
tasak 2017/05/24 05:08:19 Yeah, it's a critical bug... Thanks. Fixed by reve
1802 base::StringPrintf("%s.%s", basename, suffix); \ 1821 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1803 UMA_HISTOGRAM_MEMORY_KB(histogram_name, memory_usage); \ 1822 partition_alloc_kb)); \
1804 } 1823 base::UmaHistogramMemoryKB( \
1824 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB" suffix, \
1825 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1826 blink_gc_kb)); \
1827 base::UmaHistogramMemoryKB( \
1828 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB" suffix, \
1829 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1830 malloc_mb) * \
1831 1024); \
1832 base::UmaHistogramMemoryKB( \
1833 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB" suffix, \
1834 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1835 discardable_kb)); \
1836 base::UmaHistogramMemoryKB( \
1837 "PurgeAndSuspend.Experimental.MemoryGrowth." \
1838 "V8MainThreadIsolateKB" suffix, \
1839 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1840 v8_main_thread_isolate_mb) * \
1841 1024); \
1842 base::UmaHistogramMemoryKB( \
1843 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB" suffix, \
1844 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \
1845 total_allocated_mb) * \
1846 1024);
1805 1847
1806 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics( 1848 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics(
1807 const char* suffix, 1849 int foregrounded_count_when_purged,
1808 int foregrounded_count_when_purged) { 1850 RenderThreadImpl::RecordMemoryGrowthTiming record_timing) {
1809 // If this renderer is resumed, we should not update UMA. 1851 // If this renderer is resumed, we should not update UMA.
1810 if (!RendererIsHidden()) 1852 if (!RendererIsHidden())
1811 return; 1853 return;
1812 if (foregrounded_count_when_purged != process_foregrounded_count_) 1854 if (foregrounded_count_when_purged != process_foregrounded_count_)
1813 return; 1855 return;
1814 1856
1815 RendererMemoryMetrics memory_metrics; 1857 RendererMemoryMetrics memory_metrics;
1816 if (!GetRendererMemoryMetrics(&memory_metrics)) 1858 if (!GetRendererMemoryMetrics(&memory_metrics))
1817 return; 1859 return;
1818 1860
1819 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1861 switch (record_timing) {
1820 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix, 1862 case RECORD_30MIN_AFTER_PURGE:
1821 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1863 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("30min", memory_metrics);
1822 partition_alloc_kb)); 1864 break;
1823 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1865 case RECORD_60MIN_AFTER_PURGE:
1824 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix, 1866 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("60min", memory_metrics);
1825 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1867 break;
1826 blink_gc_kb)); 1868 case RECORD_90MIN_AFTER_PURGE:
1827 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1869 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("90min", memory_metrics);
1828 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix, 1870 break;
1829 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1871 }
1830 malloc_mb) *
1831 1024);
1832 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1833 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix,
1834 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1835 discardable_kb));
1836 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1837 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix,
1838 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1839 v8_main_thread_isolate_mb) *
1840 1024);
1841 UMA_HISTOGRAM_MEMORY_GROWTH_KB(
1842 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix,
1843 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1844 total_allocated_mb) *
1845 1024);
1846 } 1872 }
1847 1873
1848 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { 1874 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
1849 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); 1875 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1850 1876
1851 if (gpu_channel_) { 1877 if (gpu_channel_) {
1852 // Do nothing if we already have a GPU channel or are already 1878 // Do nothing if we already have a GPU channel or are already
1853 // establishing one. 1879 // establishing one.
1854 if (!gpu_channel_->IsLost()) 1880 if (!gpu_channel_->IsLost())
1855 return gpu_channel_; 1881 return gpu_channel_;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 } 2484 }
2459 } 2485 }
2460 2486
2461 void RenderThreadImpl::OnRendererInterfaceRequest( 2487 void RenderThreadImpl::OnRendererInterfaceRequest(
2462 mojom::RendererAssociatedRequest request) { 2488 mojom::RendererAssociatedRequest request) {
2463 DCHECK(!renderer_binding_.is_bound()); 2489 DCHECK(!renderer_binding_.is_bound());
2464 renderer_binding_.Bind(std::move(request)); 2490 renderer_binding_.Bind(std::move(request));
2465 } 2491 }
2466 2492
2467 } // namespace content 2493 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698