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

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

Issue 2350423003: [Tentaive patch for discussion] Add Purge+Suspend metrics as UMA.
Patch Set: Add v8 heap usage Created 4 years, 3 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
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 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 } else { 1729 } else {
1730 renderer_scheduler_->OnRendererForegrounded(); 1730 renderer_scheduler_->OnRendererForegrounded();
1731 is_renderer_suspended_ = false; 1731 is_renderer_suspended_ = false;
1732 } 1732 }
1733 } 1733 }
1734 1734
1735 void RenderThreadImpl::OnProcessPurgeAndSuspend() { 1735 void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1736 ChildThreadImpl::OnProcessPurgeAndSuspend(); 1736 ChildThreadImpl::OnProcessPurgeAndSuspend();
1737 if (is_renderer_suspended_) 1737 if (is_renderer_suspended_)
1738 return; 1738 return;
1739
1740 blink_memory_stats_ = blink::WebMemoryStatistics::Get();
1741 malloc_stats_ = base::trace_event::MallocDumpProvider::GetStatistics();
1742 discardable_stats_ =
1743 ChildThreadImpl::discardable_shared_memory_manager()->GetMemoryUsage();
1744 if (v8::Isolate* isolate = blink::mainThreadIsolate()) {
1745 v8::HeapStatistics v8_heap_statistics;
1746 isolate->GetHeapStatistics(&v8_heap_statistics);
1747 v8_total_heap_usage_ = v8_heap_statistics.total_heap_size();
1748 } else {
1749 v8_total_heap_usage_ = 0;
1750 }
1751
1752 // TODO(tasak): use MemoryCoordinator instead of NotifyMemoryPressure.
1753 base::MemoryPressureListener::NotifyMemoryPressure(
1754 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
1755 base::allocator::ReleaseFreeMemory();
1756
1757 // Since purging is not a synchronouse task (e.g. v8 GC, oilpan GC, ...),
1758 // we need to wait until the task is finished. So wait 5 seconds and
1759 // update purge+suspend uma histogram.
1760 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1761 FROM_HERE,
1762 base::Bind(&RenderThreadImpl::OnDumpMemoryUsage, base::Unretained(this)),
1763 base::TimeDelta::FromSeconds(5));
bashi 2016/09/22 23:28:26 (just for note; I understand this is WIP) Rather
1764
1739 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) 1765 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077)
1740 is_renderer_suspended_ = true; 1766 is_renderer_suspended_ = true;
1741 renderer_scheduler_->SuspendRenderer(); 1767 renderer_scheduler_->SuspendRenderer();
1742 } 1768 }
1743 1769
1770 // For purge+suspend, report memory usage diff by using UMA_HISTOGRAM.
1771 void RenderThreadImpl::OnDumpMemoryUsage() {
1772 // If this renderer is resumed, we should not update uma.
1773 if (!is_renderer_suspended_)
1774 return;
1775
1776 blink::WebMemoryStatistics stats_after = blink::WebMemoryStatistics::Get();
1777
1778 base::trace_event::MallocStatistics malloc_stats_after =
1779 base::trace_event::MallocDumpProvider::GetStatistics();
1780
1781 size_t discardable_usage_after =
1782 ChildThreadImpl::discardable_shared_memory_manager()->GetMemoryUsage();
1783
1784 size_t v8_total_heap_usage = 0;
1785 if (v8::Isolate* isolate = blink::mainThreadIsolate()) {
1786 v8::HeapStatistics v8_heap_statistics;
1787 isolate->GetHeapStatistics(&v8_heap_statistics);
1788 v8_total_heap_usage = v8_heap_statistics.total_heap_size();
1789 }
1790
1791 int64_t diff = blink_memory_stats_.partitionAllocTotalAllocatedBytes -
1792 stats_after.partitionAllocTotalAllocatedBytes;
1793 int64_t total_diff = diff;
1794 if (diff > 0)
1795 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocShrink", diff);
1796 else
1797 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocGrowth", -diff);
1798
1799 diff = blink_memory_stats_.blinkGCTotalAllocatedBytes -
1800 stats_after.blinkGCTotalAllocatedBytes;
1801 if (diff > 0)
1802 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCShrink", diff);
1803 else
1804 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCGrowth", -diff);
1805 total_diff += diff;
1806
1807 diff = malloc_stats_.allocated_objects_size -
1808 malloc_stats_after.allocated_objects_size;
1809 if (diff > 0)
1810 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocShrink", diff);
1811 else
1812 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocGrowth", -diff);
1813 total_diff += diff;
1814
1815 diff = discardable_stats_ - discardable_usage_after;
1816 if (diff > 0)
1817 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableShrink", diff);
1818 else
1819 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableGrowth", -diff);
1820 total_diff += diff;
1821
1822 diff = v8_total_heap_usage_ - v8_total_heap_usage;
1823 if (diff > 0)
1824 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapShrink", diff);
1825 else
1826 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapGrowth", -diff);
1827 total_diff += diff;
1828
1829 if (total_diff > 0)
1830 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalShrink", total_diff);
1831 else
1832 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalGrowth", -total_diff);
1833
1834 diff = malloc_stats_.resident_size - malloc_stats_after.resident_size;
1835 if (diff > 0)
1836 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeShrink", diff);
1837 else
1838 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeGrowth", -diff);
1839 }
1840
1744 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { 1841 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) {
1745 // Debug cases of https://crbug.com/626802. 1842 // Debug cases of https://crbug.com/626802.
1746 base::debug::SetCrashKeyValue("newframe_routing_id", 1843 base::debug::SetCrashKeyValue("newframe_routing_id",
1747 base::IntToString(params.routing_id)); 1844 base::IntToString(params.routing_id));
1748 base::debug::SetCrashKeyValue("newframe_proxy_id", 1845 base::debug::SetCrashKeyValue("newframe_proxy_id",
1749 base::IntToString(params.proxy_routing_id)); 1846 base::IntToString(params.proxy_routing_id));
1750 base::debug::SetCrashKeyValue("newframe_opener_id", 1847 base::debug::SetCrashKeyValue("newframe_opener_id",
1751 base::IntToString(params.opener_routing_id)); 1848 base::IntToString(params.opener_routing_id));
1752 base::debug::SetCrashKeyValue("newframe_parent_id", 1849 base::debug::SetCrashKeyValue("newframe_parent_id",
1753 base::IntToString(params.parent_routing_id)); 1850 base::IntToString(params.parent_routing_id));
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 if (blink::mainThreadIsolate()) { 2382 if (blink::mainThreadIsolate()) {
2286 blink::mainThreadIsolate()->MemoryPressureNotification( 2383 blink::mainThreadIsolate()->MemoryPressureNotification(
2287 v8::MemoryPressureLevel::kCritical); 2384 v8::MemoryPressureLevel::kCritical);
2288 blink::MemoryPressureNotificationToWorkerThreadIsolates( 2385 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2289 v8::MemoryPressureLevel::kCritical); 2386 v8::MemoryPressureLevel::kCritical);
2290 } 2387 }
2291 } 2388 }
2292 2389
2293 2390
2294 } // namespace content 2391 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698