diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index 1e847c595df0d..4ba7ec9840872 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -179,6 +179,11 @@ public abstract class BatteryStats implements Parcelable { */ public static final int FOREGROUND_SERVICE = 22; + /** + * A constant indicating an aggregate wifi multicast timer + */ + public static final int WIFI_AGGREGATE_MULTICAST_ENABLED = 23; + /** * Include all of the data in the stats, including previously saved data. */ @@ -2333,6 +2338,22 @@ public abstract class BatteryStats implements Parcelable { sUidToString, sUidToString, sUidToString, sIntToString }; + /** + * Returns total time for WiFi Multicast Wakelock timer. + * Note that this may be different from the sum of per uid timer values. + * + * {@hide} + */ + public abstract long getWifiMulticastWakelockTime(long elapsedRealtimeUs, int which); + + /** + * Returns total time for WiFi Multicast Wakelock timer + * Note that this may be different from the sum of per uid timer values. + * + * {@hide} + */ + public abstract int getWifiMulticastWakelockCount(int which); + /** * Returns the time in microseconds that wifi has been on while the device was * running on battery. @@ -3442,16 +3463,13 @@ public abstract class BatteryStats implements Parcelable { screenDozeTime / 1000); - // Calculate both wakelock and wifi multicast wakelock times across all uids. + // Calculate wakelock times across all uids. long fullWakeLockTimeTotal = 0; long partialWakeLockTimeTotal = 0; - long multicastWakeLockTimeTotalMicros = 0; - int multicastWakeLockCountTotal = 0; for (int iu = 0; iu < NU; iu++) { final Uid u = uidStats.valueAt(iu); - // First calculating the wakelock stats final ArrayMap wakelocks = u.getWakelockStats(); for (int iw=wakelocks.size()-1; iw>=0; iw--) { @@ -3469,13 +3487,6 @@ public abstract class BatteryStats implements Parcelable { rawRealtime, which); } } - - // Now calculating the wifi multicast wakelock stats - final Timer mcTimer = u.getMulticastWakelockStats(); - if (mcTimer != null) { - multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); - multicastWakeLockCountTotal += mcTimer.getCountLocked(which); - } } // Dump network stats @@ -3592,6 +3603,9 @@ public abstract class BatteryStats implements Parcelable { dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); // Dump Multicast total stats + final long multicastWakeLockTimeTotalMicros = + getWifiMulticastWakelockTime(rawRealtime, which); + final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, multicastWakeLockTimeTotalMicros / 1000, multicastWakeLockCountTotal); @@ -4456,18 +4470,15 @@ public abstract class BatteryStats implements Parcelable { pw.print(" Connectivity changes: "); pw.println(connChanges); } - // Calculate both wakelock and wifi multicast wakelock times across all uids. + // Calculate wakelock times across all uids. long fullWakeLockTimeTotalMicros = 0; long partialWakeLockTimeTotalMicros = 0; - long multicastWakeLockTimeTotalMicros = 0; - int multicastWakeLockCountTotal = 0; final ArrayList timers = new ArrayList<>(); for (int iu = 0; iu < NU; iu++) { final Uid u = uidStats.valueAt(iu); - // First calculate wakelock statistics final ArrayMap wakelocks = u.getWakelockStats(); for (int iw=wakelocks.size()-1; iw>=0; iw--) { @@ -4495,13 +4506,6 @@ public abstract class BatteryStats implements Parcelable { } } } - - // Next calculate wifi multicast wakelock statistics - final Timer mcTimer = u.getMulticastWakelockStats(); - if (mcTimer != null) { - multicastWakeLockTimeTotalMicros += mcTimer.getTotalTimeLocked(rawRealtime, which); - multicastWakeLockCountTotal += mcTimer.getCountLocked(which); - } } final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); @@ -4531,6 +4535,9 @@ public abstract class BatteryStats implements Parcelable { pw.println(sb.toString()); } + final long multicastWakeLockTimeTotalMicros = + getWifiMulticastWakelockTime(rawRealtime, which); + final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); if (multicastWakeLockTimeTotalMicros != 0) { sb.setLength(0); sb.append(prefix); @@ -7535,22 +7542,9 @@ public abstract class BatteryStats implements Parcelable { proto.end(mToken); // Wifi multicast wakelock total stats (WIFI_MULTICAST_WAKELOCK_TOTAL_DATA) - // Calculate multicast wakelock stats across all uids. - long multicastWakeLockTimeTotalUs = 0; - int multicastWakeLockCountTotal = 0; - - for (int iu = 0; iu < uidStats.size(); iu++) { - final Uid u = uidStats.valueAt(iu); - - final Timer mcTimer = u.getMulticastWakelockStats(); - - if (mcTimer != null) { - multicastWakeLockTimeTotalUs += - mcTimer.getTotalTimeLocked(rawRealtimeUs, which); - multicastWakeLockCountTotal += mcTimer.getCountLocked(which); - } - } - + final long multicastWakeLockTimeTotalUs = + getWifiMulticastWakelockTime(rawRealtimeUs, which); + final int multicastWakeLockCountTotal = getWifiMulticastWakelockCount(which); final long wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, multicastWakeLockTimeTotalUs / 1000); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index cbb4ceb2725d7..1739bed7112f1 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -651,6 +651,14 @@ public class BatteryStatsImpl extends BatteryStats { final LongSamplingCounter[] mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; + /** + * The WiFi Overall wakelock timer + * This timer tracks the actual aggregate time for which MC wakelocks are enabled + * since addition of per UID timers would not result in an accurate value due to overlapp of + * per uid wakelock timers + */ + StopwatchTimer mWifiMulticastWakelockTimer; + /** * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. */ @@ -5589,6 +5597,12 @@ public class BatteryStatsImpl extends BatteryStats { if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); + + // Start Wifi Multicast overall timer + if (!mWifiMulticastWakelockTimer.isRunningLocked()) { + if (DEBUG_HISTORY) Slog.v(TAG, "WiFi Multicast Overall Timer Started"); + mWifiMulticastWakelockTimer.startRunningLocked(elapsedRealtime); + } } mWifiMulticastNesting++; getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); @@ -5604,6 +5618,12 @@ public class BatteryStatsImpl extends BatteryStats { if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); + + // Stop Wifi Multicast overall timer + if (mWifiMulticastWakelockTimer.isRunningLocked()) { + if (DEBUG_HISTORY) Slog.v(TAG, "Multicast Overall Timer Stopped"); + mWifiMulticastWakelockTimer.stopRunningLocked(elapsedRealtime); + } } getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); } @@ -5890,6 +5910,16 @@ public class BatteryStatsImpl extends BatteryStats { return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); } + @Override public long getWifiMulticastWakelockTime( + long elapsedRealtimeUs, int which) { + return mWifiMulticastWakelockTimer.getTotalTimeLocked( + elapsedRealtimeUs, which); + } + + @Override public int getWifiMulticastWakelockCount(int which) { + return mWifiMulticastWakelockTimer.getCountLocked(which); + } + @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); } @@ -9490,6 +9520,8 @@ public class BatteryStatsImpl extends BatteryStats { mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); + mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, + WIFI_AGGREGATE_MULTICAST_ENABLED, null, mOnBatteryTimeBase); mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); for (int i=0; i