am fe45b29a: Merge "BatteryStats: Remove isolated UIDs from /proc/uid_cputime when they are not in use anymore" into mnc-dev
* commit 'fe45b29a1cce45b47f648cbff2b7d65890f1d638': BatteryStats: Remove isolated UIDs from /proc/uid_cputime when they are not in use anymore
This commit is contained in:
@@ -183,6 +183,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
public interface ExternalStatsSync {
|
public interface ExternalStatsSync {
|
||||||
void scheduleSync(String reason);
|
void scheduleSync(String reason);
|
||||||
void scheduleWifiSync(String reason);
|
void scheduleWifiSync(String reason);
|
||||||
|
void scheduleCpuSyncDueToRemovedUid(int uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final MyHandler mHandler;
|
public final MyHandler mHandler;
|
||||||
@@ -2522,13 +2523,28 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
mIsolatedUids.put(isolatedUid, appUid);
|
mIsolatedUids.put(isolatedUid, appUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeIsolatedUidLocked(int isolatedUid, int appUid) {
|
/**
|
||||||
|
* Schedules a read of the latest cpu times before removing the isolated UID.
|
||||||
|
* @see #removeIsolatedUidLocked(int)
|
||||||
|
*/
|
||||||
|
public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) {
|
||||||
int curUid = mIsolatedUids.get(isolatedUid, -1);
|
int curUid = mIsolatedUids.get(isolatedUid, -1);
|
||||||
if (curUid == appUid) {
|
if (curUid == appUid) {
|
||||||
mIsolatedUids.delete(isolatedUid);
|
if (mExternalSync != null) {
|
||||||
|
mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This should only be called after the cpu times have been read.
|
||||||
|
* @see #scheduleRemoveIsolatedUidLocked(int, int)
|
||||||
|
*/
|
||||||
|
public void removeIsolatedUidLocked(int isolatedUid) {
|
||||||
|
mIsolatedUids.delete(isolatedUid);
|
||||||
|
mKernelUidCpuTimeReader.removeUid(isolatedUid);
|
||||||
|
}
|
||||||
|
|
||||||
public int mapUid(int uid) {
|
public int mapUid(int uid) {
|
||||||
int isolated = mIsolatedUids.get(uid, -1);
|
int isolated = mIsolatedUids.get(uid, -1);
|
||||||
return isolated > 0 ? isolated : uid;
|
return isolated > 0 ? isolated : uid;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import android.os.WorkSource;
|
|||||||
import android.telephony.DataConnectionRealTimeInfo;
|
import android.telephony.DataConnectionRealTimeInfo;
|
||||||
import android.telephony.SignalStrength;
|
import android.telephony.SignalStrength;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.IntArray;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import android.util.TimeUtils;
|
import android.util.TimeUtils;
|
||||||
@@ -82,6 +83,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
public static final int MSG_SYNC_EXTERNAL_STATS = 1;
|
public static final int MSG_SYNC_EXTERNAL_STATS = 1;
|
||||||
public static final int MSG_WRITE_TO_DISK = 2;
|
public static final int MSG_WRITE_TO_DISK = 2;
|
||||||
private int mUpdateFlags = 0;
|
private int mUpdateFlags = 0;
|
||||||
|
private IntArray mUidsToRemove = new IntArray();
|
||||||
|
|
||||||
public BatteryStatsHandler(Looper looper) {
|
public BatteryStatsHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -98,6 +100,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
mUpdateFlags = 0;
|
mUpdateFlags = 0;
|
||||||
}
|
}
|
||||||
updateExternalStats((String)msg.obj, updateFlags);
|
updateExternalStats((String)msg.obj, updateFlags);
|
||||||
|
synchronized (this) {
|
||||||
|
synchronized (mStats) {
|
||||||
|
final int numUidsToRemove = mUidsToRemove.size();
|
||||||
|
for (int i = 0; i < numUidsToRemove; i++) {
|
||||||
|
mStats.removeIsolatedUidLocked(mUidsToRemove.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mUidsToRemove.clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_WRITE_TO_DISK:
|
case MSG_WRITE_TO_DISK:
|
||||||
@@ -111,22 +122,32 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scheduleSync(String reason) {
|
public void scheduleSync(String reason) {
|
||||||
scheduleSyncImpl(reason, UPDATE_ALL);
|
synchronized (this) {
|
||||||
|
scheduleSyncLocked(reason, UPDATE_ALL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scheduleWifiSync(String reason) {
|
public void scheduleWifiSync(String reason) {
|
||||||
scheduleSyncImpl(reason, UPDATE_WIFI);
|
synchronized (this) {
|
||||||
|
scheduleSyncLocked(reason, UPDATE_WIFI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleSyncImpl(String reason, int updateFlags) {
|
@Override
|
||||||
|
public void scheduleCpuSyncDueToRemovedUid(int uid) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (mUpdateFlags == 0) {
|
scheduleSyncLocked("remove-uid", UPDATE_CPU);
|
||||||
sendMessage(Message.obtain(this, MSG_SYNC_EXTERNAL_STATS, reason));
|
mUidsToRemove.add(uid);
|
||||||
}
|
|
||||||
mUpdateFlags |= updateFlags;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scheduleSyncLocked(String reason, int updateFlags) {
|
||||||
|
if (mUpdateFlags == 0) {
|
||||||
|
sendMessage(Message.obtain(this, MSG_SYNC_EXTERNAL_STATS, reason));
|
||||||
|
}
|
||||||
|
mUpdateFlags |= updateFlags;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BatteryStatsService(File systemDir, Handler handler) {
|
BatteryStatsService(File systemDir, Handler handler) {
|
||||||
@@ -220,7 +241,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
|
|
||||||
void removeIsolatedUid(int isolatedUid, int appUid) {
|
void removeIsolatedUid(int isolatedUid, int appUid) {
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
mStats.removeIsolatedUidLocked(isolatedUid, appUid);
|
mStats.scheduleRemoveIsolatedUidLocked(isolatedUid, appUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user