Index: base/chromeos/memory_pressure_observer_chromeos.cc |
diff --git a/base/chromeos/memory_pressure_observer_chromeos.cc b/base/chromeos/memory_pressure_observer_chromeos.cc |
index 8112c761e5e713e747cb015d8226e62a754c87a8..1696149d62ebeb9fc0cd091492597b18d86712cd 100644 |
--- a/base/chromeos/memory_pressure_observer_chromeos.cc |
+++ b/base/chromeos/memory_pressure_observer_chromeos.cc |
@@ -5,6 +5,7 @@ |
#include "base/chromeos/memory_pressure_observer_chromeos.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/metrics/histogram_macros.h" |
#include "base/process/process_metrics.h" |
#include "base/time/time.h" |
@@ -29,6 +30,9 @@ const int kNormalMemoryPressureCriticalThresholdPercent = 90; |
const int kAggressiveMemoryPressureModerateThresholdPercent = 35; |
const int kAggressiveMemoryPressureCriticalThresholdPercent = 70; |
+// The number used to magnify the fraction of time spent in non critical state. |
+const int kNonCriticalTimeFractionMagnification = 1000000; |
+ |
// Converts a |MemoryPressureThreshold| value into a used memory percentage for |
// the moderate pressure event. |
int GetModerateMemoryThresholdInPercent( |
@@ -51,6 +55,21 @@ int GetCriticalMemoryThresholdInPercent( |
: kNormalMemoryPressureCriticalThresholdPercent; |
} |
+// Computes the fraction of time spent in the non critical state. Multiple the |
+// fraction with 1000000 to magnify the result for better comparison between |
Mr4D (OOO till 08-26)
2015/02/01 10:16:34
Maybe:
Computes the by kNonCriticalTimeFractionMa
|
+// different memory management schemes. |
+int GetNonCriticalTimeRatio(TimeDelta critical_delta, |
+ TimeDelta non_critical_delta) { |
+ return (kNonCriticalTimeFractionMagnification * |
+ non_critical_delta.InMilliseconds()) / |
+ ((non_critical_delta + critical_delta).InMilliseconds()); |
+} |
+ |
+void RecordNonCriticalTimeRatio(int non_critical_fraction) { |
+ UMA_HISTOGRAM_COUNTS("ChromeOS.MemoryPressureHandleQuality.NonCriticalRatio", |
+ non_critical_fraction); |
+} |
+ |
// Converts free percent of memory into a memory pressure value. |
MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevelFromFillLevel( |
int actual_fill_level, |
@@ -74,11 +93,26 @@ MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS( |
GetModerateMemoryThresholdInPercent(thresholds)), |
critical_pressure_threshold_percent_( |
GetCriticalMemoryThresholdInPercent(thresholds)), |
+ non_critical_start_time_(TimeTicks::Now()), |
+ critical_start_time_(TimeTicks::Now()), |
weak_ptr_factory_(this) { |
StartObserving(); |
} |
MemoryPressureObserverChromeOS::~MemoryPressureObserverChromeOS() { |
+ // Record the percentage for the last time. |
Mr4D (OOO till 08-26)
2015/02/01 10:16:34
What about:
// Before shutting down send the qual
|
+ if (GetMemoryPressureLevelFromFillLevel( |
+ GetUsedMemoryInPercent(), moderate_pressure_threshold_percent_, |
+ critical_pressure_threshold_percent_) == |
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
+ int fraction = GetNonCriticalTimeRatio( |
+ TimeTicks::Now() - critical_start_time_, |
+ critical_start_time_ - non_critical_start_time_); |
+ RecordNonCriticalTimeRatio(fraction); |
+ } else { |
+ RecordNonCriticalTimeRatio(kNonCriticalTimeFractionMagnification); |
+ } |
+ |
StopObserving(); |
} |
@@ -108,6 +142,26 @@ void MemoryPressureObserverChromeOS::CheckMemoryPressure() { |
GetMemoryPressureLevelFromFillLevel(GetUsedMemoryInPercent(), |
moderate_pressure_threshold_percent_, |
critical_pressure_threshold_percent_); |
+ |
+ // Record the quality of service of memory pressure handling. |
+ if (old_pressure != current_memory_pressure_level_) { |
+ TimeTicks now = TimeTicks::Now(); |
+ if (old_pressure == |
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
+ // When leaving the critical memory pressure, we compute the fraction of |
+ // time spent in the non critical vs. the critical state. A larger value |
+ // indicates a better management scheme. |
+ int fraction = GetNonCriticalTimeRatio( |
+ now - critical_start_time_, |
+ critical_start_time_ - non_critical_start_time_); |
+ RecordNonCriticalTimeRatio(fraction); |
+ non_critical_start_time_ = now; |
+ } else if (current_memory_pressure_level_ == |
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
+ critical_start_time_ = now; |
+ } |
+ } |
+ |
// In case there is no memory pressure we do not notify. |
if (current_memory_pressure_level_ == |
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) { |