Skip to content

Commit

Permalink
Remove unused memory metrics.
Browse files Browse the repository at this point in the history
This CL removes several memory metrics that are not being used. These are:
  * Memory.{ProcessType}Count
  * Memory.*.Committed
  * Memory.Renderer{Shrink,Growth}In30Min
  * Memory.Swap.*

The memory metrics actively being used and developed are emitted in
ProcessMemoryMetricsEmitter. These are emitted in both UMA and UKM form. The UKM
form implicitly includes ProcessType, though with less granularity. Both the UMA
and UKMs include PrivateMemoryFootprint, a cross-platform consistent metric that
supercedes Memory.*.Committed. There is no replacement for
Memory.Renderer{Shrink,Growth}In30Min.

Bug: 765470
Change-Id: I857f710eeb3ddf233b63be3139ea90ebe8d9a5c9
Reviewed-on: https://chromium-review.googlesource.com/952985
Reviewed-by: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Takashi Sakamoto <tasak@google.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: Nick Carter <nick@chromium.org>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542144}
  • Loading branch information
erikchen authored and Commit Bot committed Mar 9, 2018
1 parent ce362d2 commit 489b507
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 304 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/metrics/chrome_metrics_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ void ChromeMetricsServiceClient::CollectFinalHistograms() {
weak_ptr_factory_.GetWeakPtr());

scoped_refptr<MetricsMemoryDetails> details(
new MetricsMemoryDetails(callback, &memory_growth_tracker_));
new MetricsMemoryDetails(callback));
details->StartFetch();

scoped_refptr<ProcessMemoryMetricsEmitter> emitter(
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/metrics/chrome_metrics_service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ class ChromeMetricsServiceClient : public metrics::MetricsServiceClient,
PluginMetricsProvider* plugin_metrics_provider_;
#endif

// The MemoryGrowthTracker instance that tracks memory usage growth in
// MemoryDetails.
MemoryGrowthTracker memory_growth_tracker_;

// Callback to determine whether or not a cellular network is currently being
// used.
base::Callback<void(bool*)> cellular_callback_;
Expand Down
193 changes: 1 addition & 192 deletions chrome/browser/metrics/metrics_memory_details.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,9 @@
#include "ppapi/features/features.h"
#include "third_party/leveldatabase/leveldb_chrome.h"

MemoryGrowthTracker::MemoryGrowthTracker() {
}

MemoryGrowthTracker::~MemoryGrowthTracker() {
}

bool MemoryGrowthTracker::UpdateSample(base::ProcessId pid,
int sample,
int* diff) {
// |sample| is memory usage in kB.
const base::TimeTicks current_time = base::TimeTicks::Now();
std::map<base::ProcessId, int>::iterator found_size = memory_sizes_.find(pid);
if (found_size != memory_sizes_.end()) {
const int last_size = found_size->second;
std::map<base::ProcessId, base::TimeTicks>::iterator found_time =
times_.find(pid);
const base::TimeTicks last_time = found_time->second;
if (last_time < (current_time - base::TimeDelta::FromMinutes(30))) {
// Note that it is undefined how division of a negative integer gets
// rounded. |*diff| may have a difference of 1 from the correct number
// if |sample| < |last_size|. We ignore it as 1 is small enough.
*diff =
((sample - last_size) * 30 / (current_time - last_time).InMinutes());
found_size->second = sample;
found_time->second = current_time;
return true;
}
// Skip if a last record is found less than 30 minutes ago.
} else {
// Not reporting if it's the first record for |pid|.
times_[pid] = current_time;
memory_sizes_[pid] = sample;
}
return false;
}

MetricsMemoryDetails::MetricsMemoryDetails(
const base::Closure& callback,
MemoryGrowthTracker* memory_growth_tracker)
const base::Closure& callback)
: callback_(callback),
memory_growth_tracker_(memory_growth_tracker),
generate_histograms_(true) {}

