OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/metrics/process_memory_metrics_emitter.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/trace_event/memory_dump_request_args.h" |
| 9 #include "content/public/common/service_manager_connection.h" |
| 10 #include "content/public/common/service_names.mojom.h" |
| 11 #include "services/service_manager/public/cpp/connector.h" |
| 12 |
| 13 using ProcessMemoryDumpPtr = |
| 14 memory_instrumentation::mojom::ProcessMemoryDumpPtr; |
| 15 |
| 16 namespace { |
| 17 void EmitBrowserMemoryMetrics(const ProcessMemoryDumpPtr& pmd) { |
| 18 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Browser2.Resident", |
| 19 pmd->os_dump.resident_set_kb * 1024); |
| 20 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Browser2.Malloc", |
| 21 pmd->chrome_dump.malloc_total_kb * 1024); |
| 22 |
| 23 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434. |
| 24 } |
| 25 |
| 26 void EmitRendererMemoryMetrics(const ProcessMemoryDumpPtr& pmd) { |
| 27 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.Resident", |
| 28 pmd->os_dump.resident_set_kb * 1024); |
| 29 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.Malloc", |
| 30 pmd->chrome_dump.malloc_total_kb * 1024); |
| 31 UMA_HISTOGRAM_MEMORY_LARGE_MB( |
| 32 "Memory.Experimental.Renderer2.PartitionAlloc", |
| 33 pmd->chrome_dump.partition_alloc_total_kb * 1024); |
| 34 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.BlinkGC", |
| 35 pmd->chrome_dump.blink_gc_total_kb * 1024); |
| 36 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.V8", |
| 37 pmd->chrome_dump.v8_total_kb * 1024); |
| 38 |
| 39 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434. |
| 40 } |
| 41 |
| 42 void EmitGpuMemoryMetrics(const ProcessMemoryDumpPtr& pmd) { |
| 43 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Gpu2.Resident", |
| 44 pmd->os_dump.resident_set_kb * 1024); |
| 45 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Gpu2.Malloc", |
| 46 pmd->chrome_dump.malloc_total_kb * 1024); |
| 47 |
| 48 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434. |
| 49 } |
| 50 } |
| 51 |
| 52 void ProcessMemoryMetricsEmitter::FetchAndEmitProcessMemoryMetrics() { |
| 53 memory_instrumentation::mojom::CoordinatorPtr coordinator; |
| 54 service_manager::Connector* connector = |
| 55 content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 56 connector->BindInterface(content::mojom::kBrowserServiceName, |
| 57 mojo::MakeRequest(&coordinator)); |
| 58 |
| 59 // The callback keeps this object alive until the callback is invoked.. |
| 60 scoped_refptr<ProcessMemoryMetricsEmitter> emitter( |
| 61 new ProcessMemoryMetricsEmitter(std::move(coordinator))); |
| 62 auto callback = |
| 63 base::Bind(&ProcessMemoryMetricsEmitter::ReceivedMemoryDump, emitter); |
| 64 |
| 65 base::trace_event::MemoryDumpRequestArgs args = { |
| 66 0, base::trace_event::MemoryDumpType::SUMMARY_ONLY, |
| 67 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
| 68 emitter->coordinator_->RequestGlobalMemoryDump(args, callback); |
| 69 } |
| 70 |
| 71 ProcessMemoryMetricsEmitter::ProcessMemoryMetricsEmitter( |
| 72 memory_instrumentation::mojom::CoordinatorPtr coordinator) |
| 73 : coordinator_(std::move(coordinator)) {} |
| 74 ProcessMemoryMetricsEmitter::~ProcessMemoryMetricsEmitter() {} |
| 75 |
| 76 void ProcessMemoryMetricsEmitter::ReceivedMemoryDump( |
| 77 uint64_t dump_guid, |
| 78 bool success, |
| 79 memory_instrumentation::mojom::GlobalMemoryDumpPtr ptr) { |
| 80 if (!success) |
| 81 return; |
| 82 |
| 83 for (const ProcessMemoryDumpPtr& pmd : ptr->process_dumps) { |
| 84 switch (pmd->process_type) { |
| 85 case memory_instrumentation::mojom::ProcessType::BROWSER: |
| 86 EmitBrowserMemoryMetrics(pmd); |
| 87 break; |
| 88 case memory_instrumentation::mojom::ProcessType::RENDERER: |
| 89 EmitRendererMemoryMetrics(pmd); |
| 90 break; |
| 91 case memory_instrumentation::mojom::ProcessType::GPU: |
| 92 EmitGpuMemoryMetrics(pmd); |
| 93 break; |
| 94 case memory_instrumentation::mojom::ProcessType::UTILITY: |
| 95 case memory_instrumentation::mojom::ProcessType::PLUGIN: |
| 96 case memory_instrumentation::mojom::ProcessType::OTHER: |
| 97 break; |
| 98 } |
| 99 } |
| 100 } |
OLD | NEW |