Chromium Code Reviews| 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 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 } else { | 1730 } else { |
| 1731 renderer_scheduler_->OnRendererForegrounded(); | 1731 renderer_scheduler_->OnRendererForegrounded(); |
| 1732 is_renderer_suspended_ = false; | 1732 is_renderer_suspended_ = false; |
| 1733 } | 1733 } |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1736 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1737 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1737 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1738 if (is_renderer_suspended_) | 1738 if (is_renderer_suspended_) |
| 1739 return; | 1739 return; |
| 1740 | |
| 1741 blink_memory_stats_ = blink::WebMemoryStatistics::Get(); | |
| 1742 malloc_stats_ = base::memory::MallocStatistics::GetStatistics(); | |
| 1743 discardable_stats_ = | |
| 1744 ChildThreadImpl::discardable_shared_memory_manager()->GetStatistics(); | |
| 1745 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { | |
| 1746 v8::HeapStatistics v8_heap_statistics; | |
| 1747 isolate->GetHeapStatistics(&v8_heap_statistics); | |
| 1748 v8_total_heap_usage_ = v8_heap_statistics.total_heap_size(); | |
| 1749 } else { | |
| 1750 v8_total_heap_usage_ = 0; | |
| 1751 } | |
| 1752 | |
| 1753 // TODO(tasak): use MemoryCoordinator instead of NotifyMemoryPressure. | |
| 1754 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 1755 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 1756 base::allocator::ReleaseFreeMemory(); | |
| 1757 | |
| 1758 // Since purging is not a synchronouse task (e.g. v8 GC, oilpan GC, ...), | |
| 1759 // we need to wait until the task is finished. So wait 5 seconds and | |
| 1760 // update purge+suspend uma histogram. | |
| 1761 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
| 1762 FROM_HERE, | |
| 1763 base::Bind(&RenderThreadImpl::OnDumpMemoryUsage, base::Unretained(this)), | |
| 1764 base::TimeDelta::FromSeconds(5)); | |
|
Primiano Tucci (use gerrit)
2016/09/23 09:24:34
This smells odd. I understand purging is not sync.
tasak
2016/09/23 10:12:18
I agree with you. When we have MemoryCoordinatorV0
Primiano Tucci (use gerrit)
2016/09/23 19:31:09
Ok I see. ack. maybe add a comment here.
| |
| 1765 | |
| 1740 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) | 1766 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) |
| 1741 is_renderer_suspended_ = true; | 1767 is_renderer_suspended_ = true; |
| 1742 renderer_scheduler_->SuspendRenderer(); | 1768 renderer_scheduler_->SuspendRenderer(); |
| 1743 } | 1769 } |
| 1744 | 1770 |
| 1771 // For purge+suspend, report memory usage diff by using UMA_HISTOGRAM. | |
| 1772 void RenderThreadImpl::OnDumpMemoryUsage() { | |
| 1773 // If this renderer is resumed, we should not update uma. | |
| 1774 if (!is_renderer_suspended_) | |
| 1775 return; | |
| 1776 | |
| 1777 blink::WebMemoryStatistics current_blink_memory_stats = | |
| 1778 blink::WebMemoryStatistics::Get(); | |
| 1779 | |
| 1780 base::memory::MallocStatistics current_malloc_stats = | |
| 1781 base::memory::MallocStatistics::GetStatistics(); | |
| 1782 | |
| 1783 ChildDiscardableSharedMemoryManager::Statistics current_discardable_stats = | |
| 1784 ChildThreadImpl::discardable_shared_memory_manager()->GetStatistics(); | |
| 1785 | |
| 1786 size_t v8_total_heap_usage = 0; | |
| 1787 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { | |
| 1788 v8::HeapStatistics v8_heap_statistics; | |
| 1789 isolate->GetHeapStatistics(&v8_heap_statistics); | |
| 1790 v8_total_heap_usage = v8_heap_statistics.total_heap_size(); | |
| 1791 } | |
| 1792 | |
| 1793 int64_t diff = blink_memory_stats_.partitionAllocTotalAllocatedBytes - | |
| 1794 current_blink_memory_stats.partitionAllocTotalAllocatedBytes; | |
| 1795 int64_t total_diff = diff; | |
| 1796 if (diff > 0) | |
| 1797 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocShrink", diff); | |
| 1798 else | |
| 1799 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocGrowth", -diff); | |
| 1800 | |
| 1801 diff = blink_memory_stats_.blinkGCTotalAllocatedBytes - | |
| 1802 current_blink_memory_stats.blinkGCTotalAllocatedBytes; | |
| 1803 if (diff > 0) | |
| 1804 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCShrink", diff); | |
| 1805 else | |
| 1806 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCGrowth", -diff); | |
| 1807 total_diff += diff; | |
| 1808 | |
| 1809 diff = malloc_stats_.allocated_objects_size - | |
| 1810 current_malloc_stats.allocated_objects_size; | |
| 1811 if (diff > 0) | |
| 1812 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocShrink", diff); | |
| 1813 else | |
| 1814 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocGrowth", -diff); | |
| 1815 total_diff += diff; | |
| 1816 | |
| 1817 diff = (discardable_stats_.total_size - discardable_stats_.freelist_size) - | |
| 1818 (current_discardable_stats.total_size - | |
| 1819 current_discardable_stats.freelist_size); | |
| 1820 if (diff > 0) | |
| 1821 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableShrink", diff); | |
| 1822 else | |
| 1823 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableGrowth", -diff); | |
| 1824 total_diff += diff; | |
| 1825 | |
| 1826 diff = v8_total_heap_usage_ - v8_total_heap_usage; | |
| 1827 if (diff > 0) | |
| 1828 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapShrink", diff); | |
| 1829 else | |
| 1830 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapGrowth", -diff); | |
| 1831 total_diff += diff; | |
| 1832 | |
| 1833 if (total_diff > 0) | |
| 1834 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalShrink", total_diff); | |
| 1835 else | |
| 1836 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalGrowth", -total_diff); | |
| 1837 | |
| 1838 diff = malloc_stats_.resident_size - current_malloc_stats.resident_size; | |
| 1839 if (diff > 0) | |
| 1840 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeShrink", diff); | |
| 1841 else | |
| 1842 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeGrowth", -diff); | |
| 1843 } | |
| 1844 | |
| 1745 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { | 1845 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { |
| 1746 // Debug cases of https://crbug.com/626802. | 1846 // Debug cases of https://crbug.com/626802. |
| 1747 base::debug::SetCrashKeyValue("newframe_routing_id", | 1847 base::debug::SetCrashKeyValue("newframe_routing_id", |
| 1748 base::IntToString(params.routing_id)); | 1848 base::IntToString(params.routing_id)); |
| 1749 base::debug::SetCrashKeyValue("newframe_proxy_id", | 1849 base::debug::SetCrashKeyValue("newframe_proxy_id", |
| 1750 base::IntToString(params.proxy_routing_id)); | 1850 base::IntToString(params.proxy_routing_id)); |
| 1751 base::debug::SetCrashKeyValue("newframe_opener_id", | 1851 base::debug::SetCrashKeyValue("newframe_opener_id", |
| 1752 base::IntToString(params.opener_routing_id)); | 1852 base::IntToString(params.opener_routing_id)); |
| 1753 base::debug::SetCrashKeyValue("newframe_parent_id", | 1853 base::debug::SetCrashKeyValue("newframe_parent_id", |
| 1754 base::IntToString(params.parent_routing_id)); | 1854 base::IntToString(params.parent_routing_id)); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2292 if (blink::mainThreadIsolate()) { | 2392 if (blink::mainThreadIsolate()) { |
| 2293 blink::mainThreadIsolate()->MemoryPressureNotification( | 2393 blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2294 v8::MemoryPressureLevel::kCritical); | 2394 v8::MemoryPressureLevel::kCritical); |
| 2295 blink::MemoryPressureNotificationToWorkerThreadIsolates( | 2395 blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2296 v8::MemoryPressureLevel::kCritical); | 2396 v8::MemoryPressureLevel::kCritical); |
| 2297 } | 2397 } |
| 2298 } | 2398 } |
| 2299 | 2399 |
| 2300 | 2400 |
| 2301 } // namespace content | 2401 } // namespace content |
| OLD | NEW |