MetricsMemoryDetails::~MetricsMemoryDetails() {
Expand All @@ -70,7 +32,6 @@ MetricsMemoryDetails::~MetricsMemoryDetails() {
void MetricsMemoryDetails::OnDetailsAvailable() {
if (generate_histograms_)
UpdateHistograms();
AnalyzeMemoryGrowth();
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_);
}

Expand All @@ -80,22 +41,12 @@ void MetricsMemoryDetails::UpdateHistograms() {
const ProcessData& browser = *ChromeBrowser();
int chrome_count = 0;
int extension_count = 0;
int pepper_plugin_count = 0;
int pepper_plugin_broker_count = 0;
int renderer_count = 0;
int other_count = 0;
int worker_count = 0;
int process_limit = content::RenderProcessHost::GetMaxRendererProcessCount();
for (size_t index = 0; index < browser.processes.size(); index++) {
size_t committed = browser.processes[index].committed.priv +
browser.processes[index].committed.mapped +
browser.processes[index].committed.image;
int num_open_fds = browser.processes[index].num_open_fds;
int open_fds_soft_limit = browser.processes[index].open_fds_soft_limit;
switch (browser.processes[index].process_type) {
case content::PROCESS_TYPE_BROWSER:
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Browser.Committed",
committed / 1024);
if (num_open_fds != -1 && open_fds_soft_limit != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.Browser.OpenFDs", num_open_fds);
UMA_HISTOGRAM_COUNTS_10000("Memory.Browser.OpenFDsSoftLimit",
Expand Down Expand Up @@ -129,9 +80,6 @@ void MetricsMemoryDetails::UpdateHistograms() {
continue;
case ProcessMemoryInformation::RENDERER_NORMAL:
default:
// TODO(erikkay): Should we bother splitting out the other subtypes?
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Committed",
committed / 1024);
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.Renderer.OpenFDs",
num_open_fds);
Expand All @@ -143,58 +91,50 @@ void MetricsMemoryDetails::UpdateHistograms() {
case content::PROCESS_TYPE_UTILITY:
if (num_open_fds != -1)
UMA_HISTOGRAM_COUNTS_10000("Memory.Utility.OpenFDs", num_open_fds);
other_count++;
continue;
case content::PROCESS_TYPE_ZYGOTE:
if (num_open_fds != -1)
UMA_HISTOGRAM_COUNTS_10000("Memory.Zygote.OpenFDs", num_open_fds);
other_count++;
continue;
case content::PROCESS_TYPE_SANDBOX_HELPER:
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.SandboxHelper.OpenFDs",
num_open_fds);
}
other_count++;
continue;
case content::PROCESS_TYPE_GPU:
if (num_open_fds != -1 && open_fds_soft_limit != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.Gpu.OpenFDs", num_open_fds);
UMA_HISTOGRAM_COUNTS_10000("Memory.Gpu.OpenFDsSoftLimit",
open_fds_soft_limit);
}
other_count++;
continue;
#if BUILDFLAG(ENABLE_PLUGINS)
case content::PROCESS_TYPE_PPAPI_PLUGIN: {
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.PepperPlugin.OpenFDs",
num_open_fds);
}
pepper_plugin_count++;
continue;
}
case content::PROCESS_TYPE_PPAPI_BROKER:
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.PepperPluginBroker.OpenFDs",
num_open_fds);
}
pepper_plugin_broker_count++;
continue;
#endif
case PROCESS_TYPE_NACL_LOADER:
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.NativeClient.OpenFDs",
num_open_fds);
}
other_count++;
continue;
case PROCESS_TYPE_NACL_BROKER:
if (num_open_fds != -1) {
UMA_HISTOGRAM_COUNTS_10000("Memory.NativeClientBroker.OpenFDs",
num_open_fds);
}
other_count++;
continue;
default:
NOTREACHED();
Expand All @@ -209,21 +149,6 @@ void MetricsMemoryDetails::UpdateHistograms() {
UMA_HISTOGRAM_MEMORY_MB("Memory.Graphics", meminfo.gem_size / 1024 / 1024);
#endif

UMA_HISTOGRAM_COUNTS_100("Memory.ProcessLimit", process_limit);
UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount",
static_cast<int>(browser.processes.size()));
UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count);
UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count);
UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count);
UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
pepper_plugin_count);
UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount",
pepper_plugin_broker_count);
UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
// TODO(viettrungluu): Do we want separate counts for the other
// (platform-specific) process types?

// Predict the number of processes needed when isolating all sites and when
// isolating only HTTPS sites.
int all_renderer_count = renderer_count + chrome_count + extension_count;
Expand All @@ -232,121 +157,5 @@ void MetricsMemoryDetails::UpdateHistograms() {
SiteDetails::UpdateHistograms(browser.site_data, all_renderer_count,
non_renderer_count);

#if defined(OS_CHROMEOS)
UpdateSwapHistograms();
#endif
leveldb_chrome::UpdateHistograms();
}

