Merge \"Record UID of wakeup packets\" into nyc-mr1-dev

am: 117cf8de91

Change-Id: Id4e843eef00a623353fe3027de13460aa92e699f
This commit is contained in:
Adam Lesinski
2016-07-18 21:15:48 +00:00
committed by android-build-merger
5 changed files with 207 additions and 29 deletions

View File

@@ -546,6 +546,20 @@ public abstract class BatteryStats implements Parcelable {
*/
public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
/**
* Returns the number of times this UID woke up the Application Processor to
* process a mobile radio packet.
* @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
*/
public abstract long getMobileRadioApWakeupCount(int which);
/**
* Returns the number of times this UID woke up the Application Processor to
* process a WiFi packet.
* @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
*/
public abstract long getWifiRadioApWakeupCount(int which);
public static abstract class Sensor {
/*
* FIXME: it's not correct to use this magic value because it
@@ -1285,9 +1299,12 @@ public abstract class BatteryStats implements Parcelable {
public static final int EVENT_TEMP_WHITELIST = 0x0011;
// Event for the screen waking up.
public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
// Event for the UID that woke up the application processor.
// Used for wakeups coming from WiFi, modem, etc.
public static final int EVENT_WAKEUP_AP = 0x0013;
// Number of event types.
public static final int EVENT_COUNT = 0x0013;
public static final int EVENT_COUNT = 0x0014;
// Mask to extract out only the type part of the event.
public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
@@ -1979,13 +1996,13 @@ public abstract class BatteryStats implements Parcelable {
public static final String[] HISTORY_EVENT_NAMES = new String[] {
"null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
"active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
"screenwake",
"screenwake", "wakeupap"
};
public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
"Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
"Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
"Esw",
"Esw", "Ewa"
};
/**
@@ -3105,20 +3122,22 @@ public abstract class BatteryStats implements Parcelable {
final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
final long mobileActiveTime = u.getMobileRadioActiveTime(which);
final int mobileActiveCount = u.getMobileRadioActiveCount(which);
final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
|| mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
|| wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
|| btBytesRx > 0 || btBytesTx > 0) {
|| btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
wifiBytesRx, wifiBytesTx,
mobilePacketsRx, mobilePacketsTx,
wifiPacketsRx, wifiPacketsTx,
mobileActiveTime, mobileActiveCount,
btBytesRx, btBytesTx);
btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
}
// Dump modem controller data, per UID.
@@ -4125,6 +4144,9 @@ public abstract class BatteryStats implements Parcelable {
final int wifiScanCount = u.getWifiScanCount(which);
final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
if (mobileRxBytes > 0 || mobileTxBytes > 0
|| mobileRxPackets > 0 || mobileTxPackets > 0) {
pw.print(prefix); pw.print(" Mobile network: ");
@@ -4150,6 +4172,14 @@ public abstract class BatteryStats implements Parcelable {
pw.println(sb.toString());
}
if (mobileWakeup > 0) {
sb.setLength(0);
sb.append(prefix);
sb.append(" Mobile radio AP wakeups: ");
sb.append(mobileWakeup);
pw.println(sb.toString());
}
printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
u.getModemControllerActivity(), which);
@@ -4181,6 +4211,14 @@ public abstract class BatteryStats implements Parcelable {
pw.println(sb.toString());
}
if (wifiWakeup > 0) {
sb.setLength(0);
sb.append(prefix);
sb.append(" WiFi AP wakeups: ");
sb.append(wifiWakeup);
pw.println(sb.toString());
}
printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
u.getWifiControllerActivity(), which);

View File

@@ -118,7 +118,7 @@ interface IBatteryStats {
void noteWifiBatchedScanStoppedFromSource(in WorkSource ws);
void noteWifiMulticastEnabledFromSource(in WorkSource ws);
void noteWifiMulticastDisabledFromSource(in WorkSource ws);
void noteWifiRadioPowerState(int powerState, long timestampNs);
void noteWifiRadioPowerState(int powerState, long timestampNs, int uid);
void noteNetworkInterfaceType(String iface, int type);
void noteNetworkStatsEnabled();
void noteDeviceIdleMode(int mode, String activeReason, int activeUid);

View File

@@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats {
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// Current on-disk Parcel version
private static final int VERSION = 147 + (USE_OLD_HISTORY ? 1000 : 0);
private static final int VERSION = 148 + (USE_OLD_HISTORY ? 1000 : 0);
// Maximum number of items we will record in the history.
private static final int MAX_HISTORY_ITEMS = 2000;
@@ -3554,6 +3554,14 @@ public class BatteryStatsImpl extends BatteryStats {
mNumConnectivityChange++;
}
private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis,
final long uptimeMillis, int uid) {
uid = mapUid(uid);
addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "",
uid);
getUidStatsLocked(uid).noteMobileRadioApWakeupLocked();
}
public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) {
final long elapsedRealtime = mClocks.elapsedRealtime();
final long uptime = mClocks.uptimeMillis();
@@ -3563,6 +3571,10 @@ public class BatteryStatsImpl extends BatteryStats {
powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM
|| powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH;
if (active) {
if (uid > 0) {
noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid);
}
mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000);
mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG;
} else {
@@ -4239,7 +4251,15 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
public void noteWifiRadioPowerState(int powerState, long timestampNs) {
private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis,
final long uptimeMillis, int uid) {
uid = mapUid(uid);
addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "",
uid);
getUidStatsLocked(uid).noteWifiRadioApWakeupLocked();
}
public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) {
final long elapsedRealtime = mClocks.elapsedRealtime();
final long uptime = mClocks.uptimeMillis();
if (mWifiRadioPowerState != powerState) {
@@ -4247,6 +4267,9 @@ public class BatteryStatsImpl extends BatteryStats {
powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM
|| powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH;
if (active) {
if (uid > 0) {
noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid);
}
mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG;
} else {
mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG;
@@ -4874,6 +4897,33 @@ public class BatteryStatsImpl extends BatteryStats {
return mUidStats;
}
private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) {
if (timer != null) {
timer.detach();
}
}
private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer,
boolean detachIfReset) {
if (timer != null) {
return timer.reset(detachIfReset);
}
return true;
}
private static void detachLongCounterIfNotNull(LongSamplingCounter counter) {
if (counter != null) {
counter.detach();
}
}
private static void resetLongCounterIfNotNull(LongSamplingCounter counter,
boolean detachIfReset) {
if (counter != null) {
counter.reset(detachIfReset);
}
}
/**
* The statistics associated with a particular uid.
*/
@@ -4920,6 +4970,16 @@ public class BatteryStatsImpl extends BatteryStats {
LongSamplingCounter mMobileRadioActiveTime;
LongSamplingCounter mMobileRadioActiveCount;
/**
* How many times this UID woke up the Application Processor due to a Mobile radio packet.
*/
private LongSamplingCounter mMobileRadioApWakeupCount;
/**
* How many times this UID woke up the Application Processor due to a Wifi packet.
*/
private LongSamplingCounter mWifiRadioApWakeupCount;
/**
* The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode.
* Can be null if the UID has had no such activity.
@@ -5629,6 +5689,36 @@ public class BatteryStatsImpl extends BatteryStats {
return 0;
}
public void noteMobileRadioApWakeupLocked() {
if (mMobileRadioApWakeupCount == null) {
mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase);
}
mMobileRadioApWakeupCount.addCountLocked(1);
}
@Override
public long getMobileRadioApWakeupCount(int which) {
if (mMobileRadioApWakeupCount != null) {
return mMobileRadioApWakeupCount.getCountLocked(which);
}
return 0;
}
public void noteWifiRadioApWakeupLocked() {
if (mWifiRadioApWakeupCount == null) {
mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase);
}
mWifiRadioApWakeupCount.addCountLocked(1);
}
@Override
public long getWifiRadioApWakeupCount(int which) {
if (mWifiRadioApWakeupCount != null) {
return mWifiRadioApWakeupCount.getCountLocked(which);
}
return 0;
}
void initNetworkActivityLocked() {
mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES];
mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES];
@@ -5671,24 +5761,14 @@ public class BatteryStatsImpl extends BatteryStats {
active |= !mWifiMulticastTimer.reset(false);
active |= mWifiMulticastEnabled;
}
if (mAudioTurnedOnTimer != null) {
active |= !mAudioTurnedOnTimer.reset(false);
}
if (mVideoTurnedOnTimer != null) {
active |= !mVideoTurnedOnTimer.reset(false);
}
if (mFlashlightTurnedOnTimer != null) {
active |= !mFlashlightTurnedOnTimer.reset(false);
}
if (mCameraTurnedOnTimer != null) {
active |= !mCameraTurnedOnTimer.reset(false);
}
if (mForegroundActivityTimer != null) {
active |= !mForegroundActivityTimer.reset(false);
}
if (mBluetoothScanTimer != null) {
active |= !mBluetoothScanTimer.reset(false);
}
active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false);
active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false);
active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false);
active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false);
active |= !resetTimerIfNotNull(mForegroundActivityTimer, false);
active |= !resetTimerIfNotNull(mBluetoothScanTimer, false);
if (mProcessStateTimer != null) {
for (int i = 0; i < NUM_PROCESS_STATE; i++) {
if (mProcessStateTimer[i] != null) {
@@ -5749,6 +5829,9 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false);
resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false);
final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap();
for (int iw=wakeStats.size()-1; iw>=0; iw--) {
Wakelock wl = wakeStats.valueAt(iw);
@@ -5908,6 +5991,9 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
}
detachLongCounterIfNotNull(mMobileRadioApWakeupCount);
detachLongCounterIfNotNull(mWifiRadioApWakeupCount);
}
return !active;
@@ -6114,6 +6200,20 @@ public class BatteryStatsImpl extends BatteryStats {
} else {
out.writeInt(0);
}
if (mMobileRadioApWakeupCount != null) {
out.writeInt(1);
mMobileRadioApWakeupCount.writeToParcel(out);
} else {
out.writeInt(0);
}
if (mWifiRadioApWakeupCount != null) {
out.writeInt(1);
mWifiRadioApWakeupCount.writeToParcel(out);
} else {
out.writeInt(0);
}
}
void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) {
@@ -6338,6 +6438,18 @@ public class BatteryStatsImpl extends BatteryStats {
} else {
mCpuClusterSpeed = null;
}
if (in.readInt() != 0) {
mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in);
} else {
mMobileRadioApWakeupCount = null;
}
if (in.readInt() != 0) {
mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in);
} else {
mWifiRadioApWakeupCount = null;
}
}
/**
@@ -10348,6 +10460,20 @@ public class BatteryStatsImpl extends BatteryStats {
u.mCpuClusterSpeed = null;
}
if (in.readInt() != 0) {
u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase);
u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in);
} else {
u.mMobileRadioApWakeupCount = null;
}
if (in.readInt() != 0) {
u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase);
u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in);
} else {
u.mWifiRadioApWakeupCount = null;
}
int NW = in.readInt();
if (NW > 100) {
throw new ParcelFormatException("File corrupt: too many wake locks " + NW);
@@ -10708,6 +10834,20 @@ public class BatteryStatsImpl extends BatteryStats {
out.writeInt(0);
}
if (u.mMobileRadioApWakeupCount != null) {
out.writeInt(1);
u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out);
} else {
out.writeInt(0);
}
if (u.mWifiRadioApWakeupCount != null) {
out.writeInt(1);
u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out);
} else {
out.writeInt(0);
}
final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap();
int NW = wakeStats.size();
out.writeInt(NW);

View File

@@ -494,7 +494,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
if (mLastPowerStateFromWifi != powerState) {
mLastPowerStateFromWifi = powerState;
try {
getBatteryStats().noteWifiRadioPowerState(powerState, tsNanos);
getBatteryStats().noteWifiRadioPowerState(powerState, tsNanos, uid);
} catch (RemoteException e) {
}
}

View File

@@ -710,7 +710,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
@Override
public void noteWifiRadioPowerState(int powerState, long tsNanos) {
public void noteWifiRadioPowerState(int powerState, long tsNanos, int uid) {
enforceCallingPermission();
// There was a change in WiFi power state.
@@ -723,7 +723,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
mHandler.scheduleSync("wifi-data: " + type,
BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI);
}
mStats.noteWifiRadioPowerState(powerState, tsNanos);
mStats.noteWifiRadioPowerState(powerState, tsNanos, uid);
}
}