diff options
| -rw-r--r-- | core/java/android/os/BatteryStats.java | 111 | ||||
| -rw-r--r-- | core/java/com/android/internal/os/BatteryStatsImpl.java | 5 | ||||
| -rw-r--r-- | core/proto/android/os/batterystats.proto | 20 |
3 files changed, 131 insertions, 5 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index af91e81959d1..811091e37da2 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -224,6 +224,7 @@ public abstract class BatteryStats implements Parcelable { * - Always On Display (screen doze mode) time and power * New in version 28: * - Light/Deep Doze power + * - WiFi Multicast Wakelock statistics (count & duration) */ static final int CHECKIN_VERSION = 28; @@ -313,6 +314,8 @@ public abstract class BatteryStats implements Parcelable { private static final String CAMERA_DATA = "cam"; private static final String VIDEO_DATA = "vid"; private static final String AUDIO_DATA = "aud"; + private static final String WIFI_MULTICAST_TOTAL_DATA = "wmct"; + private static final String WIFI_MULTICAST_DATA = "wmc"; public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; @@ -516,6 +519,13 @@ public abstract class BatteryStats implements Parcelable { public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); /** + * Returns the WiFi Multicast Wakelock statistics. + * + * @return a Timer Object for the per uid Multicast statistics. + */ + public abstract Timer getMulticastWakelockStats(); + + /** * Returns a mapping containing sync statistics. * * @return a Map from Strings to Timer objects. @@ -3363,13 +3373,16 @@ public abstract class BatteryStats implements Parcelable { screenDozeTime / 1000); - // Calculate wakelock times across all uids. + // Calculate both wakelock and wifi multicast 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--) { @@ -3387,6 +3400,13 @@ 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 @@ -3502,6 +3522,11 @@ public abstract class BatteryStats implements Parcelable { } dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); + // Dump Multicast total stats + dumpLine(pw, 0 /* uid */, category, WIFI_MULTICAST_TOTAL_DATA, + multicastWakeLockTimeTotalMicros / 1000, + multicastWakeLockCountTotal); + if (which == STATS_SINCE_UNPLUGGED) { dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), getDischargeCurrentLevel()); @@ -3828,6 +3853,18 @@ public abstract class BatteryStats implements Parcelable { } } + // WiFi Multicast Wakelock Statistics + final Timer mcTimer = u.getMulticastWakelockStats(); + if (mcTimer != null) { + final long totalMcWakelockTimeMs = + mcTimer.getTotalTimeLocked(rawRealtime, which) / 1000 ; + final int countMcWakelock = mcTimer.getCountLocked(which); + if(totalMcWakelockTimeMs > 0) { + dumpLine(pw, uid, category, WIFI_MULTICAST_DATA, + totalMcWakelockTimeMs, countMcWakelock); + } + } + final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); for (int isy=syncs.size()-1; isy>=0; isy--) { final Timer timer = syncs.valueAt(isy); @@ -4327,15 +4364,18 @@ public abstract class BatteryStats implements Parcelable { pw.print(" Connectivity changes: "); pw.println(connChanges); } - // Calculate wakelock times across all uids. + // Calculate both wakelock and wifi multicast 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--) { @@ -4363,6 +4403,13 @@ 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); @@ -4392,6 +4439,20 @@ public abstract class BatteryStats implements Parcelable { pw.println(sb.toString()); } + if (multicastWakeLockTimeTotalMicros != 0) { + sb.setLength(0); + sb.append(prefix); + sb.append(" Total WiFi Multicast wakelock Count: "); + sb.append(multicastWakeLockCountTotal); + pw.println(sb.toString()); + + sb.setLength(0); + sb.append(prefix); + sb.append(" Total WiFi Multicast wakelock time: "); + formatTimeMsNoSpace(sb, (multicastWakeLockTimeTotalMicros + 500) / 1000); + pw.println(sb.toString()); + } + pw.println(""); pw.print(prefix); sb.setLength(0); @@ -5309,6 +5370,24 @@ public abstract class BatteryStats implements Parcelable { } } + // Calculate multicast wakelock stats + final Timer mcTimer = u.getMulticastWakelockStats(); + if (mcTimer != null) { + final long multicastWakeLockTimeMicros = mcTimer.getTotalTimeLocked(rawRealtime, which); + final int multicastWakeLockCount = mcTimer.getCountLocked(which); + + if (multicastWakeLockTimeMicros > 0) { + sb.setLength(0); + sb.append(prefix); + sb.append(" WiFi Multicast Wakelock"); + sb.append(" count = "); + sb.append(multicastWakeLockCount); + sb.append(" time = "); + formatTimeMsNoSpace(sb, (multicastWakeLockTimeMicros + 500) / 1000); + pw.println(sb.toString()); + } + } + final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); for (int isy=syncs.size()-1; isy>=0; isy--) { final Timer timer = syncs.valueAt(isy); @@ -7085,6 +7164,10 @@ public abstract class BatteryStats implements Parcelable { proto.end(wToken); } + // Wifi Multicast Wakelock (WIFI_MULTICAST_WAKELOCK_DATA) + dumpTimer(proto, UidProto.WIFI_MULTICAST_WAKELOCK, u.getMulticastWakelockStats(), + rawRealtimeUs, which); + // Wakeup alarms (WAKEUP_ALARM_DATA) for (int ipkg = packageStats.size() - 1; ipkg >= 0; --ipkg) { final Uid.Pkg ps = packageStats.valueAt(ipkg); @@ -7341,6 +7424,30 @@ public abstract class BatteryStats implements Parcelable { getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); 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 wmctToken = proto.start(SystemProto.WIFI_MULTICAST_WAKELOCK_TOTAL); + proto.write(SystemProto.WifiMulticastWakelockTotal.DURATION_MS, + multicastWakeLockTimeTotalUs / 1000); + proto.write(SystemProto.WifiMulticastWakelockTotal.COUNT, + multicastWakeLockCountTotal); + proto.end(wmctToken); + // Power use item (POWER_USE_ITEM_DATA) final List<BatterySipper> sippers = helper.getUsageList(); if (sippers != null) { diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 6ede72d49806..56d0bb229b80 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -6020,6 +6020,11 @@ public class BatteryStatsImpl extends BatteryStats { } @Override + public Timer getMulticastWakelockStats() { + return mWifiMulticastTimer; + } + + @Override public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { return mSyncStats.getMap(); } diff --git a/core/proto/android/os/batterystats.proto b/core/proto/android/os/batterystats.proto index 0a3344fe13f1..cff187992fdb 100644 --- a/core/proto/android/os/batterystats.proto +++ b/core/proto/android/os/batterystats.proto @@ -395,6 +395,12 @@ message SystemProto { }; repeated WakeupReason wakeup_reason = 22; + message WifiMulticastWakelockTotal { + optional int64 duration_ms = 1; + optional int32 count = 2; + } + optional WifiMulticastWakelockTotal wifi_multicast_wakelock_total = 23; + message WifiSignalStrength { enum Name { NONE = 0; @@ -406,7 +412,7 @@ message SystemProto { optional Name name = 1; optional TimerProto total = 2; }; - repeated WifiSignalStrength wifi_signal_strength = 23; + repeated WifiSignalStrength wifi_signal_strength = 24; message WifiState { enum Name { @@ -422,7 +428,7 @@ message SystemProto { optional Name name = 1; optional TimerProto total = 2; }; - repeated WifiState wifi_state = 24; + repeated WifiState wifi_state = 25; message WifiSupplicantState { enum Name { @@ -443,7 +449,7 @@ message SystemProto { optional Name name = 1; optional TimerProto total = 2; }; - repeated WifiSupplicantState wifi_supplicant_state = 25; + repeated WifiSupplicantState wifi_supplicant_state = 26; } message TimerProto { @@ -775,4 +781,12 @@ message UidProto { optional TimerProto background_scan = 4; }; optional Wifi wifi = 27; + + // WiFi Multicast Wakelock + // This timer tracks the duration and count for the app to request the + // wakelock for wifi multicast traffic. + // This wakelock disables the filtering of multicast packets to reach the host + // processor, and results in a power penalty. + // It is useful to monitor the applications resulting in that + optional TimerProto wifi_multicast_wakelock = 28; } |