Chromium Code Reviews| Index: content/renderer/render_thread_impl.cc |
| diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc |
| index 7c267b35fa6afcdd8e0997e16bafbd8f9635900c..d8aec6139cbebfaea714768ad661271de6572c3c 100644 |
| --- a/content/renderer/render_thread_impl.cc |
| +++ b/content/renderer/render_thread_impl.cc |
| @@ -1736,11 +1736,87 @@ void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| if (is_renderer_suspended_) |
| return; |
| + |
| + blink_memory_stats_ = blink::WebMemoryStatistics::Get(); |
| + malloc_stats_ = base::trace_event::MallocDumpProvider::GetStatistics(); |
| + discardable_stats_ = |
| + ChildThreadImpl::discardable_shared_memory_manager()->GetMemoryUsage(); |
| + |
| + // TODO(tasak): use MemoryCoordinator instead of NotifyMemoryPressure. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::allocator::ReleaseFreeMemory(); |
| + |
| + // Since purging is not a synchronouse task (e.g. v8 GC, oilpan GC, ...), |
| + // we need to wait until the task is finished. So wait 5 seconds and |
| + // update purge+suspend uma histogram. |
| + GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&RenderThreadImpl::OnDumpMemoryUsage, base::Unretained(this)), |
| + base::TimeDelta::FromSeconds(5)); |
| + |
| // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) |
| is_renderer_suspended_ = true; |
| renderer_scheduler_->SuspendRenderer(); |
| } |
| +// For purge+suspend, report memory usage diff by using UMA_HISTOGRAM. |
| +void RenderThreadImpl::OnDumpMemoryUsage() { |
| + // If this renderer is resumed, we should not update uma. |
| + if (!is_renderer_suspended_) |
| + return; |
| + |
| + blink::WebMemoryStatistics stats_after = blink::WebMemoryStatistics::Get(); |
| + |
| + base::trace_event::MallocStatistics malloc_stats_after = |
| + base::trace_event::MallocDumpProvider::GetStatistics(); |
| + |
| + size_t discardable_usage_after = |
| + ChildThreadImpl::discardable_shared_memory_manager()->GetMemoryUsage(); |
| + |
| + ssize_t diff = blink_memory_stats_.partitionAllocTotalAllocatedBytes - |
| + stats_after.partitionAllocTotalAllocatedBytes; |
| + ssize_t total_diff = diff; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.PartitionAllocGrowth", -diff); |
| + |
| + diff = blink_memory_stats_.blinkGCTotalAllocatedBytes - |
| + stats_after.blinkGCTotalAllocatedBytes; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCGrowth", -diff); |
| + |
| + diff = malloc_stats_.allocated_objects_size - |
| + malloc_stats_after.allocated_objects_size; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.MallocGrowth", -diff); |
| + total_diff += diff; |
| + |
| + diff = malloc_stats_.resident_size - malloc_stats_after.resident_size; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeGrowth", -diff); |
| + total_diff += diff; |
| + |
| + diff = discardable_stats_ - discardable_usage_after; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableGrowth", -diff); |
| + total_diff += diff; |
| + |
| + if (total_diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.TotalShrink", total_diff); |
| + else |
| + 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
|
| +} |
| + |
| void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { |
| // Debug cases of https://crbug.com/626802. |
| base::debug::SetCrashKeyValue("newframe_routing_id", |