Proper calculation for overall WiFi MC statistics
In current implementations the WiFi MC statistcs are calculating by aggregating the per uid statistics accross all UIDs. This does not result in the correct values in case of time overlapping acquisitions of MC wakelocks by same or different UIDs This commit creates a separate Timer instance that tracks the actual time spent with MC Enabled. Bug: 69854369 Test: Manual Test Change-Id: I78533f48300bc9faccc374d684698dae647bde5d Signed-off-by: Ahmed ElArabawy <arabawy@google.com>
This commit is contained in:
@@ -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<String, ? extends BatteryStats.Uid.Wakelock> 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<TimerEntry> timers = new ArrayList<>();
|
||||
|
||||
for (int iu = 0; iu < NU; iu++) {
|
||||
final Uid u = uidStats.valueAt(iu);
|
||||
|
||||
// First calculate wakelock statistics
|
||||
final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> 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);
|
||||
|
||||
@@ -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<NUM_WIFI_STATES; i++) {
|
||||
@@ -10191,6 +10223,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
|
||||
mWifiSignalStrengthsTimer[i].reset(false);
|
||||
}
|
||||
mWifiMulticastWakelockTimer.reset(false);
|
||||
mWifiActivity.reset(false);
|
||||
mBluetoothActivity.reset(false);
|
||||
mModemActivity.reset(false);
|
||||
@@ -12637,6 +12670,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in);
|
||||
mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in);
|
||||
mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in);
|
||||
mWifiMulticastWakelockTimer.readSummaryFromParcelLocked(in);
|
||||
mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
|
||||
mWifiOn = false;
|
||||
mWifiOnTimer.readSummaryFromParcelLocked(in);
|
||||
@@ -13077,6 +13111,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out);
|
||||
mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out);
|
||||
mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out);
|
||||
mWifiMulticastWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
|
||||
mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
|
||||
mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
|
||||
for (int i=0; i<NUM_WIFI_STATES; i++) {
|
||||
@@ -13540,6 +13575,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in);
|
||||
mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in);
|
||||
mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in);
|
||||
mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, -4, null,
|
||||
mOnBatteryTimeBase, in);
|
||||
mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
|
||||
mWifiOn = false;
|
||||
mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in);
|
||||
@@ -13746,6 +13783,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mMobileRadioActiveAdjustedTime.writeToParcel(out);
|
||||
mMobileRadioActiveUnknownTime.writeToParcel(out);
|
||||
mMobileRadioActiveUnknownCount.writeToParcel(out);
|
||||
mWifiMulticastWakelockTimer.writeToParcel(out, uSecRealtime);
|
||||
mWifiOnTimer.writeToParcel(out, uSecRealtime);
|
||||
mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime);
|
||||
for (int i=0; i<NUM_WIFI_STATES; i++) {
|
||||
@@ -13932,6 +13970,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mMobileRadioActiveTimer.logState(pr, " ");
|
||||
pr.println("*** Mobile network active adjusted timer:");
|
||||
mMobileRadioActiveAdjustedTime.logState(pr, " ");
|
||||
pr.println("*** Wifi Multicast WakeLock Timer:");
|
||||
mWifiMulticastWakelockTimer.logState(pr, " ");
|
||||
pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState);
|
||||
pr.println("*** Wifi timer:");
|
||||
mWifiOnTimer.logState(pr, " ");
|
||||
|
||||
Reference in New Issue
Block a user