Merge "Work on issue #30407061: OverflowArrayMap.stopObject unable to find object" into nyc-mr1-dev

This commit is contained in:
Dianne Hackborn
2016-07-30 00:03:37 +00:00
committed by Android (Google) Code Review

View File

@@ -1791,11 +1791,17 @@ public class BatteryStatsImpl extends BatteryStats {
public abstract class OverflowArrayMap<T> { public abstract class OverflowArrayMap<T> {
private static final String OVERFLOW_NAME = "*overflow*"; private static final String OVERFLOW_NAME = "*overflow*";
final int mUid;
final ArrayMap<String, T> mMap = new ArrayMap<>(); final ArrayMap<String, T> mMap = new ArrayMap<>();
T mCurOverflow; T mCurOverflow;
ArrayMap<String, MutableInt> mActiveOverflow; ArrayMap<String, MutableInt> mActiveOverflow;
long mLastOverflowTime;
long mLastOverflowFinishTime;
long mLastClearTime;
long mLastCleanupTime;
public OverflowArrayMap() { public OverflowArrayMap(int uid) {
mUid = uid;
} }
public ArrayMap<String, T> getMap() { public ArrayMap<String, T> getMap() {
@@ -1803,6 +1809,7 @@ public class BatteryStatsImpl extends BatteryStats {
} }
public void clear() { public void clear() {
mLastClearTime = SystemClock.elapsedRealtime();
mMap.clear(); mMap.clear();
mCurOverflow = null; mCurOverflow = null;
mActiveOverflow = null; mActiveOverflow = null;
@@ -1819,6 +1826,7 @@ public class BatteryStatsImpl extends BatteryStats {
} }
public void cleanup() { public void cleanup() {
mLastCleanupTime = SystemClock.elapsedRealtime();
if (mActiveOverflow != null) { if (mActiveOverflow != null) {
if (mActiveOverflow.size() == 0) { if (mActiveOverflow.size() == 0) {
mActiveOverflow = null; mActiveOverflow = null;
@@ -1885,6 +1893,7 @@ public class BatteryStatsImpl extends BatteryStats {
mActiveOverflow = new ArrayMap<>(); mActiveOverflow = new ArrayMap<>();
} }
mActiveOverflow.put(name, new MutableInt(1)); mActiveOverflow.put(name, new MutableInt(1));
mLastOverflowTime = SystemClock.elapsedRealtime();
return obj; return obj;
} }
@@ -1914,6 +1923,7 @@ public class BatteryStatsImpl extends BatteryStats {
over.value--; over.value--;
if (over.value <= 0) { if (over.value <= 0) {
mActiveOverflow.remove(name); mActiveOverflow.remove(name);
mLastOverflowFinishTime = SystemClock.elapsedRealtime();
} }
return obj; return obj;
} }
@@ -1922,9 +1932,35 @@ public class BatteryStatsImpl extends BatteryStats {
// Huh, they are stopping an active operation but we can't find one! // Huh, they are stopping an active operation but we can't find one!
// That's not good. // That's not good.
Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" StringBuilder sb = new StringBuilder();
+ mMap.size() + " activeoverflow=" + mActiveOverflow sb.append("Unable to find object for ");
+ " curoverflow=" + mCurOverflow); sb.append(name);
sb.append(" in uid ");
sb.append(mUid);
sb.append(" mapsize=");
sb.append(mMap.size());
sb.append(" activeoverflow=");
sb.append(mActiveOverflow);
sb.append(" curoverflow=");
sb.append(mCurOverflow);
long now = SystemClock.elapsedRealtime();
if (mLastOverflowTime != 0) {
sb.append(" lastOverflowTime=");
TimeUtils.formatDuration(mLastOverflowTime-now, sb);
}
if (mLastOverflowFinishTime != 0) {
sb.append(" lastOverflowFinishTime=");
TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb);
}
if (mLastClearTime != 0) {
sb.append(" lastClearTime=");
TimeUtils.formatDuration(mLastClearTime-now, sb);
}
if (mLastCleanupTime != 0) {
sb.append(" lastCleanupTime=");
TimeUtils.formatDuration(mLastCleanupTime-now, sb);
}
Slog.wtf(TAG, sb.toString());
return null; return null;
} }
@@ -5084,18 +5120,18 @@ public class BatteryStatsImpl extends BatteryStats {
mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase);
mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase);
mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>() { mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) {
@Override public Wakelock instantiateObject() { @Override public Wakelock instantiateObject() {
return new Wakelock(mBsi, Uid.this); return new Wakelock(mBsi, Uid.this);
} }
}; };
mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) {
@Override public StopwatchTimer instantiateObject() { @Override public StopwatchTimer instantiateObject() {
return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null,
mBsi.mOnBatteryTimeBase); mBsi.mOnBatteryTimeBase);
} }
}; };
mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) {
@Override public StopwatchTimer instantiateObject() { @Override public StopwatchTimer instantiateObject() {
return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null,
mBsi.mOnBatteryTimeBase); mBsi.mOnBatteryTimeBase);