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 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1688 return; | 1688 return; |
1689 | 1689 |
1690 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); | 1690 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); |
1691 needs_to_record_first_active_paint_ = true; | 1691 needs_to_record_first_active_paint_ = true; |
1692 | 1692 |
1693 RendererMemoryMetrics memory_metrics; | 1693 RendererMemoryMetrics memory_metrics; |
1694 if (!GetRendererMemoryMetrics(&memory_metrics)) | 1694 if (!GetRendererMemoryMetrics(&memory_metrics)) |
1695 return; | 1695 return; |
1696 | 1696 |
1697 purge_and_suspend_memory_metrics_ = memory_metrics; | 1697 purge_and_suspend_memory_metrics_ = memory_metrics; |
1698 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
1699 FROM_HERE, | |
1700 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | |
1701 base::Unretained(this), process_foregrounded_count_, | |
1702 RECORD_30MIN_AFTER_PURGE), | |
1703 base::TimeDelta::FromMinutes(30)); | |
1704 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
1705 FROM_HERE, | |
1706 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | |
1707 base::Unretained(this), process_foregrounded_count_, | |
1708 RECORD_60MIN_AFTER_PURGE), | |
1709 base::TimeDelta::FromMinutes(60)); | |
1710 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
1711 FROM_HERE, | |
1712 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | |
1713 base::Unretained(this), process_foregrounded_count_, | |
1714 RECORD_90MIN_AFTER_PURGE), | |
1715 base::TimeDelta::FromMinutes(90)); | |
1698 } | 1716 } |
1699 | 1717 |
1700 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1718 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
1701 // when it is possible to run memory-infra without tracing. | 1719 // when it is possible to run memory-infra without tracing. |
1702 #if defined(OS_WIN) | 1720 #if defined(OS_WIN) |
1703 namespace { | 1721 namespace { |
1704 | 1722 |
1705 static size_t GetMallocUsage() { | 1723 static size_t GetMallocUsage() { |
1706 // Iterate through whichever heap the CRT is using. | 1724 // Iterate through whichever heap the CRT is using. |
1707 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | 1725 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1789 total_allocated / render_view_count / 1024 / 1024; | 1807 total_allocated / render_view_count / 1024 / 1024; |
1790 | 1808 |
1791 return true; | 1809 return true; |
1792 } | 1810 } |
1793 | 1811 |
1794 #define GET_MEMORY_GROWTH(current, previous, allocator) \ | 1812 #define GET_MEMORY_GROWTH(current, previous, allocator) \ |
1795 (current.allocator > previous.allocator \ | 1813 (current.allocator > previous.allocator \ |
1796 ? current.allocator - previous.allocator \ | 1814 ? current.allocator - previous.allocator \ |
1797 : 0) | 1815 : 0) |
1798 | 1816 |
1799 #define UMA_HISTOGRAM_MEMORY_GROWTH_KB(basename, suffix, memory_usage) \ | 1817 #define UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH(suffix, memory_metrics) \ |
1800 { \ | 1818 UMA_HISTOGRAM_MEMORY_KB( \ |
1801 std::string histogram_name = \ | 1819 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB" suffix, \ |
1802 base::StringPrintf("%s.%s", basename, suffix); \ | 1820 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ |
1803 UMA_HISTOGRAM_MEMORY_KB(histogram_name, memory_usage); \ | 1821 partition_alloc_kb)); \ |
1804 } | 1822 UMA_HISTOGRAM_MEMORY_KB( \ |
1823 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB" suffix, \ | |
1824 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
1825 blink_gc_kb)); \ | |
1826 UMA_HISTOGRAM_MEMORY_KB( \ | |
1827 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB" suffix, \ | |
1828 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
1829 malloc_mb) * \ | |
1830 1024); \ | |
1831 UMA_HISTOGRAM_MEMORY_KB( \ | |
1832 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB" suffix, \ | |
1833 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
1834 discardable_kb)); \ | |
1835 UMA_HISTOGRAM_MEMORY_KB( \ | |
1836 "PurgeAndSuspend.Experimental.MemoryGrowth." \ | |
1837 "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_KB( \ | |
Ilya Sherman
2017/05/22 20:28:01
Could you use base::UmaHistogramMemoryKB() and avo
tasak
2017/05/23 05:15:16
Done.
| |
1842 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB" suffix, \ | |
1843 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
1844 total_allocated_mb) * \ | |
1845 1024); | |
1805 | 1846 |
1806 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics( | 1847 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics( |
1807 const char* suffix, | 1848 int foregrounded_count_when_purged, |
1808 int foregrounded_count_when_purged) { | 1849 RenderThreadImpl::RecordMemoryGrowthTiming record_timing) { |
1809 // If this renderer is resumed, we should not update UMA. | 1850 // If this renderer is resumed, we should not update UMA. |
1810 if (!RendererIsHidden()) | 1851 if (!RendererIsHidden()) |
1811 return; | 1852 return; |
1812 if (foregrounded_count_when_purged != process_foregrounded_count_) | 1853 if (foregrounded_count_when_purged != process_foregrounded_count_) |
1813 return; | 1854 return; |
1814 | 1855 |
1815 RendererMemoryMetrics memory_metrics; | 1856 RendererMemoryMetrics memory_metrics; |
1816 if (!GetRendererMemoryMetrics(&memory_metrics)) | 1857 if (!GetRendererMemoryMetrics(&memory_metrics)) |
1817 return; | 1858 return; |
1818 | 1859 |
1819 UMA_HISTOGRAM_MEMORY_GROWTH_KB( | 1860 switch (record_timing) { |
1820 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", suffix, | 1861 case RECORD_30MIN_AFTER_PURGE: |
1821 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1862 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("30min", memory_metrics); |
1822 partition_alloc_kb)); | 1863 break; |
1823 UMA_HISTOGRAM_MEMORY_GROWTH_KB( | 1864 case RECORD_60MIN_AFTER_PURGE: |
1824 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", suffix, | 1865 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("60min", memory_metrics); |
1825 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1866 break; |
1826 blink_gc_kb)); | 1867 case RECORD_90MIN_AFTER_PURGE: |
1827 UMA_HISTOGRAM_MEMORY_GROWTH_KB( | 1868 UMA_PURGE_AND_SUSPEND_MEMORY_GROWTH("90min", memory_metrics); |
1828 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", suffix, | 1869 break; |
1829 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1870 default: |
1830 malloc_mb) * | 1871 NOTREACHED(); |
Ilya Sherman
2017/05/22 20:28:01
nit: In general, it's discouraged to have default
tasak
2017/05/23 05:15:16
Done.
| |
1831 1024); | 1872 } |
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 } | 1873 } |
1847 | 1874 |
1848 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1875 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
1849 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1876 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
1850 | 1877 |
1851 if (gpu_channel_) { | 1878 if (gpu_channel_) { |
1852 // Do nothing if we already have a GPU channel or are already | 1879 // Do nothing if we already have a GPU channel or are already |
1853 // establishing one. | 1880 // establishing one. |
1854 if (!gpu_channel_->IsLost()) | 1881 if (!gpu_channel_->IsLost()) |
1855 return gpu_channel_; | 1882 return gpu_channel_; |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2458 } | 2485 } |
2459 } | 2486 } |
2460 | 2487 |
2461 void RenderThreadImpl::OnRendererInterfaceRequest( | 2488 void RenderThreadImpl::OnRendererInterfaceRequest( |
2462 mojom::RendererAssociatedRequest request) { | 2489 mojom::RendererAssociatedRequest request) { |
2463 DCHECK(!renderer_binding_.is_bound()); | 2490 DCHECK(!renderer_binding_.is_bound()); |
2464 renderer_binding_.Bind(std::move(request)); | 2491 renderer_binding_.Bind(std::move(request)); |
2465 } | 2492 } |
2466 | 2493 |
2467 } // namespace content | 2494 } // namespace content |
OLD | NEW |