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

Side by Side Diff: base/memory/memory_pressure_monitor_win.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 unified diff | Download patch
« no previous file with comments | « base/memory/memory_pressure_monitor_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_win.h" 5 #include "base/memory/memory_pressure_monitor_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/metrics/histogram_macros.h"
10 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 12
14 namespace base { 13 namespace base {
15 namespace win { 14 namespace win {
16 15
17 namespace { 16 namespace {
18 17
19 static const DWORDLONG kMBBytes = 1024 * 1024; 18 static const DWORDLONG kMBBytes = 1024 * 1024;
20 19
21 // Enumeration of UMA memory pressure levels. This needs to be kept in sync with
22 // histograms.xml and the memory pressure levels defined in
23 // MemoryPressureListener.
24 enum MemoryPressureLevelUMA {
25 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0,
26 UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1,
27 UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2,
28 // This must be the last value in the enum.
29 UMA_MEMORY_PRESSURE_LEVEL_COUNT,
30 };
31
32 // Converts a memory pressure level to an UMA enumeration value.
33 MemoryPressureLevelUMA MemoryPressureLevelToUmaEnumValue(
34 MemoryPressureListener::MemoryPressureLevel level) {
35 switch (level) {
36 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
37 return UMA_MEMORY_PRESSURE_LEVEL_NONE;
38 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
39 return UMA_MEMORY_PRESSURE_LEVEL_MODERATE;
40 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
41 return UMA_MEMORY_PRESSURE_LEVEL_CRITICAL;
42 }
43 NOTREACHED();
44 return UMA_MEMORY_PRESSURE_LEVEL_NONE;
45 }
46
47 } // namespace 20 } // namespace
48 21
49 // The following constants have been lifted from similar values in the ChromeOS 22 // The following constants have been lifted from similar values in the ChromeOS
50 // memory pressure monitor. The values were determined experimentally to ensure 23 // memory pressure monitor. The values were determined experimentally to ensure
51 // sufficient responsiveness of the memory pressure subsystem, and minimal 24 // sufficient responsiveness of the memory pressure subsystem, and minimal
52 // overhead. 25 // overhead.
53 const int MemoryPressureMonitor::kPollingIntervalMs = 5000; 26 const int MemoryPressureMonitor::kPollingIntervalMs = 5000;
54 const int MemoryPressureMonitor::kModeratePressureCooldownMs = 10000; 27 const int MemoryPressureMonitor::kModeratePressureCooldownMs = 10000;
55 const int MemoryPressureMonitor::kModeratePressureCooldownCycles = 28 const int MemoryPressureMonitor::kModeratePressureCooldownCycles =
56 kModeratePressureCooldownMs / kPollingIntervalMs; 29 kModeratePressureCooldownMs / kPollingIntervalMs;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 DCHECK_NE(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, 176 DCHECK_NE(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
204 current_memory_pressure_level_); 177 current_memory_pressure_level_);
205 dispatch_callback_.Run(current_memory_pressure_level_); 178 dispatch_callback_.Run(current_memory_pressure_level_);
206 } 179 }
207 180
208 void MemoryPressureMonitor::CheckMemoryPressureAndRecordStatistics() { 181 void MemoryPressureMonitor::CheckMemoryPressureAndRecordStatistics() {
209 DCHECK(thread_checker_.CalledOnValidThread()); 182 DCHECK(thread_checker_.CalledOnValidThread());
210 183
211 CheckMemoryPressure(); 184 CheckMemoryPressure();
212 185
213 UMA_HISTOGRAM_ENUMERATION( 186 RecordMemoryPressure(current_memory_pressure_level_, 1);
214 "Memory.PressureLevel",
215 MemoryPressureLevelToUmaEnumValue(current_memory_pressure_level_),
216 UMA_MEMORY_PRESSURE_LEVEL_COUNT);
217 } 187 }
218 188
219 MemoryPressureListener::MemoryPressureLevel 189 MemoryPressureListener::MemoryPressureLevel
220 MemoryPressureMonitor::CalculateCurrentPressureLevel() { 190 MemoryPressureMonitor::CalculateCurrentPressureLevel() {
221 MEMORYSTATUSEX mem_status = {}; 191 MEMORYSTATUSEX mem_status = {};
222 if (!GetSystemMemoryStatus(&mem_status)) 192 if (!GetSystemMemoryStatus(&mem_status))
223 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; 193 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
224 194
225 // How much system memory is actively available for use right now, in MBs. 195 // How much system memory is actively available for use right now, in MBs.
226 int phys_free = static_cast<int>(mem_status.ullAvailPhys / kMBBytes); 196 int phys_free = static_cast<int>(mem_status.ullAvailPhys / kMBBytes);
(...skipping 27 matching lines...) Expand all
254 return true; 224 return true;
255 } 225 }
256 226
257 void MemoryPressureMonitor::SetDispatchCallback( 227 void MemoryPressureMonitor::SetDispatchCallback(
258 const DispatchCallback& callback) { 228 const DispatchCallback& callback) {
259 dispatch_callback_ = callback; 229 dispatch_callback_ = callback;
260 } 230 }
261 231
262 } // namespace win 232 } // namespace win
263 } // namespace base 233 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/memory_pressure_monitor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698