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 81605209e52e373ec6d972d44b5b8c842c8b6b65..6cdc6ef670166a53b982fca75ca42348c49fea50 100644 |
| --- a/content/renderer/render_thread_impl.cc |
| +++ b/content/renderer/render_thread_impl.cc |
| @@ -1737,11 +1737,111 @@ void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| if (is_renderer_suspended_) |
| return; |
| + |
| + blink_memory_stats_ = blink::WebMemoryStatistics::Get(); |
| + malloc_stats_ = base::memory::MallocStatistics::GetStatistics(); |
| + discardable_stats_ = |
| + ChildThreadImpl::discardable_shared_memory_manager()->GetStatistics(); |
| + if (v8::Isolate* isolate = blink::mainThreadIsolate()) { |
| + v8::HeapStatistics v8_heap_statistics; |
| + isolate->GetHeapStatistics(&v8_heap_statistics); |
| + v8_total_heap_usage_ = v8_heap_statistics.total_heap_size(); |
| + } else { |
| + v8_total_heap_usage_ = 0; |
| + } |
| + |
| + // 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)); |
|
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.
|
| + |
| // 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 current_blink_memory_stats = |
| + blink::WebMemoryStatistics::Get(); |
| + |
| + base::memory::MallocStatistics current_malloc_stats = |
| + base::memory::MallocStatistics::GetStatistics(); |
| + |
| + ChildDiscardableSharedMemoryManager::Statistics current_discardable_stats = |
| + ChildThreadImpl::discardable_shared_memory_manager()->GetStatistics(); |
| + |
| + size_t v8_total_heap_usage = 0; |
| + if (v8::Isolate* isolate = blink::mainThreadIsolate()) { |
| + v8::HeapStatistics v8_heap_statistics; |
| + isolate->GetHeapStatistics(&v8_heap_statistics); |
| + v8_total_heap_usage = v8_heap_statistics.total_heap_size(); |
| + } |
| + |
| + int64_t diff = blink_memory_stats_.partitionAllocTotalAllocatedBytes - |
| + current_blink_memory_stats.partitionAllocTotalAllocatedBytes; |
| + int64_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 - |
| + current_blink_memory_stats.blinkGCTotalAllocatedBytes; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.BlinkGCGrowth", -diff); |
| + total_diff += diff; |
| + |
| + diff = malloc_stats_.allocated_objects_size - |
| + current_malloc_stats.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 = (discardable_stats_.total_size - discardable_stats_.freelist_size) - |
| + (current_discardable_stats.total_size - |
| + current_discardable_stats.freelist_size); |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.DiscardableGrowth", -diff); |
| + total_diff += diff; |
| + |
| + diff = v8_total_heap_usage_ - v8_total_heap_usage; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.V8HeapGrowth", -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); |
| + |
| + diff = malloc_stats_.resident_size - current_malloc_stats.resident_size; |
| + if (diff > 0) |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeShrink", diff); |
| + else |
| + UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.ResidentSizeGrowth", -diff); |
| +} |
| + |
| void RenderThreadImpl::OnCreateNewFrame(FrameMsg_NewFrame_Params params) { |
| // Debug cases of https://crbug.com/626802. |
| base::debug::SetCrashKeyValue("newframe_routing_id", |