#if defined(OS_CHROMEOS)
void MetricsMemoryDetails::UpdateSwapHistograms() {
UMA_HISTOGRAM_BOOLEAN("Memory.Swap.HaveSwapped", swap_info().num_writes > 0);
if (swap_info().num_writes == 0)
return;

// Only record swap info when any swaps have happened, to give us more
// detail in the histograms.
const ProcessData& browser = *ChromeBrowser();
size_t aggregate_memory = 0;
for (size_t index = 0; index < browser.processes.size(); index++) {
int sample = static_cast<int>(browser.processes[index].working_set.swapped);
aggregate_memory += sample;
switch (browser.processes[index].process_type) {
case content::PROCESS_TYPE_BROWSER:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Browser", sample);
continue;
case content::PROCESS_TYPE_RENDERER: {
ProcessMemoryInformation::RendererProcessType renderer_type =
browser.processes[index].renderer_type;
switch (renderer_type) {
case ProcessMemoryInformation::RENDERER_EXTENSION:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Extension", sample);
continue;
case ProcessMemoryInformation::RENDERER_CHROME:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Chrome", sample);
continue;
case ProcessMemoryInformation::RENDERER_UNKNOWN:
NOTREACHED() << "Unknown renderer process type.";
continue;
case ProcessMemoryInformation::RENDERER_NORMAL:
default:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Renderer", sample);
continue;
}
}
case content::PROCESS_TYPE_UTILITY:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Utility", sample);
continue;
case content::PROCESS_TYPE_ZYGOTE:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Zygote", sample);
continue;
case content::PROCESS_TYPE_SANDBOX_HELPER:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.SandboxHelper", sample);
continue;
case content::PROCESS_TYPE_GPU:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.Gpu", sample);
continue;
case content::PROCESS_TYPE_PPAPI_PLUGIN:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.PepperPlugin", sample);
continue;
case content::PROCESS_TYPE_PPAPI_BROKER:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.PepperPluginBroker", sample);
continue;
case PROCESS_TYPE_NACL_LOADER:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.NativeClient", sample);
continue;
case PROCESS_TYPE_NACL_BROKER:
UMA_HISTOGRAM_MEMORY_KB("Memory.Swap.NativeClientBroker", sample);
continue;
default:
NOTREACHED();
continue;
}
}

// TODO(rkaplow): Remove once we've verified Memory.Swap.Total2 is ok.
int total_sample_old = static_cast<int>(aggregate_memory / 1000);
UMA_HISTOGRAM_MEMORY_MB("Memory.Swap.Total", total_sample_old);
int total_sample = static_cast<int>(aggregate_memory / 1024);
UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Swap.Total2", total_sample);

UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.CompressedDataSize",
swap_info().compr_data_size / (1024 * 1024), 1,
4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.OriginalDataSize",
swap_info().orig_data_size / (1024 * 1024), 1,
4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.MemUsedTotal",
swap_info().mem_used_total / (1024 * 1024), 1,
4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumReads", swap_info().num_reads, 1,
100000000, 100);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites", swap_info().num_writes,
1, 100000000, 100);

if (swap_info().orig_data_size > 0 && swap_info().compr_data_size > 0) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Memory.Swap.CompressionRatio",
swap_info().orig_data_size / swap_info().compr_data_size, 1, 20, 20);
}
}
#endif // defined(OS_CHROMEOS)

void MetricsMemoryDetails::AnalyzeMemoryGrowth() {
for (const auto& process_entry : ChromeBrowser()->processes) {
int sample = static_cast<int>(process_entry.working_set.priv);
int diff;

// UpdateSample changes state of |memory_growth_tracker_| and it should be
// called even if |generate_histograms_| is false.
if (memory_growth_tracker_ &&
memory_growth_tracker_->UpdateSample(process_entry.pid, sample,
&diff) &&
generate_histograms_) {
if (diff < 0)
UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff);
else
UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff);
}
}
}
42 changes: 1 addition & 41 deletions chrome/browser/metrics/metrics_memory_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,12 @@
#include "build/build_config.h"
#include "chrome/browser/memory_details.h"

// MemoryGrowthTracker tracks latest metrics about record time and memory usage
// at that time per process.
class MemoryGrowthTracker {
public:
MemoryGrowthTracker();
virtual ~MemoryGrowthTracker();

// If 30 minutes have passed since last UMA record, UpdateSample() computes
// a difference between current memory usage |sample| of process |pid| and
// stored memory usage at the time of last UMA record. Then, it updates the
// stored memory usage to |sample|, stores the difference in |diff| and
// returns true.
// If no memory usage of |pid| has not been recorded so far or 30 minutes
// have not passed since last record, it just returns false.
// |sample| is memory usage in kB.
virtual bool UpdateSample(base::ProcessId pid, int sample, int* diff);

private:
// Latest metrics about record time and memory usage at that time per process.
// The second values of |memory_sizes_| are in kB.
std::map<base::ProcessId, base::TimeTicks> times_;
std::map<base::ProcessId, int> memory_sizes_;

DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker);
};

// Handles asynchronous fetching of memory details and logging histograms about
// memory use of various processes.
// Will run the provided callback when finished.
class MetricsMemoryDetails : public MemoryDetails {
public:
MetricsMemoryDetails(const base::Closure& callback,
MemoryGrowthTracker* memory_growth_tracker);
explicit MetricsMemoryDetails(const base::Closure& callback);

void set_generate_histograms(bool generate_histograms) {
generate_histograms_ = generate_histograms;
Expand All @@ -60,21 +33,8 @@ class MetricsMemoryDetails : public MemoryDetails {
// Updates the global histograms for tracking memory usage.
void UpdateHistograms();

#if defined(OS_CHROMEOS)
void UpdateSwapHistograms();
#endif

// Notifies |memory_growth_tracker_| about the memory usage.
// Update histograms on memory growth or shrink in renderer processes.
void AnalyzeMemoryGrowth();

base::Closure callback_;

// A pointer to MemoryGrowthTracker which is contained in a longer-lived
// owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient.
// If it is null, nothing is tracked.
MemoryGrowthTracker* memory_growth_tracker_;

// A flag indicating if histogram data should be generated. True on default.
// If false, then only MemoryGrowthTracker gets notified about memory usage.
bool generate_histograms_;
Expand Down
Loading

0 comments on commit 489b507

Please sign in to comment.