Call Debug.getPss without a lock held am: 10e8f16add am: f10d31f5d0

am: 65fdd196fa

Change-Id: Ic41194d60d8919d69123bd40082c86b2a1e22571
This commit is contained in:
Amith Yamasani
2016-09-01 01:33:19 +00:00
committed by android-build-merger
2 changed files with 46 additions and 26 deletions

View File

@@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
public class ProcessCpuTracker {
@@ -177,6 +178,11 @@ public class ProcessCpuTracker {
private byte[] mBuffer = new byte[4096];
public interface FilterStats {
/** Which stats to pick when filtering */
boolean needed(Stats stats);
}
public static class Stats {
public final int pid;
public final int uid;
@@ -695,6 +701,18 @@ public class ProcessCpuTracker {
return mProcStats.get(index);
}
final public List<Stats> getStats(FilterStats filter) {
final ArrayList<Stats> statses = new ArrayList<>(mProcStats.size());
final int N = mProcStats.size();
for (int p = 0; p < N; p++) {
Stats stats = mProcStats.get(p);
if (filter.needed(stats)) {
statses.add(stats);
}
}
return statses;
}
final public int countWorkingStats() {
buildWorkingProcs();
return mWorkingProcs.size();

View File

@@ -2397,22 +2397,21 @@ public final class ActivityManagerService extends ActivityManagerNative
if (memInfo != null) {
updateCpuStatsNow();
long nativeTotalPss = 0;
final List<ProcessCpuTracker.Stats> stats;
synchronized (mProcessCpuTracker) {
final int N = mProcessCpuTracker.countStats();
for (int j=0; j<N; j++) {
ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(j);
if (st.vsize <= 0 || st.uid >= Process.FIRST_APPLICATION_UID) {
// This is definitely an application process; skip it.
stats = mProcessCpuTracker.getStats( (st)-> {
return st.vsize > 0 && st.uid < Process.FIRST_APPLICATION_UID;
});
}
final int N = stats.size();
for (int j = 0; j < N; j++) {
synchronized (mPidsSelfLocked) {
if (mPidsSelfLocked.indexOfKey(stats.get(j).pid) >= 0) {
// This is one of our own processes; skip it.
continue;
}
synchronized (mPidsSelfLocked) {
if (mPidsSelfLocked.indexOfKey(st.pid) >= 0) {
// This is one of our own processes; skip it.
continue;
}
}
nativeTotalPss += Debug.getPss(st.pid, null, null);
}
nativeTotalPss += Debug.getPss(stats.get(j).pid, null, null);
}
memInfo.readMemInfo();
synchronized (ActivityManagerService.this) {
@@ -16505,21 +16504,24 @@ public final class ActivityManagerService extends ActivityManagerNative
}
updateCpuStatsNow();
long[] memtrackTmp = new long[1];
final List<ProcessCpuTracker.Stats> stats;
// Get a list of Stats that have vsize > 0
synchronized (mProcessCpuTracker) {
final int N = mProcessCpuTracker.countStats();
for (int i=0; i<N; i++) {
ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
if (st.vsize > 0) {
long pss = Debug.getPss(st.pid, null, memtrackTmp);
if (pss > 0) {
if (infoMap.indexOfKey(st.pid) < 0) {
ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid,
ProcessList.NATIVE_ADJ, -1, "native", null);
mi.pss = pss;
mi.memtrack = memtrackTmp[0];
memInfos.add(mi);
}
}
stats = mProcessCpuTracker.getStats((st) -> {
return st.vsize > 0;
});
}
final int statsCount = stats.size();
for (int i = 0; i < statsCount; i++) {
ProcessCpuTracker.Stats st = stats.get(i);
long pss = Debug.getPss(st.pid, null, memtrackTmp);
if (pss > 0) {
if (infoMap.indexOfKey(st.pid) < 0) {
ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid,
ProcessList.NATIVE_ADJ, -1, "native", null);
mi.pss = pss;
mi.memtrack = memtrackTmp[0];
memInfos.add(mi);
}
}
}