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

Side by Side Diff: chrome/browser/metrics/process_memory_metrics_emitter.cc

Issue 2876693002: Emit UMAs for metrics from memory instrumentation service. (Closed)
Patch Set: comments from ssid. Created 3 years, 7 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
(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
18 void EmitBrowserMemoryMetrics(const ProcessMemoryDumpPtr& pmd) {
19 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Browser2.Resident",
20 pmd->os_dump.resident_set_kb * 1024);
21 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Browser2.Malloc",
22 pmd->chrome_dump.malloc_total_kb * 1024);
23
24 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434.
25 }
26
27 void EmitRendererMemoryMetrics(const ProcessMemoryDumpPtr& pmd) {
28 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.Resident",
29 pmd->os_dump.resident_set_kb * 1024);
30 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.Malloc",
31 pmd->chrome_dump.malloc_total_kb * 1024);
32 UMA_HISTOGRAM_MEMORY_LARGE_MB(
33 "Memory.Experimental.Renderer2.PartitionAlloc",
34 pmd->chrome_dump.partition_alloc_total_kb * 1024);
35 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.BlinkGC",
36 pmd->chrome_dump.blink_gc_total_kb * 1024);
37 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer2.V8",
38 pmd->chrome_dump.v8_total_kb * 1024);
39
40 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434.
41 }
42
43 void EmitGpuMemoryMetrics(const ProcessMemoryDumpPtr& pmd) {
44 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Gpu2.Resident",
45 pmd->os_dump.resident_set_kb * 1024);
46 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Gpu2.Malloc",
47 pmd->chrome_dump.malloc_total_kb * 1024);
48
49 // TODO(erikchen): Emit private memory footprint. https://crbug.com/721434.
50 }
51
52 } // namespace
53
54 ProcessMemoryMetricsEmitter::ProcessMemoryMetricsEmitter() {}
55
56 void ProcessMemoryMetricsEmitter::FetchAndEmitProcessMemoryMetrics() {
57 service_manager::Connector* connector =
58 content::ServiceManagerConnection::GetForProcess()->GetConnector();
59 connector->BindInterface(content::mojom::kBrowserServiceName,
60 mojo::MakeRequest(&coordinator_));
61
62 // The callback keeps this object alive until the callback is invoked..
63 auto callback =
64 base::Bind(&ProcessMemoryMetricsEmitter::ReceivedMemoryDump, this);
65
66 base::trace_event::MemoryDumpRequestArgs args = {
67 0, base::trace_event::MemoryDumpType::SUMMARY_ONLY,
68 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND};
69 coordinator_->RequestGlobalMemoryDump(args, callback);
70 }
71
72 ProcessMemoryMetricsEmitter::~ProcessMemoryMetricsEmitter() {}
73
74 void ProcessMemoryMetricsEmitter::ReceivedMemoryDump(
75 uint64_t dump_guid,
76 bool success,
77 memory_instrumentation::mojom::GlobalMemoryDumpPtr ptr) {
78 if (!success)
79 return;
80 if (!ptr)
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698