| 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..dff791bc6d1cb1aa1331705e4eeeecb2b198debd 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,20 @@ int GetCriticalMemoryThresholdInPercent(
|
| : kNormalMemoryPressureCriticalThresholdPercent;
|
| }
|
|
|
| +// Computes the by kNonCriticalTimeFractionMagnification scaled fraction of time
|
| +// spent in non critical state vs. in critical + non critical state.
|
| +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 +92,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() {
|
| + // Before shutting down send the quality of service statistics.
|
| + 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 +141,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) {
|
|
|