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

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

Issue 2350423003: [Tentaive patch for discussion] Add Purge+Suspend metrics as UMA.
Patch Set: 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
1745 // TODO(tasak): use MemoryCoordinator instead of NotifyMemoryPressure.
1746 base::MemoryPressureListener::NotifyMemoryPressure(
1747 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
1748 base::allocator::ReleaseFreeMemory();
1749
1750 // Since purging is not a synchronouse task (e.g. v8 GC, oilpan GC, ...),
1751 // we need to wait until the task is finished. So wait 5 seconds and
1752 // update purge+suspend uma histogram.
1753 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1754 FROM_HERE,
1755 base::Bind(&RenderThreadImpl::OnDumpMemoryUsage, base::Unretained(this)),
1756 base::TimeDelta::FromSeconds(5));
1757
1739 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) 1758 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077)
1740 is_renderer_suspended_ = true; 1759 is_renderer_suspended_ = true;
1741 renderer_scheduler_->SuspendRenderer(); 1760 renderer_scheduler_->SuspendRenderer();
1742 } 1761 }
1743 1762
1763 // For purge+suspend, report memory usage diff by using UMA_HISTOGRAM.
1764 void RenderThreadImpl::OnDumpMemoryUsage() {
1765 // If this renderer is resumed, we should not update uma.
1766 if (!is_renderer_suspended_)
1767 return;
1768
1769 blink::WebMemoryStatistics stats_after = blink::WebMemoryStatistics::Get();
1770
1771 base::trace_event::MallocStatistics malloc_stats_after =
1772 base::trace_event::MallocDumpProvider::GetStatistics();
1773
1774 size_t discardable_usage_after =
1775 ChildThreadImpl::discardable_shared_memory_manager()->GetMemoryUsage();
1776
1777 ssize_t diff = blink_memory_stats_.partitionAllocTotalAllocatedBytes -
1778 stats_after.partitionAllocTotalAllocatedBytes;
1779 ssize_t total_diff = diff;
1780 if (diff > 0)
1781 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocShrink", diff);
1782 else
1783 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocGrowth", -diff);
1784
1785 diff = blink_memory_stats_.blinkGCTotalAllocatedBytes -
1786 stats_after.blinkGCTotalAllocatedBytes;
1787 if (diff > 0)
1788 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCShrink", diff);
1789 else
1790 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCGrowth", -diff);
1791
1792 diff = malloc_stats_.allocated_objects_size -
1793 malloc_stats_after.allocated_objects_size;
1794 if (diff > 0)
1795 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocShrink", diff);
1796 else
1797 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocGrowth", -diff);
1798 total_diff += diff;
1799
1800 diff = malloc_stats_.resident_size - malloc_stats_after.resident_size;
1801 if (diff > 0)
1802 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeShrink", diff);
1803 else
1804 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeGrowth", -diff);
1805 total_diff += diff;
1806
1807 diff = discardable_stats_ - discardable_usage_after;
1808 if (diff > 0)
1809 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableShrink", diff);
1810 else
1811 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableGrowth", -diff);
1812 total_diff += diff;
1813
1814 if (total_diff > 0)
1815 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalShrink", total_diff);
1816 else
1817 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalGrowth", -total_diff);
haraken 2016/09/20 12:19:14 isherman@: Is there any way to report a negative n
Ilya Sherman 2016/09/21 21:15:48 Yes, using a sparse histogram. But, it's not very
1818 }
1819
1744 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { 1820 void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) {
1745 // Debug cases of https://crbug.com/626802. 1821 // Debug cases of https://crbug.com/626802.
1746 base::debug::SetCrashKeyValue("newframe_routing_id", 1822 base::debug::SetCrashKeyValue("newframe_routing_id",
1747 base::IntToString(params.routing_id)); 1823 base::IntToString(params.routing_id));
1748 base::debug::SetCrashKeyValue("newframe_proxy_id", 1824 base::debug::SetCrashKeyValue("newframe_proxy_id",
1749 base::IntToString(params.proxy_routing_id)); 1825 base::IntToString(params.proxy_routing_id));
1750 base::debug::SetCrashKeyValue("newframe_opener_id", 1826 base::debug::SetCrashKeyValue("newframe_opener_id",
1751 base::IntToString(params.opener_routing_id)); 1827 base::IntToString(params.opener_routing_id));
1752 base::debug::SetCrashKeyValue("newframe_parent_id", 1828 base::debug::SetCrashKeyValue("newframe_parent_id",
1753 base::IntToString(params.parent_routing_id)); 1829 base::IntToString(params.parent_routing_id));
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 if (blink::mainThreadIsolate()) { 2361 if (blink::mainThreadIsolate()) {
2286 blink::mainThreadIsolate()->MemoryPressureNotification( 2362 blink::mainThreadIsolate()->MemoryPressureNotification(
2287 v8::MemoryPressureLevel::kCritical); 2363 v8::MemoryPressureLevel::kCritical);
2288 blink::MemoryPressureNotificationToWorkerThreadIsolates( 2364 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2289 v8::MemoryPressureLevel::kCritical); 2365 v8::MemoryPressureLevel::kCritical);
2290 } 2366 }
2291 } 2367 }
2292 2368
2293 2369
2294 } // namespace content 2370 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698