diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-02-25 01:07:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-02-25 01:07:42 +0000 |
commit | 7a603b294d00e3b0da09dd7dac253ffcc10ffb56 (patch) | |
tree | 97236e6b2be41e6a9d46fa7a86957bffc22c6d60 /core/java | |
parent | eb1d804246f031889619e9c5466e899f95c249d0 (diff) | |
parent | fb7b50a0263e500a6a8d2bbd7366b06d1fc91fe3 (diff) | |
download | frameworks_base-7a603b294d00e3b0da09dd7dac253ffcc10ffb56.zip frameworks_base-7a603b294d00e3b0da09dd7dac253ffcc10ffb56.tar.gz frameworks_base-7a603b294d00e3b0da09dd7dac253ffcc10ffb56.tar.bz2 |
Merge "Fix some issues with network usage in battery stats."
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/com/android/internal/os/BatteryStatsHelper.java | 4 | ||||
-rw-r--r-- | core/java/com/android/internal/os/BatteryStatsImpl.java | 34 |
2 files changed, 21 insertions, 17 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsHelper.java b/core/java/com/android/internal/os/BatteryStatsHelper.java index 8a15c99..e0cf435 100644 --- a/core/java/com/android/internal/os/BatteryStatsHelper.java +++ b/core/java/com/android/internal/os/BatteryStatsHelper.java @@ -642,8 +642,8 @@ public class BatteryStatsHelper { final long radioDataUptimeMs = mStats.getMobileRadioActiveTime(mBatteryRealtime, mStatsType) / 1000; - final double mobilePps = radioDataUptimeMs != 0 - ? mobileData / (double)radioDataUptimeMs + final double mobilePps = (mobileData != 0 && radioDataUptimeMs != 0) + ? (mobileData / (double)radioDataUptimeMs) : (((double)MOBILE_BPS) / 8 / 2048); return (MOBILE_POWER / mobilePps) / (60*60); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index c3e9862..40e8727 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -56,7 +56,6 @@ import com.android.internal.net.NetworkStatsFactory; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastPrintWriter; import com.android.internal.util.JournaledFile; -import com.google.android.collect.Sets; import java.io.File; import java.io.FileInputStream; @@ -65,7 +64,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -372,8 +370,10 @@ public final class BatteryStatsImpl extends BatteryStats { new HashMap<String, KernelWakelockStats>(); private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); - private NetworkStats mLastMobileSnapshot; - private NetworkStats mLastWifiSnapshot; + private NetworkStats mCurMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); + private NetworkStats mLastMobileSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); + private NetworkStats mCurWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); + private NetworkStats mLastWifiSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 50); private NetworkStats mTmpNetworkStats; private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); @@ -5608,6 +5608,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (mMobileIfaces.length > 0) { final NetworkStats snapshot; + final NetworkStats last = mCurMobileSnapshot; try { snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, mMobileIfaces, NetworkStats.TAG_NONE, mLastMobileSnapshot); @@ -5616,15 +5617,12 @@ public final class BatteryStatsImpl extends BatteryStats { return; } - if (mLastMobileSnapshot == null) { - mLastMobileSnapshot = snapshot; - return; - } + mCurMobileSnapshot = snapshot; + mLastMobileSnapshot = last; - final NetworkStats delta = NetworkStats.subtract(snapshot, mLastMobileSnapshot, + final NetworkStats delta = NetworkStats.subtract(snapshot, last, null, null, mTmpNetworkStats); mTmpNetworkStats = delta; - mLastMobileSnapshot = snapshot; final int size = delta.size(); for (int i = 0; i < size; i++) { @@ -5649,6 +5647,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (mWifiIfaces.length > 0) { final NetworkStats snapshot; + final NetworkStats last = mCurWifiSnapshot; try { snapshot = mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL, mWifiIfaces, NetworkStats.TAG_NONE, mLastWifiSnapshot); @@ -5657,12 +5656,10 @@ public final class BatteryStatsImpl extends BatteryStats { return; } - if (mLastWifiSnapshot == null) { - mLastWifiSnapshot = snapshot; - return; - } + mCurWifiSnapshot = snapshot; + mLastWifiSnapshot = last; - final NetworkStats delta = NetworkStats.subtract(snapshot, mLastWifiSnapshot, + final NetworkStats delta = NetworkStats.subtract(snapshot, last, null, null, mTmpNetworkStats); mTmpNetworkStats = delta; mLastWifiSnapshot = snapshot; @@ -5671,6 +5668,13 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i = 0; i < size; i++) { final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); + if (DEBUG) { + final NetworkStats.Entry cur = snapshot.getValues(i, null); + Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes + + " tx=" + entry.txBytes + ", cur rx=" + cur.rxBytes + + " tx=" + cur.txBytes); + } + if (entry.rxBytes == 0 || entry.txBytes == 0) continue; final Uid u = getUidStatsLocked(entry.uid); |