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

Unified Diff: base/memory/memory_pressure_monitor_mac.h

Issue 1587273002: [Mac] Collect real-time memory pressure stats, in an energy-efficient way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits. Created 3 years, 10 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 | « no previous file | base/memory/memory_pressure_monitor_mac.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.h
diff --git a/base/memory/memory_pressure_monitor_mac.h b/base/memory/memory_pressure_monitor_mac.h
index 9118632bd664e4e5289c3e60f7b3c842861ab5d6..b85b6c9017dbaaffe22a11b548c139ab3a59c8e1 100644
--- a/base/memory/memory_pressure_monitor_mac.h
+++ b/base/memory/memory_pressure_monitor_mac.h
@@ -9,10 +9,12 @@
#include <dispatch/dispatch.h>
#include "base/base_export.h"
+#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_dispatch_object.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/memory_pressure_monitor.h"
+#include "base/message_loop/message_pump_mac.h"
namespace base {
namespace mac {
@@ -34,24 +36,51 @@ class BASE_EXPORT MemoryPressureMonitor : public base::MemoryPressureMonitor {
private:
friend TestMemoryPressureMonitor;
- static MemoryPressureLevel
- MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure);
+ static MemoryPressureLevel MemoryPressureLevelForMacMemoryPressureLevel(
+ int mac_memory_pressure_level);
+ static void OnRunLoopExit(CFRunLoopObserverRef observer,
+ CFRunLoopActivity activity,
+ void* info);
+ // Returns the raw memory pressure level from the macOS. Exposed for
+ // unit testing.
+ virtual int GetMacMemoryPressureLevel();
+
+ // Updates |last_pressure_level_| with the current memory pressure level.
+ void UpdatePressureLevel();
+
+ // Updates |last_pressure_level_| at the end of every run loop pass (modulo
+ // some number of seconds).
+ void UpdatePressureLevelOnRunLoopExit();
+
+ // Run |dispatch_callback| on memory pressure notifications from the OS.
void OnMemoryPressureChanged(dispatch_source_s* event_source,
const DispatchCallback& dispatch_callback);
- void SendStatisticsIfNecessary(bool pressure_level_changed);
+ // Returns the number of seconds per UMA tick (for statistics recording).
+ // Exposed for testing.
+ static int GetSecondsPerUMATick();
+
+ // The dispatch source that generates memory pressure change notifications.
ScopedDispatchObject<dispatch_source_t> memory_level_event_source_;
+ // The callback to call upon receiving a memory pressure change notification.
DispatchCallback dispatch_callback_;
- CFTimeInterval last_statistic_report_;
+ // Last UMA report time.
+ CFTimeInterval last_statistic_report_time_;
+ // Most-recent memory pressure level.
MemoryPressureLevel last_pressure_level_;
- // The UMA statistic is recorded in 5 second increments. This
- // accumulates the remaining time to be rolled into the next
- // call.
- CFTimeInterval reporting_error_;
+ // Observer that tracks exits from the main run loop.
+ ScopedCFTypeRef<CFRunLoopObserverRef> exit_observer_;
+
+ // Next time to update the memory pressure level when exiting the run loop.
+ CFTimeInterval next_run_loop_update_time_;
+
+ // Seconds left over from the last UMA tick calculation (to be added to the
+ // next calculation).
+ CFTimeInterval subtick_seconds_;
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
};
« no previous file with comments | « no previous file | base/memory/memory_pressure_monitor_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698