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

Side by Side Diff: base/memory/memory_pressure_monitor_win.cc

Issue 1250093006: Added memory pressure monitor for linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uncomment ::Get functionality Created 5 years, 5 months 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
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.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 13
14 namespace base { 14 namespace base {
15 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 20 // Enumeration of UMA memory pressure levels. This needs to be kept in sync with
22 // histograms.xml and the memory pressure levels defined in 21 // histograms.xml and the memory pressure levels defined in
23 // MemoryPressureListener. 22 // MemoryPressureListener.
24 enum MemoryPressureLevelUMA { 23 enum MemoryPressureLevelUMA {
25 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0, 24 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 87 }
89 88
90 MemoryPressureMonitor::MemoryPressureMonitor(int moderate_threshold_mb, 89 MemoryPressureMonitor::MemoryPressureMonitor(int moderate_threshold_mb,
91 int critical_threshold_mb) 90 int critical_threshold_mb)
92 : moderate_threshold_mb_(moderate_threshold_mb), 91 : moderate_threshold_mb_(moderate_threshold_mb),
93 critical_threshold_mb_(critical_threshold_mb), 92 critical_threshold_mb_(critical_threshold_mb),
94 current_memory_pressure_level_( 93 current_memory_pressure_level_(
95 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), 94 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
96 moderate_pressure_repeat_count_(0), 95 moderate_pressure_repeat_count_(0),
97 weak_ptr_factory_(this) { 96 weak_ptr_factory_(this) {
97 DCHECK(!g_monitor);
98 g_monitor = this;
99
98 DCHECK_GE(moderate_threshold_mb_, critical_threshold_mb_); 100 DCHECK_GE(moderate_threshold_mb_, critical_threshold_mb_);
99 DCHECK_LE(0, critical_threshold_mb_); 101 DCHECK_LE(0, critical_threshold_mb_);
100 StartObserving(); 102 StartObserving();
101 } 103 }
102 104
103 MemoryPressureMonitor::~MemoryPressureMonitor() { 105 MemoryPressureMonitor::~MemoryPressureMonitor() {
106 DCHECK(g_monitor);
107 g_monitor = nullptr;
108
104 StopObserving(); 109 StopObserving();
105 } 110 }
106 111
107 void MemoryPressureMonitor::CheckMemoryPressureSoon() { 112 void MemoryPressureMonitor::CheckMemoryPressureSoon() {
108 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
109 114
110 ThreadTaskRunnerHandle::Get()->PostTask( 115 ThreadTaskRunnerHandle::Get()->PostTask(
111 FROM_HERE, Bind(&MemoryPressureMonitor::CheckMemoryPressure, 116 FROM_HERE, Bind(&MemoryPressureMonitor::CheckMemoryPressure,
112 weak_ptr_factory_.GetWeakPtr())); 117 weak_ptr_factory_.GetWeakPtr()));
113 } 118 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 248
244 bool MemoryPressureMonitor::GetSystemMemoryStatus( 249 bool MemoryPressureMonitor::GetSystemMemoryStatus(
245 MEMORYSTATUSEX* mem_status) { 250 MEMORYSTATUSEX* mem_status) {
246 DCHECK(mem_status != nullptr); 251 DCHECK(mem_status != nullptr);
247 mem_status->dwLength = sizeof(*mem_status); 252 mem_status->dwLength = sizeof(*mem_status);
248 if (!::GlobalMemoryStatusEx(mem_status)) 253 if (!::GlobalMemoryStatusEx(mem_status))
249 return false; 254 return false;
250 return true; 255 return true;
251 } 256 }
252 257
253 } // namespace win
254 } // namespace base 258 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/memory_pressure_monitor_win.h ('k') | base/memory/memory_pressure_monitor_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698