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

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 | « no previous file | 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), "30min", process_foregrounded_count_),
1703 base::TimeDelta::FromMinutes(30));
1704 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1705 FROM_HERE,
1706 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1707 base::Unretained(this), "60min", process_foregrounded_count_),
1708 base::TimeDelta::FromMinutes(60));
1709 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1710 FROM_HERE,
1711 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics,
1712 base::Unretained(this), "90min", process_foregrounded_count_),
1713 base::TimeDelta::FromMinutes(90));
1698 } 1714 }
1699 1715
1700 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra 1716 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra
1701 // when it is possible to run memory-infra without tracing. 1717 // when it is possible to run memory-infra without tracing.
1702 #if defined(OS_WIN) 1718 #if defined(OS_WIN)
1703 namespace { 1719 namespace {
1704 1720
1705 static size_t GetMallocUsage() { 1721 static size_t GetMallocUsage() {
1706 // Iterate through whichever heap the CRT is using. 1722 // Iterate through whichever heap the CRT is using.
1707 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); 1723 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; 1805 total_allocated / render_view_count / 1024 / 1024;
1790 1806
1791 return true; 1807 return true;
1792 } 1808 }
1793 1809
1794 #define GET_MEMORY_GROWTH(current, previous, allocator) \ 1810 #define GET_MEMORY_GROWTH(current, previous, allocator) \
1795 (current.allocator > previous.allocator \ 1811 (current.allocator > previous.allocator \
1796 ? current.allocator - previous.allocator \ 1812 ? current.allocator - previous.allocator \
1797 : 0) 1813 : 0)
1798 1814
1799 #define UMA_HISTOGRAM_MEMORY_GROWTH_KB(basename, suffix, memory_usage) \ 1815 static void RecordPurgeAndSuspendMemoryGrowthKB(const char* basename,
1800 { \ 1816 const char* suffix,
1801 std::string histogram_name = \ 1817 int memory_usage) {
1802 base::StringPrintf("%s.%s", basename, suffix); \ 1818 std::string histogram_name = base::StringPrintf("%s.%s", basename, suffix);
1803 UMA_HISTOGRAM_MEMORY_KB(histogram_name, memory_usage); \ 1819 base::UmaHistogramMemoryKB(histogram_name, memory_usage);
1804 } 1820 }
1805 1821
1806 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics( 1822 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics(
1807 const char* suffix, 1823 const char* suffix,
1808 int foregrounded_count_when_purged) { 1824 int foregrounded_count_when_purged) {
1809 // If this renderer is resumed, we should not update UMA. 1825 // If this renderer is resumed, we should not update UMA.
1810 if (!RendererIsHidden()) 1826 if (!RendererIsHidden())
1811 return; 1827 return;
1812 if (foregrounded_count_when_purged != process_foregrounded_count_) 1828 if (foregrounded_count_when_purged != process_foregrounded_count_)
1813 return; 1829 return;
1814 1830
1815 RendererMemoryMetrics memory_metrics; 1831 RendererMemoryMetrics memory_metrics;
1816 if (!GetRendererMemoryMetrics(&memory_metrics)) 1832 if (!GetRendererMemoryMetrics(&memory_metrics))
1817 return; 1833 return;
1818 1834
1819 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1835 RecordPurgeAndSuspendMemoryGrowthKB(
1820 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix, 1836 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix,
1821 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1837 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1822 partition_alloc_kb)); 1838 partition_alloc_kb));
1823 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1839 RecordPurgeAndSuspendMemoryGrowthKB(
1824 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix, 1840 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix,
1825 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1841 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1826 blink_gc_kb)); 1842 blink_gc_kb));
1827 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1843 RecordPurgeAndSuspendMemoryGrowthKB(
1828 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix, 1844 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix,
1829 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1845 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1830 malloc_mb) * 1846 malloc_mb) *
1831 1024); 1847 1024);
1832 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1848 RecordPurgeAndSuspendMemoryGrowthKB(
1833 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix, 1849 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", suffix,
1834 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1850 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1835 discardable_kb)); 1851 discardable_kb));
1836 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1852 RecordPurgeAndSuspendMemoryGrowthKB(
1837 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix, 1853 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", suffix,
1838 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1854 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1839 v8_main_thread_isolate_mb) * 1855 v8_main_thread_isolate_mb) *
1840 1024); 1856 1024);
1841 UMA_HISTOGRAM_MEMORY_GROWTH_KB( 1857 RecordPurgeAndSuspendMemoryGrowthKB(
1842 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix, 1858 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", suffix,
1843 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, 1859 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_,
1844 total_allocated_mb) * 1860 total_allocated_mb) *
1845 1024); 1861 1024);
1846 } 1862 }
1847 1863
1848 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { 1864 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
1849 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); 1865 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1850 1866
1851 if (gpu_channel_) { 1867 if (gpu_channel_) {
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 } 2474 }
2459 } 2475 }
2460 2476
2461 void RenderThreadImpl::OnRendererInterfaceRequest( 2477 void RenderThreadImpl::OnRendererInterfaceRequest(
2462 mojom::RendererAssociatedRequest request) { 2478 mojom::RendererAssociatedRequest request) {
2463 DCHECK(!renderer_binding_.is_bound()); 2479 DCHECK(!renderer_binding_.is_bound());
2464 renderer_binding_.Bind(std::move(request)); 2480 renderer_binding_.Bind(std::move(request));
2465 } 2481 }
2466 2482
2467 } // namespace content 2483 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698