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

Unified 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 side-by-side diff with in-line comments
Download patch
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..66369bb36876881e2201f1f752e93bd9c02b6f17 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -1736,11 +1736,108 @@ 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();
+ 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));
bashi 2016/09/22 23:28:26 (just for note; I understand this is WIP) Rather
+
// 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();
+
+ 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 -
+ stats_after.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 -
+ stats_after.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 -
+ 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 = 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;
+
+ 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 - malloc_stats_after.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",

Powered by Google App Engine
This is Rietveld 408576698