OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/memory_pressure_monitor_chromeos.h" | 5 #include "base/memory/memory_pressure_monitor_chromeos.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/select.h> | 8 #include <sys/select.h> |
9 | 9 |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return HANDLE_EINTR(select(file_descriptor + 1, &fds, NULL, NULL, &tv)) > 0; | 101 return HANDLE_EINTR(select(file_descriptor + 1, &fds, NULL, NULL, &tv)) > 0; |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 MemoryPressureMonitor::MemoryPressureMonitor( | 106 MemoryPressureMonitor::MemoryPressureMonitor( |
107 MemoryPressureThresholds thresholds) | 107 MemoryPressureThresholds thresholds) |
108 : current_memory_pressure_level_( | 108 : current_memory_pressure_level_( |
109 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), | 109 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), |
110 moderate_pressure_repeat_count_(0), | 110 moderate_pressure_repeat_count_(0), |
| 111 seconds_since_reporting_(0), |
111 moderate_pressure_threshold_percent_( | 112 moderate_pressure_threshold_percent_( |
112 GetModerateMemoryThresholdInPercent(thresholds)), | 113 GetModerateMemoryThresholdInPercent(thresholds)), |
113 critical_pressure_threshold_percent_( | 114 critical_pressure_threshold_percent_( |
114 GetCriticalMemoryThresholdInPercent(thresholds)), | 115 GetCriticalMemoryThresholdInPercent(thresholds)), |
115 low_mem_file_(HANDLE_EINTR(::open(kLowMemFile, O_RDONLY))), | 116 low_mem_file_(HANDLE_EINTR(::open(kLowMemFile, O_RDONLY))), |
116 dispatch_callback_( | 117 dispatch_callback_( |
117 base::Bind(&MemoryPressureListener::NotifyMemoryPressure)), | 118 base::Bind(&MemoryPressureListener::NotifyMemoryPressure)), |
118 weak_ptr_factory_(this) { | 119 weak_ptr_factory_(this) { |
119 StartObserving(); | 120 StartObserving(); |
120 LOG_IF(ERROR, | 121 LOG_IF(ERROR, |
(...skipping 30 matching lines...) Expand all Loading... |
151 weak_ptr_factory_.GetWeakPtr())); | 152 weak_ptr_factory_.GetWeakPtr())); |
152 } | 153 } |
153 | 154 |
154 void MemoryPressureMonitor::StopObserving() { | 155 void MemoryPressureMonitor::StopObserving() { |
155 // If StartObserving failed, StopObserving will still get called. | 156 // If StartObserving failed, StopObserving will still get called. |
156 timer_.Stop(); | 157 timer_.Stop(); |
157 } | 158 } |
158 | 159 |
159 void MemoryPressureMonitor::CheckMemoryPressureAndRecordStatistics() { | 160 void MemoryPressureMonitor::CheckMemoryPressureAndRecordStatistics() { |
160 CheckMemoryPressure(); | 161 CheckMemoryPressure(); |
161 | 162 if (seconds_since_reporting_++ == 5) { |
| 163 seconds_since_reporting_ = 0; |
| 164 RecordMemoryPressure(current_memory_pressure_level_, 1); |
| 165 } |
162 // Record UMA histogram statistics for the current memory pressure level. | 166 // Record UMA histogram statistics for the current memory pressure level. |
| 167 // TODO(lgrey): Remove this once there's a usable history for the |
| 168 // "Memory.PressureLevel" statistic |
163 MemoryPressureLevelUMA memory_pressure_level_uma(MEMORY_PRESSURE_LEVEL_NONE); | 169 MemoryPressureLevelUMA memory_pressure_level_uma(MEMORY_PRESSURE_LEVEL_NONE); |
164 switch (current_memory_pressure_level_) { | 170 switch (current_memory_pressure_level_) { |
165 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: | 171 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: |
166 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_NONE; | 172 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_NONE; |
167 break; | 173 break; |
168 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: | 174 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: |
169 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_MODERATE; | 175 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_MODERATE; |
170 break; | 176 break; |
171 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: | 177 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: |
172 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_CRITICAL; | 178 memory_pressure_level_uma = MEMORY_PRESSURE_LEVEL_CRITICAL; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return percentage; | 279 return percentage; |
274 } | 280 } |
275 | 281 |
276 void MemoryPressureMonitor::SetDispatchCallback( | 282 void MemoryPressureMonitor::SetDispatchCallback( |
277 const DispatchCallback& callback) { | 283 const DispatchCallback& callback) { |
278 dispatch_callback_ = callback; | 284 dispatch_callback_ = callback; |
279 } | 285 } |
280 | 286 |
281 } // namespace chromeos | 287 } // namespace chromeos |
282 } // namespace base | 288 } // namespace base |
OLD | NEW |