Commit b67d830f authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Add Memory.*.ResidentSet histograms.

These histograms record the size of the resident memory per process type and in
total. Resident memory is influenced by factors we control (e.g. memory that is
not accessed can be swapped) and factors we don't control (e.g. an unrelated
process using a lot of memory can force memory in our process to be swapped).
Histograms are recorded once per UMA ping.

These histograms are added to answer the following question:
- Do the efforts we make to reduce the amount of memory accessed by frozen
  renderers has an impact on the size of their working set?

Bug: 885293
Change-Id: I7cb3b1b5bd4d927277f5f4c9e96455dc0ff2ef94
Reviewed-on: https://chromium-review.googlesource.com/c/1301847
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604654}
parent 9e7f34f7
...@@ -305,7 +305,12 @@ void EmitProcessUkm(const GlobalMemoryDump::ProcessDump& pmd, ...@@ -305,7 +305,12 @@ void EmitProcessUkm(const GlobalMemoryDump::ProcessDump& pmd,
} }
} }
} }
#if !defined(OS_MACOSX)
// Resident set is not populated on Mac.
builder->SetResident(pmd.os_dump().resident_set_kb / 1024); builder->SetResident(pmd.os_dump().resident_set_kb / 1024);
#endif
builder->SetPrivateMemoryFootprint(pmd.os_dump().private_footprint_kb / 1024); builder->SetPrivateMemoryFootprint(pmd.os_dump().private_footprint_kb / 1024);
builder->SetSharedMemoryFootprint(pmd.os_dump().shared_footprint_kb / 1024); builder->SetSharedMemoryFootprint(pmd.os_dump().shared_footprint_kb / 1024);
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
...@@ -317,6 +322,14 @@ void EmitProcessUkm(const GlobalMemoryDump::ProcessDump& pmd, ...@@ -317,6 +322,14 @@ void EmitProcessUkm(const GlobalMemoryDump::ProcessDump& pmd,
if (!record_uma) if (!record_uma)
return; return;
#if defined(OS_MACOSX)
// Resident set is not populated on Mac.
DCHECK_EQ(pmd.os_dump().resident_set_kb, 0U);
#else
MEMORY_METRICS_HISTOGRAM_MB(
std::string(UMA_PREFIX) + process_name + ".ResidentSet",
pmd.os_dump().resident_set_kb / 1024);
#endif
MEMORY_METRICS_HISTOGRAM_MB( MEMORY_METRICS_HISTOGRAM_MB(
std::string(UMA_PREFIX) + process_name + ".PrivateMemoryFootprint", std::string(UMA_PREFIX) + process_name + ".PrivateMemoryFootprint",
pmd.os_dump().private_footprint_kb / 1024); pmd.os_dump().private_footprint_kb / 1024);
...@@ -545,6 +558,7 @@ void ProcessMemoryMetricsEmitter::CollateResults() { ...@@ -545,6 +558,7 @@ void ProcessMemoryMetricsEmitter::CollateResults() {
uint32_t private_footprint_total_kb = 0; uint32_t private_footprint_total_kb = 0;
uint32_t renderer_private_footprint_total_kb = 0; uint32_t renderer_private_footprint_total_kb = 0;
uint32_t shared_footprint_total_kb = 0; uint32_t shared_footprint_total_kb = 0;
uint32_t resident_set_total_kb = 0;
bool emit_metrics_for_all_processes = pid_scope_ == base::kNullProcessId; bool emit_metrics_for_all_processes = pid_scope_ == base::kNullProcessId;
TabFootprintAggregator per_tab_metrics; TabFootprintAggregator per_tab_metrics;
...@@ -554,6 +568,7 @@ void ProcessMemoryMetricsEmitter::CollateResults() { ...@@ -554,6 +568,7 @@ void ProcessMemoryMetricsEmitter::CollateResults() {
uint32_t process_pmf_kb = pmd.os_dump().private_footprint_kb; uint32_t process_pmf_kb = pmd.os_dump().private_footprint_kb;
private_footprint_total_kb += process_pmf_kb; private_footprint_total_kb += process_pmf_kb;
shared_footprint_total_kb += pmd.os_dump().shared_footprint_kb; shared_footprint_total_kb += pmd.os_dump().shared_footprint_kb;
resident_set_total_kb += pmd.os_dump().resident_set_kb;
if (!emit_metrics_for_all_processes && pid_scope_ != pmd.pid()) if (!emit_metrics_for_all_processes && pid_scope_ != pmd.pid())
continue; continue;
...@@ -636,6 +651,14 @@ void ProcessMemoryMetricsEmitter::CollateResults() { ...@@ -636,6 +651,14 @@ void ProcessMemoryMetricsEmitter::CollateResults() {
UMA_HISTOGRAM_MEMORY_LARGE_MB( UMA_HISTOGRAM_MEMORY_LARGE_MB(
"Memory.Experimental.Total2.PrivateMemoryFootprint", "Memory.Experimental.Total2.PrivateMemoryFootprint",
private_footprint_total_kb / 1024); private_footprint_total_kb / 1024);
#if defined(OS_MACOSX)
// Resident set is not populated on Mac.
DCHECK_EQ(resident_set_total_kb, 0U);
#else
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total.ResidentSet",
resident_set_total_kb / 1024);
#endif
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total.PrivateMemoryFootprint", UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total.PrivateMemoryFootprint",
private_footprint_total_kb / 1024); private_footprint_total_kb / 1024);
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total.RendererPrivateMemoryFootprint", UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total.RendererPrivateMemoryFootprint",
......
...@@ -145,7 +145,7 @@ void CheckMemoryMetric(const std::string& name, ...@@ -145,7 +145,7 @@ void CheckMemoryMetric(const std::string& name,
EXPECT_EQ(samples->TotalCount(), count * number_of_processes) << name; EXPECT_EQ(samples->TotalCount(), count * number_of_processes) << name;
} }
if (value_restriction == ValueRestriction::ABOVE_ZERO) if (count != 0 && value_restriction == ValueRestriction::ABOVE_ZERO)
EXPECT_GT(samples->sum(), 0u) << name; EXPECT_GT(samples->sum(), 0u) << name;
// As a sanity check, no memory stat should exceed 4 GB. // As a sanity check, no memory stat should exceed 4 GB.
...@@ -153,10 +153,11 @@ void CheckMemoryMetric(const std::string& name, ...@@ -153,10 +153,11 @@ void CheckMemoryMetric(const std::string& name,
EXPECT_LT(samples->sum(), maximum_expected_size) << name; EXPECT_LT(samples->sum(), maximum_expected_size) << name;
} }
void CheckAllMemoryMetrics(const base::HistogramTester& histogram_tester, void CheckExperimentalMemoryMetrics(
int count, const base::HistogramTester& histogram_tester,
int number_of_renderer_processes = 1u, int count,
int number_of_extenstion_processes = 0u) { int number_of_renderer_processes,
int number_of_extension_processes) {
#if !defined(OS_WIN) #if !defined(OS_WIN)
CheckMemoryMetric("Memory.Experimental.Browser2.Malloc", histogram_tester, CheckMemoryMetric("Memory.Experimental.Browser2.Malloc", histogram_tester,
count, ValueRestriction::ABOVE_ZERO); count, ValueRestriction::ABOVE_ZERO);
...@@ -177,26 +178,98 @@ void CheckAllMemoryMetrics(const base::HistogramTester& histogram_tester, ...@@ -177,26 +178,98 @@ void CheckAllMemoryMetrics(const base::HistogramTester& histogram_tester,
count, ValueRestriction::ABOVE_ZERO, count, ValueRestriction::ABOVE_ZERO,
number_of_renderer_processes); number_of_renderer_processes);
} }
if (number_of_extenstion_processes) { if (number_of_extension_processes) {
#if !defined(OS_WIN) #if !defined(OS_WIN)
CheckMemoryMetric("Memory.Experimental.Extension2.Malloc", histogram_tester, CheckMemoryMetric("Memory.Experimental.Extension2.Malloc", histogram_tester,
count, ValueRestriction::ABOVE_ZERO, count, ValueRestriction::ABOVE_ZERO,
number_of_extenstion_processes); number_of_extension_processes);
#endif #endif
CheckMemoryMetric("Memory.Experimental.Extension2.BlinkGC", CheckMemoryMetric("Memory.Experimental.Extension2.BlinkGC",
histogram_tester, count, ValueRestriction::NONE, histogram_tester, count, ValueRestriction::NONE,
number_of_extenstion_processes); number_of_extension_processes);
CheckMemoryMetric("Memory.Experimental.Extension2.PartitionAlloc", CheckMemoryMetric("Memory.Experimental.Extension2.PartitionAlloc",
histogram_tester, count, ValueRestriction::NONE, histogram_tester, count, ValueRestriction::NONE,
number_of_extenstion_processes); number_of_extension_processes);
CheckMemoryMetric("Memory.Experimental.Extension2.V8", histogram_tester, CheckMemoryMetric("Memory.Experimental.Extension2.V8", histogram_tester,
count, ValueRestriction::ABOVE_ZERO, count, ValueRestriction::ABOVE_ZERO,
number_of_extenstion_processes); number_of_extension_processes);
} }
CheckMemoryMetric("Memory.Experimental.Total2.PrivateMemoryFootprint", CheckMemoryMetric("Memory.Experimental.Total2.PrivateMemoryFootprint",
histogram_tester, count, ValueRestriction::ABOVE_ZERO); histogram_tester, count, ValueRestriction::ABOVE_ZERO);
} }
void CheckStableMemoryMetrics(const base::HistogramTester& histogram_tester,
int count,
int number_of_renderer_processes,
int number_of_extension_processes) {
const int count_for_resident_set =
#if defined(OS_MACOSX)
0;
#else
count;
#endif
const int count_for_private_swap_footprint =
#if defined(OS_LINUX) || defined(OS_ANDROID)
count;
#else
0;
#endif
if (number_of_renderer_processes) {
CheckMemoryMetric("Memory.Renderer.ResidentSet", histogram_tester,
count_for_resident_set, ValueRestriction::ABOVE_ZERO,
number_of_renderer_processes);
CheckMemoryMetric("Memory.Renderer.PrivateMemoryFootprint",
histogram_tester, count, ValueRestriction::ABOVE_ZERO,
number_of_renderer_processes);
// Shared memory footprint can be below 1 MB, which is reported as zero.
CheckMemoryMetric("Memory.Renderer.SharedMemoryFootprint", histogram_tester,
count, ValueRestriction::NONE,
number_of_renderer_processes);
CheckMemoryMetric("Memory.Renderer.PrivateSwapFootprint", histogram_tester,
count_for_private_swap_footprint, ValueRestriction::NONE,
number_of_renderer_processes);
}
if (number_of_extension_processes) {
CheckMemoryMetric("Memory.Extension.ResidentSet", histogram_tester,
count_for_resident_set, ValueRestriction::ABOVE_ZERO,
number_of_extension_processes);
CheckMemoryMetric("Memory.Extension.PrivateMemoryFootprint",
histogram_tester, count, ValueRestriction::ABOVE_ZERO,
number_of_extension_processes);
// Shared memory footprint can be below 1 MB, which is reported as zero.
CheckMemoryMetric("Memory.Extension.SharedMemoryFootprint",
histogram_tester, count, ValueRestriction::NONE,
number_of_extension_processes);
CheckMemoryMetric("Memory.Extension.PrivateSwapFootprint", histogram_tester,
count_for_private_swap_footprint, ValueRestriction::NONE,
number_of_extension_processes);
}
CheckMemoryMetric("Memory.Total.ResidentSet", histogram_tester,
count_for_resident_set, ValueRestriction::ABOVE_ZERO);
CheckMemoryMetric("Memory.Total.PrivateMemoryFootprint", histogram_tester,
count, ValueRestriction::ABOVE_ZERO);
CheckMemoryMetric("Memory.Total.RendererPrivateMemoryFootprint",
histogram_tester, count, ValueRestriction::ABOVE_ZERO);
// Shared memory footprint can be below 1 MB, which is reported as zero.
CheckMemoryMetric("Memory.Total.SharedMemoryFootprint", histogram_tester,
count, ValueRestriction::NONE);
}
void CheckAllMemoryMetrics(const base::HistogramTester& histogram_tester,
int count,
int number_of_renderer_processes = 1u,
int number_of_extension_processes = 0u) {
CheckExperimentalMemoryMetrics(histogram_tester, count,
number_of_renderer_processes,
number_of_extension_processes);
CheckStableMemoryMetrics(histogram_tester, count,
number_of_renderer_processes,
number_of_extension_processes);
}
} // namespace } // namespace
class ProcessMemoryMetricsEmitterTest class ProcessMemoryMetricsEmitterTest
......
// Copyright 2017 The Chromium Authors. All rights reserved. // Copyright kTestRendererPid2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -30,6 +30,19 @@ namespace { ...@@ -30,6 +30,19 @@ namespace {
using UkmEntry = ukm::builders::Memory_Experimental; using UkmEntry = ukm::builders::Memory_Experimental;
using MetricMap = base::flat_map<const char*, int64_t>;
int GetResidentValue(const MetricMap& metric_map) {
#if defined(OS_MACOSX)
// Resident set is not populated on Mac.
return 0;
#else
auto it = metric_map.find("Resident");
EXPECT_NE(it, metric_map.end());
return it->second;
#endif
}
// Provide fake to surface ReceivedMemoryDump and ReceivedProcessInfos to public // Provide fake to surface ReceivedMemoryDump and ReceivedProcessInfos to public
// visibility. // visibility.
class ProcessMemoryMetricsEmitterFake : public ProcessMemoryMetricsEmitter { class ProcessMemoryMetricsEmitterFake : public ProcessMemoryMetricsEmitter {
...@@ -96,34 +109,32 @@ void SetAllocatorDumpMetric(ProcessMemoryDumpPtr& pmd, ...@@ -96,34 +109,32 @@ void SetAllocatorDumpMetric(ProcessMemoryDumpPtr& pmd,
OSMemDumpPtr GetFakeOSMemDump(uint32_t resident_set_kb, OSMemDumpPtr GetFakeOSMemDump(uint32_t resident_set_kb,
uint32_t private_footprint_kb, uint32_t private_footprint_kb,
uint32_t shared_footprint_kb
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
uint32_t shared_footprint_kb, ,
uint32_t private_swap_footprint_kb uint32_t private_swap_footprint_kb
#else
uint32_t shared_footprint_kb
#endif #endif
) { ) {
using memory_instrumentation::mojom::VmRegion; using memory_instrumentation::mojom::VmRegion;
#if defined(OS_LINUX) || defined(OS_ANDROID)
return memory_instrumentation::mojom::OSMemDump::New( return memory_instrumentation::mojom::OSMemDump::New(
resident_set_kb, private_footprint_kb, shared_footprint_kb, resident_set_kb, private_footprint_kb, shared_footprint_kb
private_swap_footprint_kb); #if defined(OS_LINUX) || defined(OS_ANDROID)
#else ,
return memory_instrumentation::mojom::OSMemDump::New( private_swap_footprint_kb
resident_set_kb, private_footprint_kb, shared_footprint_kb);
#endif #endif
);
} }
void PopulateBrowserMetrics(GlobalMemoryDumpPtr& global_dump, void PopulateBrowserMetrics(GlobalMemoryDumpPtr& global_dump,
base::flat_map<const char*, int64_t>& metrics_mb) { MetricMap& metrics_mb) {
ProcessMemoryDumpPtr pmd( ProcessMemoryDumpPtr pmd(
memory_instrumentation::mojom::ProcessMemoryDump::New()); memory_instrumentation::mojom::ProcessMemoryDump::New());
pmd->process_type = ProcessType::BROWSER; pmd->process_type = ProcessType::BROWSER;
SetAllocatorDumpMetric(pmd, "malloc", "effective_size", SetAllocatorDumpMetric(pmd, "malloc", "effective_size",
metrics_mb["Malloc"] * 1024 * 1024); metrics_mb["Malloc"] * 1024 * 1024);
OSMemDumpPtr os_dump = OSMemDumpPtr os_dump =
GetFakeOSMemDump(metrics_mb["Resident"] * 1024, GetFakeOSMemDump(GetResidentValue(metrics_mb) * 1024,
metrics_mb["PrivateMemoryFootprint"] * 1024, metrics_mb["PrivateMemoryFootprint"] * 1024,
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
// accessing PrivateSwapFootprint on other OSes will // accessing PrivateSwapFootprint on other OSes will
...@@ -139,14 +150,15 @@ void PopulateBrowserMetrics(GlobalMemoryDumpPtr& global_dump, ...@@ -139,14 +150,15 @@ void PopulateBrowserMetrics(GlobalMemoryDumpPtr& global_dump,
global_dump->process_dumps.push_back(std::move(pmd)); global_dump->process_dumps.push_back(std::move(pmd));
} }
base::flat_map<const char*, int64_t> GetExpectedBrowserMetrics() { MetricMap GetExpectedBrowserMetrics() {
return base::flat_map<const char*, int64_t>( return MetricMap(
{ {
{"ProcessType", static_cast<int64_t>(ProcessType::BROWSER)}, {"ProcessType", static_cast<int64_t>(ProcessType::BROWSER)},
#if !defined(OS_MACOSX)
{"Resident", 10}, {"Resident", 10},
{"Malloc", 20}, #endif
{"PrivateMemoryFootprint", 30}, {"SharedMemoryFootprint", 35}, {"Malloc", 20}, {"PrivateMemoryFootprint", 30},
{"Uptime", 42}, {"SharedMemoryFootprint", 35}, {"Uptime", 42},
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
{"PrivateSwapFootprint", 50}, {"PrivateSwapFootprint", 50},
#endif #endif
...@@ -154,10 +166,9 @@ base::flat_map<const char*, int64_t> GetExpectedBrowserMetrics() { ...@@ -154,10 +166,9 @@ base::flat_map<const char*, int64_t> GetExpectedBrowserMetrics() {
base::KEEP_FIRST_OF_DUPES); base::KEEP_FIRST_OF_DUPES);
} }
void PopulateRendererMetrics( void PopulateRendererMetrics(GlobalMemoryDumpPtr& global_dump,
GlobalMemoryDumpPtr& global_dump, MetricMap& metrics_mb_or_count,
base::flat_map<const char*, int64_t>& metrics_mb_or_count, base::ProcessId pid) {
base::ProcessId pid) {
ProcessMemoryDumpPtr pmd( ProcessMemoryDumpPtr pmd(
memory_instrumentation::mojom::ProcessMemoryDump::New()); memory_instrumentation::mojom::ProcessMemoryDump::New());
pmd->process_type = ProcessType::RENDERER; pmd->process_type = ProcessType::RENDERER;
...@@ -269,7 +280,7 @@ void PopulateRendererMetrics( ...@@ -269,7 +280,7 @@ void PopulateRendererMetrics(
1024); 1024);
OSMemDumpPtr os_dump = GetFakeOSMemDump( OSMemDumpPtr os_dump = GetFakeOSMemDump(
metrics_mb_or_count["Resident"] * 1024, GetResidentValue(metrics_mb_or_count) * 1024,
metrics_mb_or_count["PrivateMemoryFootprint"] * 1024, metrics_mb_or_count["PrivateMemoryFootprint"] * 1024,
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
// accessing PrivateSwapFootprint on other OSes will // accessing PrivateSwapFootprint on other OSes will
...@@ -286,15 +297,31 @@ void PopulateRendererMetrics( ...@@ -286,15 +297,31 @@ void PopulateRendererMetrics(
global_dump->process_dumps.push_back(std::move(pmd)); global_dump->process_dumps.push_back(std::move(pmd));
} }
base::flat_map<const char*, int64_t> GetExpectedRendererMetrics() { constexpr int kTestRendererPrivateMemoryFootprint = 130;
return base::flat_map<const char*, int64_t>( constexpr int kTestRendererSharedMemoryFootprint = 135;
#if !defined(OS_MACOSX)
constexpr int kTestRendererResidentSet = 110;
#endif
constexpr base::ProcessId kTestRendererPid201 = 201;
constexpr base::ProcessId kTestRendererPid202 = 202;
constexpr base::ProcessId kTestRendererPid203 = 203;
MetricMap GetExpectedRendererMetrics() {
return MetricMap(
{ {
{"ProcessType", static_cast<int64_t>(ProcessType::RENDERER)}, {"ProcessType", static_cast<int64_t>(ProcessType::RENDERER)},
{"Resident", 110}, {"Malloc", 120}, {"PrivateMemoryFootprint", 130}, #if !defined(OS_MACOSX)
{"SharedMemoryFootprint", 135}, {"PartitionAlloc", 140}, {"Resident", kTestRendererResidentSet},
{"BlinkGC", 150}, {"V8", 160}, {"V8.AllocatedObjects", 70}, #endif
{"V8.Main", 100}, {"V8.Main.AllocatedObjects", 30}, {"Malloc", 120},
{"V8.Main.Heap", 98}, {"V8.Main.Heap.AllocatedObjects", 28}, {"PrivateMemoryFootprint", kTestRendererPrivateMemoryFootprint},
{"SharedMemoryFootprint", kTestRendererSharedMemoryFootprint},
{"PartitionAlloc", 140}, {"BlinkGC", 150}, {"V8", 160},
{"V8.AllocatedObjects", 70}, {"V8.Main", 100},
{"V8.Main.AllocatedObjects", 30}, {"V8.Main.Heap", 98},
{"V8.Main.Heap.AllocatedObjects", 28},
{"V8.Main.Heap.CodeSpace", 11}, {"V8.Main.Heap.CodeSpace", 11},
{"V8.Main.Heap.CodeSpace.AllocatedObjects", 1}, {"V8.Main.Heap.CodeSpace.AllocatedObjects", 1},
{"V8.Main.Heap.LargeObjectSpace", 12}, {"V8.Main.Heap.LargeObjectSpace", 12},
...@@ -323,14 +350,14 @@ base::flat_map<const char*, int64_t> GetExpectedRendererMetrics() { ...@@ -323,14 +350,14 @@ base::flat_map<const char*, int64_t> GetExpectedRendererMetrics() {
base::KEEP_FIRST_OF_DUPES); base::KEEP_FIRST_OF_DUPES);
} }
void AddPageMetrics(base::flat_map<const char*, int64_t>& expected_metrics) { void AddPageMetrics(MetricMap& expected_metrics) {
expected_metrics["IsVisible"] = true; expected_metrics["IsVisible"] = true;
expected_metrics["TimeSinceLastNavigation"] = 20; expected_metrics["TimeSinceLastNavigation"] = 20;
expected_metrics["TimeSinceLastVisibilityChange"] = 15; expected_metrics["TimeSinceLastVisibilityChange"] = 15;
} }
void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump, void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump,
base::flat_map<const char*, int64_t>& metrics_mb) { MetricMap& metrics_mb) {
ProcessMemoryDumpPtr pmd( ProcessMemoryDumpPtr pmd(
memory_instrumentation::mojom::ProcessMemoryDump::New()); memory_instrumentation::mojom::ProcessMemoryDump::New());
pmd->process_type = ProcessType::GPU; pmd->process_type = ProcessType::GPU;
...@@ -339,7 +366,7 @@ void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump, ...@@ -339,7 +366,7 @@ void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump,
SetAllocatorDumpMetric(pmd, "gpu/gl", "effective_size", SetAllocatorDumpMetric(pmd, "gpu/gl", "effective_size",
metrics_mb["CommandBuffer"] * 1024 * 1024); metrics_mb["CommandBuffer"] * 1024 * 1024);
OSMemDumpPtr os_dump = OSMemDumpPtr os_dump =
GetFakeOSMemDump(metrics_mb["Resident"] * 1024, GetFakeOSMemDump(GetResidentValue(metrics_mb) * 1024,
metrics_mb["PrivateMemoryFootprint"] * 1024, metrics_mb["PrivateMemoryFootprint"] * 1024,
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
// accessing PrivateSwapFootprint on other OSes will // accessing PrivateSwapFootprint on other OSes will
...@@ -355,14 +382,16 @@ void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump, ...@@ -355,14 +382,16 @@ void PopulateGpuMetrics(GlobalMemoryDumpPtr& global_dump,
global_dump->process_dumps.push_back(std::move(pmd)); global_dump->process_dumps.push_back(std::move(pmd));
} }
base::flat_map<const char*, int64_t> GetExpectedGpuMetrics() { MetricMap GetExpectedGpuMetrics() {
return base::flat_map<const char*, int64_t>( return MetricMap(
{ {
{"ProcessType", static_cast<int64_t>(ProcessType::GPU)}, {"ProcessType", static_cast<int64_t>(ProcessType::GPU)},
#if !defined(OS_MACOSX)
{"Resident", 210}, {"Resident", 210},
{"Malloc", 220}, #endif
{"PrivateMemoryFootprint", 230}, {"SharedMemoryFootprint", 235}, {"Malloc", 220}, {"PrivateMemoryFootprint", 230},
{"CommandBuffer", 240}, {"Uptime", 42}, {"SharedMemoryFootprint", 235}, {"CommandBuffer", 240},
{"Uptime", 42},
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
{"PrivateSwapFootprint", 50}, {"PrivateSwapFootprint", 50},
#endif #endif
...@@ -370,16 +399,15 @@ base::flat_map<const char*, int64_t> GetExpectedGpuMetrics() { ...@@ -370,16 +399,15 @@ base::flat_map<const char*, int64_t> GetExpectedGpuMetrics() {
base::KEEP_FIRST_OF_DUPES); base::KEEP_FIRST_OF_DUPES);
} }
void PopulateAudioServiceMetrics( void PopulateAudioServiceMetrics(GlobalMemoryDumpPtr& global_dump,
GlobalMemoryDumpPtr& global_dump, MetricMap& metrics_mb) {
base::flat_map<const char*, int64_t>& metrics_mb) {
ProcessMemoryDumpPtr pmd( ProcessMemoryDumpPtr pmd(
memory_instrumentation::mojom::ProcessMemoryDump::New()); memory_instrumentation::mojom::ProcessMemoryDump::New());
pmd->process_type = ProcessType::UTILITY; pmd->process_type = ProcessType::UTILITY;
SetAllocatorDumpMetric(pmd, "malloc", "effective_size", SetAllocatorDumpMetric(pmd, "malloc", "effective_size",
metrics_mb["Malloc"] * 1024 * 1024); metrics_mb["Malloc"] * 1024 * 1024);
OSMemDumpPtr os_dump = OSMemDumpPtr os_dump =
GetFakeOSMemDump(metrics_mb["Resident"] * 1024, GetFakeOSMemDump(GetResidentValue(metrics_mb) * 1024,
metrics_mb["PrivateMemoryFootprint"] * 1024, metrics_mb["PrivateMemoryFootprint"] * 1024,
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
// accessing PrivateSwapFootprint on other OSes will // accessing PrivateSwapFootprint on other OSes will
...@@ -395,11 +423,14 @@ void PopulateAudioServiceMetrics( ...@@ -395,11 +423,14 @@ void PopulateAudioServiceMetrics(
global_dump->process_dumps.push_back(std::move(pmd)); global_dump->process_dumps.push_back(std::move(pmd));
} }
base::flat_map<const char*, int64_t> GetExpectedAudioServiceMetrics() { MetricMap GetExpectedAudioServiceMetrics() {
return base::flat_map<const char*, int64_t>( return MetricMap(
{ {
{"ProcessType", static_cast<int64_t>(ProcessType::UTILITY)}, {"ProcessType", static_cast<int64_t>(ProcessType::UTILITY)},
{"Resident", 10}, {"Malloc", 20}, {"PrivateMemoryFootprint", 30}, #if !defined(OS_MACOSX)
{"Resident", 10},
#endif
{"Malloc", 20}, {"PrivateMemoryFootprint", 30},
{"SharedMemoryFootprint", 35}, {"Uptime", 42}, {"SharedMemoryFootprint", 35}, {"Uptime", 42},
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
{"PrivateSwapFootprint", 50}, {"PrivateSwapFootprint", 50},
...@@ -410,7 +441,7 @@ base::flat_map<const char*, int64_t> GetExpectedAudioServiceMetrics() { ...@@ -410,7 +441,7 @@ base::flat_map<const char*, int64_t> GetExpectedAudioServiceMetrics() {
void PopulateMetrics(GlobalMemoryDumpPtr& global_dump, void PopulateMetrics(GlobalMemoryDumpPtr& global_dump,
ProcessType ptype, ProcessType ptype,
base::flat_map<const char*, int64_t>& metrics_mb) { MetricMap& metrics_mb) {
switch (ptype) { switch (ptype) {
case ProcessType::BROWSER: case ProcessType::BROWSER:
PopulateBrowserMetrics(global_dump, metrics_mb); PopulateBrowserMetrics(global_dump, metrics_mb);
...@@ -434,8 +465,7 @@ void PopulateMetrics(GlobalMemoryDumpPtr& global_dump, ...@@ -434,8 +465,7 @@ void PopulateMetrics(GlobalMemoryDumpPtr& global_dump,
FAIL() << "Unknown process type case " << ptype << "."; FAIL() << "Unknown process type case " << ptype << ".";
} }
base::flat_map<const char*, int64_t> GetExpectedProcessMetrics( MetricMap GetExpectedProcessMetrics(ProcessType ptype) {
ProcessType ptype) {
switch (ptype) { switch (ptype) {
case ProcessType::BROWSER: case ProcessType::BROWSER:
return GetExpectedBrowserMetrics(); return GetExpectedBrowserMetrics();
...@@ -453,7 +483,7 @@ base::flat_map<const char*, int64_t> GetExpectedProcessMetrics( ...@@ -453,7 +483,7 @@ base::flat_map<const char*, int64_t> GetExpectedProcessMetrics(
// We shouldn't reach here. // We shouldn't reach here.
CHECK(false); CHECK(false);
return base::flat_map<const char*, int64_t>(); return MetricMap();
} }
ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) { ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) {
...@@ -467,11 +497,11 @@ ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) { ...@@ -467,11 +497,11 @@ ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) {
process_infos.push_back(std::move(process_info)); process_infos.push_back(std::move(process_info));
} }
// Process 201 always has 1 URL // Process kTestRendererPid201 always has 1 URL
{ {
ProcessInfoPtr process_info( ProcessInfoPtr process_info(
resource_coordinator::mojom::ProcessInfo::New()); resource_coordinator::mojom::ProcessInfo::New());
process_info->pid = 201; process_info->pid = kTestRendererPid201;
ukm::SourceId first_source_id = ukm::UkmRecorder::GetNewSourceID(); ukm::SourceId first_source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(first_source_id, ukm_recorder.UpdateSourceURL(first_source_id,
GURL("http://www.url201.com/")); GURL("http://www.url201.com/"));
...@@ -488,11 +518,11 @@ ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) { ...@@ -488,11 +518,11 @@ ProcessInfoVector GetProcessInfo(ukm::TestUkmRecorder& ukm_recorder) {
process_infos.push_back(std::move(process_info)); process_infos.push_back(std::move(process_info));
} }
// Process 202 always has 2 URL // Process kTestRendererPid202 always has 2 URL
{ {
ProcessInfoPtr process_info( ProcessInfoPtr process_info(
resource_coordinator::mojom::ProcessInfo::New()); resource_coordinator::mojom::ProcessInfo::New());
process_info->pid = 202; process_info->pid = kTestRendererPid202;
ukm::SourceId first_source_id = ukm::UkmRecorder::GetNewSourceID(); ukm::SourceId first_source_id = ukm::UkmRecorder::GetNewSourceID();
ukm::SourceId second_source_id = ukm::UkmRecorder::GetNewSourceID(); ukm::SourceId second_source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(first_source_id, ukm_recorder.UpdateSourceURL(first_source_id,
...@@ -530,9 +560,8 @@ class ProcessMemoryMetricsEmitterTest ...@@ -530,9 +560,8 @@ class ProcessMemoryMetricsEmitterTest
~ProcessMemoryMetricsEmitterTest() override {} ~ProcessMemoryMetricsEmitterTest() override {}
protected: protected:
void CheckMemoryUkmEntryMetrics( void CheckMemoryUkmEntryMetrics(const std::vector<MetricMap>& expected,
const std::vector<base::flat_map<const char*, int64_t>>& expected, size_t expected_total_memory_entries = 1u) {
size_t expected_total_memory_entries = 1u) {
const auto& entries = const auto& entries =
test_ukm_recorder_.GetEntriesByName(UkmEntry::kEntryName); test_ukm_recorder_.GetEntriesByName(UkmEntry::kEntryName);
size_t i = 0; size_t i = 0;
...@@ -564,8 +593,7 @@ class ProcessMemoryMetricsEmitterTest ...@@ -564,8 +593,7 @@ class ProcessMemoryMetricsEmitterTest
}; };
TEST_P(ProcessMemoryMetricsEmitterTest, CollectsSingleProcessUKMs) { TEST_P(ProcessMemoryMetricsEmitterTest, CollectsSingleProcessUKMs) {
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedProcessMetrics(GetParam());
GetExpectedProcessMetrics(GetParam());
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
...@@ -577,7 +605,7 @@ TEST_P(ProcessMemoryMetricsEmitterTest, CollectsSingleProcessUKMs) { ...@@ -577,7 +605,7 @@ TEST_P(ProcessMemoryMetricsEmitterTest, CollectsSingleProcessUKMs) {
emitter->ReceivedMemoryDump( emitter->ReceivedMemoryDump(
true, GlobalMemoryDump::MoveFrom(std::move(global_dump))); true, GlobalMemoryDump::MoveFrom(std::move(global_dump)));
std::vector<base::flat_map<const char*, int64_t>> expected_entries; std::vector<MetricMap> expected_entries;
expected_entries.push_back(expected_metrics); expected_entries.push_back(expected_metrics);
CheckMemoryUkmEntryMetrics(expected_entries); CheckMemoryUkmEntryMetrics(expected_entries);
} }
...@@ -590,8 +618,7 @@ INSTANTIATE_TEST_CASE_P(SinglePtype, ...@@ -590,8 +618,7 @@ INSTANTIATE_TEST_CASE_P(SinglePtype,
ProcessType::UTILITY)); ProcessType::UTILITY));
TEST_F(ProcessMemoryMetricsEmitterTest, CollectsExtensionProcessUKMs) { TEST_F(ProcessMemoryMetricsEmitterTest, CollectsExtensionProcessUKMs) {
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics();
expected_metrics["NumberOfExtensions"] = 1; expected_metrics["NumberOfExtensions"] = 1;
expected_metrics["Uptime"] = 21; expected_metrics["Uptime"] = 21;
...@@ -605,7 +632,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsExtensionProcessUKMs) { ...@@ -605,7 +632,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsExtensionProcessUKMs) {
emitter->ReceivedMemoryDump( emitter->ReceivedMemoryDump(
true, GlobalMemoryDump::MoveFrom(std::move(global_dump))); true, GlobalMemoryDump::MoveFrom(std::move(global_dump)));
std::vector<base::flat_map<const char*, int64_t>> expected_entries; std::vector<MetricMap> expected_entries;
expected_entries.push_back(expected_metrics); expected_entries.push_back(expected_metrics);
CheckMemoryUkmEntryMetrics(expected_entries); CheckMemoryUkmEntryMetrics(expected_entries);
} }
...@@ -619,7 +646,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsSingleDump) { ...@@ -619,7 +646,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsSingleDump) {
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
std::vector<base::flat_map<const char*, int64_t>> entries_metrics; std::vector<MetricMap> entries_metrics;
for (const auto& ptype : entries_ptypes) { for (const auto& ptype : entries_ptypes) {
auto expected_metrics = GetExpectedProcessMetrics(ptype); auto expected_metrics = GetExpectedProcessMetrics(ptype);
PopulateMetrics(global_dump, ptype, expected_metrics); PopulateMetrics(global_dump, ptype, expected_metrics);
...@@ -643,7 +670,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsManyDumps) { ...@@ -643,7 +670,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsManyDumps) {
ProcessType::BROWSER}, ProcessType::BROWSER},
}; };
std::vector<base::flat_map<const char*, int64_t>> entries_metrics; std::vector<MetricMap> entries_metrics;
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter( scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter(
new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_)); new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_));
...@@ -666,10 +693,9 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsManyDumps) { ...@@ -666,10 +693,9 @@ TEST_F(ProcessMemoryMetricsEmitterTest, CollectsManyProcessUKMsManyDumps) {
TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) { TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) {
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics();
AddPageMetrics(expected_metrics); AddPageMetrics(expected_metrics);
PopulateRendererMetrics(global_dump, expected_metrics, 201); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid201);
scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter( scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter(
new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_)); new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_));
...@@ -691,7 +717,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) { ...@@ -691,7 +717,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) {
} }
EXPECT_EQ(1, total_memory_entries); EXPECT_EQ(1, total_memory_entries);
std::vector<base::flat_map<const char*, int64_t>> expected_entries; std::vector<MetricMap> expected_entries;
expected_entries.push_back(expected_metrics); expected_entries.push_back(expected_metrics);
CheckMemoryUkmEntryMetrics(expected_entries); CheckMemoryUkmEntryMetrics(expected_entries);
} }
...@@ -699,10 +725,9 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) { ...@@ -699,10 +725,9 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoFirst) {
TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) { TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) {
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics();
AddPageMetrics(expected_metrics); AddPageMetrics(expected_metrics);
PopulateRendererMetrics(global_dump, expected_metrics, 201); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid201);
scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter( scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter(
new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_)); new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_));
...@@ -724,7 +749,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) { ...@@ -724,7 +749,7 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) {
} }
EXPECT_EQ(1, total_memory_entries); EXPECT_EQ(1, total_memory_entries);
std::vector<base::flat_map<const char*, int64_t>> expected_entries; std::vector<MetricMap> expected_entries;
expected_entries.push_back(expected_metrics); expected_entries.push_back(expected_metrics);
CheckMemoryUkmEntryMetrics(expected_entries); CheckMemoryUkmEntryMetrics(expected_entries);
} }
...@@ -732,11 +757,10 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) { ...@@ -732,11 +757,10 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ReceiveProcessInfoSecond) {
TEST_F(ProcessMemoryMetricsEmitterTest, ProcessInfoHasTwoURLs) { TEST_F(ProcessMemoryMetricsEmitterTest, ProcessInfoHasTwoURLs) {
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics(); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid201);
PopulateRendererMetrics(global_dump, expected_metrics, 200); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid202);
PopulateRendererMetrics(global_dump, expected_metrics, 201); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid203);
PopulateRendererMetrics(global_dump, expected_metrics, 202);
scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter( scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter(
new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_)); new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_));
...@@ -765,41 +789,65 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ProcessInfoHasTwoURLs) { ...@@ -765,41 +789,65 @@ TEST_F(ProcessMemoryMetricsEmitterTest, ProcessInfoHasTwoURLs) {
EXPECT_EQ(1, entries_with_urls); EXPECT_EQ(1, entries_with_urls);
} }
TEST_F(ProcessMemoryMetricsEmitterTest, TEST_F(ProcessMemoryMetricsEmitterTest, RendererAndTotalHistogramsAreRecorded) {
CheckForRendererPrivateMemoryFootprint) { // Take a snapshot of the current state of the histograms.
base::HistogramTester histograms;
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics(); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid201);
PopulateRendererMetrics(global_dump, expected_metrics, 201); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid202);
// Take a snapshot of the current state of the histograms. // No histograms should have been recorded yet.
base::HistogramTester sentinel; histograms.ExpectTotalCount("Memory.Renderer.PrivateMemoryFootprint", 0);
auto samples = sentinel.GetHistogramSamplesSinceCreation( histograms.ExpectTotalCount("Memory.Renderer.SharedMemoryFootprint", 0);
"Memory.Total.RendererPrivateMemoryFootprint"); histograms.ExpectTotalCount("Memory.Renderer.ResidentSet", 0);
EXPECT_EQ(0, samples->TotalCount());
samples.reset(); histograms.ExpectTotalCount("Memory.Total.PrivateMemoryFootprint", 0);
histograms.ExpectTotalCount("Memory.Total.RendererPrivateMemoryFootprint", 0);
histograms.ExpectTotalCount("Memory.Total.SharedMemoryFootprint", 0);
histograms.ExpectTotalCount("Memory.Total.ResidentSet", 0);
// Simulate some metrics emission. // Simulate some metrics emission.
scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter( scoped_refptr<ProcessMemoryMetricsEmitterFake> emitter =
new ProcessMemoryMetricsEmitterFake(test_ukm_recorder_)); base::MakeRefCounted<ProcessMemoryMetricsEmitterFake>(test_ukm_recorder_);
emitter->ReceivedMemoryDump( emitter->ReceivedMemoryDump(
true, GlobalMemoryDump::MoveFrom(std::move(global_dump))); true, GlobalMemoryDump::MoveFrom(std::move(global_dump)));
emitter->ReceivedProcessInfos(GetProcessInfo(test_ukm_recorder_)); emitter->ReceivedProcessInfos(GetProcessInfo(test_ukm_recorder_));
// Check that the RendererPrivateMemoryFootprint histogram got written to. // Check that the expected values have been emitted to histograms.
samples = sentinel.GetHistogramSamplesSinceCreation( histograms.ExpectUniqueSample("Memory.Renderer.PrivateMemoryFootprint",
"Memory.Total.RendererPrivateMemoryFootprint"); kTestRendererPrivateMemoryFootprint, 2);
EXPECT_EQ(1, samples->TotalCount()); histograms.ExpectUniqueSample("Memory.Renderer.SharedMemoryFootprint",
kTestRendererSharedMemoryFootprint, 2);
#if defined(OS_MACOSX)
histograms.ExpectTotalCount("Memory.Renderer.ResidentSet", 0);
#else
histograms.ExpectUniqueSample("Memory.Renderer.ResidentSet",
kTestRendererResidentSet, 2);
#endif
histograms.ExpectUniqueSample("Memory.Total.PrivateMemoryFootprint",
2 * kTestRendererPrivateMemoryFootprint, 1);
histograms.ExpectUniqueSample("Memory.Total.RendererPrivateMemoryFootprint",
2 * kTestRendererPrivateMemoryFootprint, 1);
histograms.ExpectUniqueSample("Memory.Total.SharedMemoryFootprint",
2 * kTestRendererSharedMemoryFootprint, 1);
#if defined(OS_MACOSX)
histograms.ExpectTotalCount("Memory.Total.ResidentSet", 0);
#else
histograms.ExpectUniqueSample("Memory.Total.ResidentSet",
2 * kTestRendererResidentSet, 1);
#endif
} }
TEST_F(ProcessMemoryMetricsEmitterTest, MainFramePMFEmitted) { TEST_F(ProcessMemoryMetricsEmitterTest, MainFramePMFEmitted) {
GlobalMemoryDumpPtr global_dump( GlobalMemoryDumpPtr global_dump(
memory_instrumentation::mojom::GlobalMemoryDump::New()); memory_instrumentation::mojom::GlobalMemoryDump::New());
base::flat_map<const char*, int64_t> expected_metrics = MetricMap expected_metrics = GetExpectedRendererMetrics();
GetExpectedRendererMetrics();
AddPageMetrics(expected_metrics); AddPageMetrics(expected_metrics);
PopulateRendererMetrics(global_dump, expected_metrics, 201); PopulateRendererMetrics(global_dump, expected_metrics, kTestRendererPid201);
auto entries = test_ukm_recorder_.GetEntriesByName( auto entries = test_ukm_recorder_.GetEntriesByName(
ukm::builders::Memory_TabFootprint::kEntryName); ukm::builders::Memory_TabFootprint::kEntryName);
......
...@@ -47549,6 +47549,18 @@ uploading your change for review. ...@@ -47549,6 +47549,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.AudioService.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in a audio service process. This is
influenced by factors we control (e.g. memory that is not accessed can be
swapped) and factors we don't control (e.g. an unrelated process using a lot
of memory can force memory in our process to be swapped). Recorded once per
UMA ping on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.AudioService.SharedMemoryFootprint" units="MB"> <histogram name="Memory.AudioService.SharedMemoryFootprint" units="MB">
<owner>marinaciocea@chromium.org</owner> <owner>marinaciocea@chromium.org</owner>
<owner>maxmorin@chromium.org</owner> <owner>maxmorin@chromium.org</owner>
...@@ -47634,6 +47646,18 @@ uploading your change for review. ...@@ -47634,6 +47646,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Browser.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in the browser process. This is influenced
by factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Browser.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Browser.SharedMemoryFootprint" units="MB">
<owner>erikchen@chromium.org</owner> <owner>erikchen@chromium.org</owner>
<summary> <summary>
...@@ -48306,6 +48330,18 @@ uploading your change for review. ...@@ -48306,6 +48330,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Extension.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in an extension process. This is influenced
by factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Extension.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Extension.SharedMemoryFootprint" units="MB">
<owner>erikchen@chromium.org</owner> <owner>erikchen@chromium.org</owner>
<owner>ssid@chromium.org</owner> <owner>ssid@chromium.org</owner>
...@@ -48374,6 +48410,17 @@ uploading your change for review. ...@@ -48374,6 +48410,17 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Gpu.ResidentSet" units="MiB" expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in the GPU process. This is influenced by
factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Gpu.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Gpu.SharedMemoryFootprint" units="MB">
<owner>erikchen@chromium.org</owner> <owner>erikchen@chromium.org</owner>
<owner>ssid@chromium.org</owner> <owner>ssid@chromium.org</owner>
...@@ -48743,6 +48790,18 @@ uploading your change for review. ...@@ -48743,6 +48790,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Renderer.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in a renderer process. This is influenced by
factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Renderer.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Renderer.SharedMemoryFootprint" units="MB">
<owner>erikchen@chromium.org</owner> <owner>erikchen@chromium.org</owner>
<owner>ssid@chromium.org</owner> <owner>ssid@chromium.org</owner>
...@@ -49366,6 +49425,18 @@ uploading your change for review. ...@@ -49366,6 +49425,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Total.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in all processes. This is influenced by
factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Total.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Total.SharedMemoryFootprint" units="MB">
<owner>erikchen@chromium.org</owner> <owner>erikchen@chromium.org</owner>
<owner>ssid@chromium.org</owner> <owner>ssid@chromium.org</owner>
...@@ -49418,6 +49489,18 @@ uploading your change for review. ...@@ -49418,6 +49489,18 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.Utility.ResidentSet" units="MiB"
expires_after="2019-01-31">
<owner>fdoray@chromium.org</owner>
<summary>
The size of the resident memory in a utility process. This is influenced by
factors we control (e.g. memory that is not accessed can be swapped) and
factors we don't control (e.g. an unrelated process using a lot of memory
can force memory in our process to be swapped). Recorded once per UMA ping
on Windows/Linux/ChromeOS/Android.
</summary>
</histogram>
<histogram name="Memory.Utility.SharedMemoryFootprint" units="MB"> <histogram name="Memory.Utility.SharedMemoryFootprint" units="MB">
<owner>jam@chromium.org</owner> <owner>jam@chromium.org</owner>
<summary> <summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment