| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "base/memory/memory_pressure_monitor.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/process/process_metrics.h" | 8 #include "base/process/process_metrics.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // The time between memory pressure checks. While under critical pressure, this | 17 // The time between memory pressure checks. While under critical pressure, this |
| 18 // is also the timer to repeat cleanup attempts. | 18 // is also the timer to repeat cleanup attempts. |
| 19 const int kMemoryPressureIntervalMs = 1000; | 19 const int kMemoryPressureIntervalMs = 1000; |
| 20 | 20 |
| 21 // The time which should pass between two moderate memory pressure calls. | 21 // The time which should pass between two moderate memory pressure calls. |
| 22 const int kModerateMemoryPressureCooldownMs = 10000; | 22 const int kModerateMemoryPressureCooldownMs = 10000; |
| 23 | 23 |
| 24 // Number of event polls before the next moderate pressure event can be sent. | 24 // Number of event polls before the next moderate pressure event can be sent. |
| 25 const int kModerateMemoryPressureCooldown = | 25 const int kModerateMemoryPressureCooldown = |
| 26 kModerateMemoryPressureCooldownMs / kMemoryPressureIntervalMs; | 26 kModerateMemoryPressureCooldownMs / kMemoryPressureIntervalMs; |
| 27 | 27 |
| 28 // Threshold constants to emit pressure events. | 28 // Threshold constants to emit pressure events. |
| 29 const int kNormalMemoryPressureModerateThresholdPercent = 60; | 29 const int kNormalMemoryPressureModerateThresholdPercent = 60; |
| 30 const int kNormalMemoryPressureCriticalThresholdPercent = 95; | 30 const int kNormalMemoryPressureCriticalThresholdPercent = 90; |
| 31 | 31 |
| 32 // The possible state for memory pressure level. The values should be in line | 32 // The possible state for memory pressure level. The values should be in line |
| 33 // with values in MemoryPressureListener::MemoryPressureLevel and should be | 33 // with values in MemoryPressureListener::MemoryPressureLevel and should be |
| 34 // updated if more memory pressure levels are introduced. | 34 // updated if more memory pressure levels are introduced. |
| 35 enum MemoryPressureLevelUMA { | 35 enum MemoryPressureLevelUMA { |
| 36 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0, | 36 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0, |
| 37 UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1, | 37 UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1, |
| 38 UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2, | 38 UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2, |
| 39 // This must be the last value in the enum. | 39 // This must be the last value in the enum. |
| 40 UMA_MEMORY_PRESSURE_LEVEL_COUNT, | 40 UMA_MEMORY_PRESSURE_LEVEL_COUNT, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 int64 total_memory = info.total; | 160 int64 total_memory = info.total; |
| 161 int64 available_memory = info.free; | 161 int64 available_memory = info.free; |
| 162 | 162 |
| 163 DCHECK(available_memory < total_memory); | 163 DCHECK(available_memory < total_memory); |
| 164 int percentage = static_cast<int>(((total_memory - available_memory) * 100) / | 164 int percentage = static_cast<int>(((total_memory - available_memory) * 100) / |
| 165 total_memory); | 165 total_memory); |
| 166 return percentage; | 166 return percentage; |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace base | 169 } // namespace base |
| OLD | NEW |