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

Unified Diff: base/memory/memory_pressure_monitor.cc

Issue 2434103003: Add Mac memory pressure statistic reporting and consolidate platform code (Closed)
Patch Set: Add radar ID Created 4 years, 1 month 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
« no previous file with comments | « base/memory/memory_pressure_monitor.h ('k') | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_pressure_monitor.cc
diff --git a/base/memory/memory_pressure_monitor.cc b/base/memory/memory_pressure_monitor.cc
index 00633f1dd61981af41c7738d9c182d97367b9aef..ed350b81b98681610030511229b8a680cb2ca3d0 100644
--- a/base/memory/memory_pressure_monitor.cc
+++ b/base/memory/memory_pressure_monitor.cc
@@ -5,12 +5,39 @@
#include "base/memory/memory_pressure_monitor.h"
#include "base/logging.h"
+#include "base/metrics/histogram_macros.h"
namespace base {
namespace {
MemoryPressureMonitor* g_monitor = nullptr;
+// Enumeration of UMA memory pressure levels. This needs to be kept in sync with
+// histograms.xml and the memory pressure levels defined in
+// MemoryPressureListener.
+enum MemoryPressureLevelUMA {
+ UMA_MEMORY_PRESSURE_LEVEL_NONE = 0,
+ UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1,
+ UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2,
+ // This must be the last value in the enum.
+ UMA_MEMORY_PRESSURE_LEVEL_COUNT,
+};
+
+// Converts a memory pressure level to an UMA enumeration value.
+MemoryPressureLevelUMA MemoryPressureLevelToUmaEnumValue(
+ base::MemoryPressureListener::MemoryPressureLevel level) {
+ switch (level) {
+ case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
+ return UMA_MEMORY_PRESSURE_LEVEL_NONE;
+ case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
+ return UMA_MEMORY_PRESSURE_LEVEL_MODERATE;
+ case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
+ return UMA_MEMORY_PRESSURE_LEVEL_CRITICAL;
+ }
+ NOTREACHED();
+ return UMA_MEMORY_PRESSURE_LEVEL_NONE;
+}
+
} // namespace
MemoryPressureMonitor::MemoryPressureMonitor() {
@@ -27,5 +54,18 @@ MemoryPressureMonitor::~MemoryPressureMonitor() {
MemoryPressureMonitor* MemoryPressureMonitor::Get() {
return g_monitor;
}
+void MemoryPressureMonitor::RecordMemoryPressure(
+ base::MemoryPressureListener::MemoryPressureLevel level,
+ int ticks) {
+ // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the
+ // simple UMA_HISTOGRAM macros don't expose 'AddCount' functionality.
+ STATIC_HISTOGRAM_POINTER_BLOCK(
+ "Memory.PressureLevel",
+ AddCount(MemoryPressureLevelToUmaEnumValue(level), ticks),
+ base::LinearHistogram::FactoryGet(
+ "Memory.PressureLevel", 1, UMA_MEMORY_PRESSURE_LEVEL_COUNT,
+ UMA_MEMORY_PRESSURE_LEVEL_COUNT + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag));
+}
} // namespace base
« no previous file with comments | « base/memory/memory_pressure_monitor.h ('k') | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698