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

Unified Diff: base/memory/memory_pressure_monitor_mac.cc

Issue 2434103003: Add Mac memory pressure statistic reporting and consolidate platform code (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/memory_pressure_monitor_mac.h ('k') | base/memory/memory_pressure_monitor_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_pressure_monitor_mac.cc
diff --git a/base/memory/memory_pressure_monitor_mac.cc b/base/memory/memory_pressure_monitor_mac.cc
index d3430e94ca45a1ad9150c3cfe8f3342faf02ffe6..5207aa5cde4101076f14c1a038545d7a247150b4 100644
--- a/base/memory/memory_pressure_monitor_mac.cc
+++ b/base/memory/memory_pressure_monitor_mac.cc
@@ -33,26 +33,17 @@ MemoryPressureMonitor::MemoryPressureLevelForMacMemoryPressure(
return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
}
-void MemoryPressureMonitor::NotifyMemoryPressureChanged(
- dispatch_source_s* event_source,
- const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
- int mac_memory_pressure = dispatch_source_get_data(event_source);
- MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
- MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
- dispatch_callback.Run(memory_pressure_level);
-}
-
MemoryPressureMonitor::MemoryPressureMonitor()
- // The MemoryPressureListener doesn't want to know about transitions to
- // MEMORY_PRESSURE_LEVEL_NONE so don't watch for
- // DISPATCH_MEMORYPRESSURE_NORMAL notifications.
: memory_level_event_source_(dispatch_source_create(
DISPATCH_SOURCE_TYPE_MEMORYPRESSURE,
0,
- DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL,
+ DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL |
+ DISPATCH_MEMORYPRESSURE_NORMAL,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0))),
dispatch_callback_(
- base::Bind(&MemoryPressureListener::NotifyMemoryPressure)) {
+ base::Bind(&MemoryPressureListener::NotifyMemoryPressure)),
shrike 2016/10/20 21:04:31 I think MemoryPressureListener::NotifyMemoryPressu
lgrey 2016/10/21 14:15:04 This threw me for a loop for a bit, then I realize
chrisha 2016/10/21 18:18:58 Yeah, the rename might help. Maybe "OnMemoryPressu
lgrey 2016/10/21 18:39:35 Done.
+ last_pressure_change_(CFAbsoluteTimeGetCurrent()) {
+ last_pressure_level_ = GetCurrentPressureLevel();
dispatch_source_set_event_handler(memory_level_event_source_, ^{
NotifyMemoryPressureChanged(memory_level_event_source_.get(),
dispatch_callback_);
@@ -72,6 +63,28 @@ MemoryPressureMonitor::GetCurrentPressureLevel() const {
&length, nullptr, 0);
return MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
}
+void MemoryPressureMonitor::NotifyMemoryPressureChanged(
+ dispatch_source_s* event_source,
+ const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
+ int mac_memory_pressure = dispatch_source_get_data(event_source);
+ MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
+ MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
+ CFTimeInterval now = CFAbsoluteTimeGetCurrent();
+ CFTimeInterval since_last_change = now - last_pressure_change_;
+ last_pressure_change_ = now;
+
+ // TODO(lgrey): Two questions:
+ // 1) Is it OK to give up precision by flooring this?
+ // 2) Is there a better way to send multiple events?
+ int last_level_seconds = static_cast<int>(since_last_change);
+ for (int i = 0; i < last_level_seconds; i++) {
shrike 2016/10/20 21:04:30 This is unfortunate, because last_level_seconds co
lgrey 2016/10/21 14:15:04 asvitkine@ what do you think? For context, this p
chrisha 2016/10/21 18:18:58 We had talked about switching to polling on Mac, a
lgrey 2016/10/21 18:39:35 My mistake, it looks like Chrome polls once a seco
+ RecordMemoryPressure(last_pressure_level_);
+ }
+ last_pressure_level_ = memory_pressure_level;
+ if (memory_pressure_level !=
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE)
+ dispatch_callback.Run(memory_pressure_level);
+}
void MemoryPressureMonitor::SetDispatchCallback(
const DispatchCallback& callback) {
« no previous file with comments | « base/memory/memory_pressure_monitor_mac.h ('k') | base/memory/memory_pressure_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698