summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bookatz <bookatz@google.com> 2017-09-13 11:51:52 -0700
committer Bookatz <bookatz@google.com> 2017-09-13 14:31:14 -0700
commit0b8a050853e9665152e139e9b7e1b90825f2004f (patch)
tree9ebce17585259d9cbc4acea2ed70cc5560297357
parent50df711a5125460acb8d2960ffc0a1f17a818103 (diff)
Throttle fetching RPM stats
RPM stats are expensive to fetch. However, updateRpmStatsLocked can get called over and over again. E.g. if BatteryStatsService.getStatistics is called multiple times in quick succession, the RPM stats would be fetched repeatedly. Because it is expensive, if therefore makes sense to throttle it to ensure that the fetching is not done too frequently. The data last fetched is cached. When asked to update, it will only actually do so if it is sufficiently old. Bug: 62549421 Bug: 65629008 Test: manual Change-Id: I6b7530d203deb9ad5bfb3415336a0de6a55bd89b
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 90455f643f35..54c32e816bec 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -183,8 +183,12 @@ public class BatteryStatsImpl extends BatteryStats {
return mKernelMemoryStats;
}
- /** Temporary container for Resource Power Manager stats. */
+ /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */
private final RpmStats mTmpRpmStats = new RpmStats();
+ /** The soonest the RPM stats can be updated after it was last updated. */
+ private static final long RPM_STATS_UPDATE_FREQ_MS = 1000;
+ /** Last time that RPM stats were updated by updateRpmStatsLocked. */
+ private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS;
public interface BatteryCallback {
public void batteryNeedsCpuUpdate();
@@ -10240,11 +10244,17 @@ public class BatteryStatsImpl extends BatteryStats {
}
/**
- * Read and record Resource Power Manager state and voter times.
+ * Read and record Resource Power Manager (RPM) state and voter times.
+ * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data
+ * instead of fetching it anew.
*/
public void updateRpmStatsLocked() {
if (mPlatformIdleStateCallback == null) return;
- mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats);
+ long now = SystemClock.elapsedRealtime();
+ if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) {
+ mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats);
+ mLastRpmStatsUpdateTimeMs = now;
+ }
for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate
: mTmpRpmStats.mPlatformLowPowerStats.entrySet()) {