use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by AOSPA.
the class ProcessStats method computeTotalMemoryUse.
public void computeTotalMemoryUse(TotalMemoryUseCollection data, long now) {
data.totalTime = 0;
for (int i = 0; i < STATE_COUNT; i++) {
data.processStateWeight[i] = 0;
data.processStatePss[i] = 0;
data.processStateTime[i] = 0;
data.processStateSamples[i] = 0;
}
for (int i = 0; i < SYS_MEM_USAGE_COUNT; i++) {
data.sysMemUsage[i] = 0;
}
data.sysMemCachedWeight = 0;
data.sysMemFreeWeight = 0;
data.sysMemZRamWeight = 0;
data.sysMemKernelWeight = 0;
data.sysMemNativeWeight = 0;
data.sysMemSamples = 0;
final long[] totalMemUsage = mSysMemUsage.getTotalMemUsage();
for (int is = 0; is < data.screenStates.length; is++) {
for (int im = 0; im < data.memStates.length; im++) {
int memBucket = data.screenStates[is] + data.memStates[im];
int stateBucket = memBucket * STATE_COUNT;
long memTime = mMemFactorDurations[memBucket];
if (mMemFactor == memBucket) {
memTime += now - mStartTime;
}
data.totalTime += memTime;
final int sysKey = mSysMemUsage.getKey((byte) stateBucket);
long[] longs = totalMemUsage;
int idx = 0;
if (sysKey != SparseMappingTable.INVALID_KEY) {
final long[] tmpLongs = mSysMemUsage.getArrayForKey(sysKey);
final int tmpIndex = SparseMappingTable.getIndexFromKey(sysKey);
if (tmpLongs[tmpIndex + SYS_MEM_USAGE_SAMPLE_COUNT] >= 3) {
SysMemUsageTable.mergeSysMemUsage(data.sysMemUsage, 0, longs, idx);
longs = tmpLongs;
idx = tmpIndex;
}
}
data.sysMemCachedWeight += longs[idx + SYS_MEM_USAGE_CACHED_AVERAGE] * (double) memTime;
data.sysMemFreeWeight += longs[idx + SYS_MEM_USAGE_FREE_AVERAGE] * (double) memTime;
data.sysMemZRamWeight += longs[idx + SYS_MEM_USAGE_ZRAM_AVERAGE] * (double) memTime;
data.sysMemKernelWeight += longs[idx + SYS_MEM_USAGE_KERNEL_AVERAGE] * (double) memTime;
data.sysMemNativeWeight += longs[idx + SYS_MEM_USAGE_NATIVE_AVERAGE] * (double) memTime;
data.sysMemSamples += longs[idx + SYS_MEM_USAGE_SAMPLE_COUNT];
}
}
data.hasSwappedOutPss = mHasSwappedOutPss;
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
for (int iproc = 0; iproc < procMap.size(); iproc++) {
SparseArray<ProcessState> uids = procMap.valueAt(iproc);
for (int iu = 0; iu < uids.size(); iu++) {
final ProcessState proc = uids.valueAt(iu);
proc.aggregatePss(data, now);
}
}
}
use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by AOSPA.
the class ProcessStats method dumpCheckinLocked.
public void dumpCheckinLocked(PrintWriter pw, String reqPackage) {
final long now = SystemClock.uptimeMillis();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
pw.println("vers,5");
pw.print("period,");
pw.print(mTimePeriodStartClockStr);
pw.print(",");
pw.print(mTimePeriodStartRealtime);
pw.print(",");
pw.print(mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
boolean partial = true;
if ((mFlags & FLAG_SHUTDOWN) != 0) {
pw.print(",shutdown");
partial = false;
}
if ((mFlags & FLAG_SYSPROPS) != 0) {
pw.print(",sysprops");
partial = false;
}
if ((mFlags & FLAG_COMPLETE) != 0) {
pw.print(",complete");
partial = false;
}
if (partial) {
pw.print(",partial");
}
if (mHasSwappedOutPss) {
pw.print(",swapped-out-pss");
}
pw.println();
pw.print("config,");
pw.println(mRuntime);
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
if (reqPackage != null && !reqPackage.equals(pkgName)) {
continue;
}
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
final int vers = vpkgs.keyAt(iv);
final PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
final int NSRVS = pkgState.mServices.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
proc.dumpPackageProcCheckin(pw, pkgName, uid, vers, pkgState.mProcesses.keyAt(iproc), now);
}
for (int isvc = 0; isvc < NSRVS; isvc++) {
final String serviceName = DumpUtils.collapseString(pkgName, pkgState.mServices.keyAt(isvc));
final ServiceState svc = pkgState.mServices.valueAt(isvc);
svc.dumpTimesCheckin(pw, pkgName, uid, vers, serviceName, now);
}
}
}
}
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
for (int ip = 0; ip < procMap.size(); ip++) {
String procName = procMap.keyAt(ip);
SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final ProcessState procState = uids.valueAt(iu);
procState.dumpProcCheckin(pw, procName, uid, now);
}
}
pw.print("total");
DumpUtils.dumpAdjTimesCheckin(pw, ",", mMemFactorDurations, mMemFactor, mStartTime, now);
pw.println();
final int sysMemUsageCount = mSysMemUsage.getKeyCount();
if (sysMemUsageCount > 0) {
pw.print("sysmemusage");
for (int i = 0; i < sysMemUsageCount; i++) {
final int key = mSysMemUsage.getKeyAt(i);
final int type = SparseMappingTable.getIdFromKey(key);
pw.print(",");
DumpUtils.printProcStateTag(pw, type);
for (int j = SYS_MEM_USAGE_SAMPLE_COUNT; j < SYS_MEM_USAGE_COUNT; j++) {
if (j > SYS_MEM_USAGE_CACHED_MINIMUM) {
pw.print(":");
}
pw.print(mSysMemUsage.getValue(key, j));
}
}
}
pw.println();
TotalMemoryUseCollection totalMem = new TotalMemoryUseCollection(ALL_SCREEN_ADJ, ALL_MEM_ADJ);
computeTotalMemoryUse(totalMem, now);
pw.print("weights,");
pw.print(totalMem.totalTime);
pw.print(",");
pw.print(totalMem.sysMemCachedWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemFreeWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemZRamWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemKernelWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemNativeWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
for (int i = 0; i < STATE_COUNT; i++) {
pw.print(",");
pw.print(totalMem.processStateWeight[i]);
pw.print(":");
pw.print(totalMem.processStateSamples[i]);
}
pw.println();
final int NPAGETYPES = mPageTypeLabels.size();
for (int i = 0; i < NPAGETYPES; i++) {
pw.print("availablepages,");
pw.print(mPageTypeLabels.get(i));
pw.print(",");
pw.print(mPageTypeZones.get(i));
pw.print(",");
final int[] sizes = mPageTypeSizes.get(i);
final int N = sizes == null ? 0 : sizes.length;
for (int j = 0; j < N; j++) {
if (j != 0) {
pw.print(",");
}
pw.print(sizes[j]);
}
pw.println();
}
}
use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by AOSPA.
the class ProcessStats method resetSafely.
public void resetSafely() {
if (DEBUG)
Slog.d(TAG, "Safely resetting state of " + mTimePeriodStartClockStr);
resetCommon();
// First initialize use count of all common processes.
final long now = SystemClock.uptimeMillis();
final ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
for (int ip = procMap.size() - 1; ip >= 0; ip--) {
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
uids.valueAt(iu).tmpNumInUse = 0;
}
}
// Next reset or prune all per-package processes, and for the ones that are reset
// track this back to the common processes.
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = pkgMap.size() - 1; ip >= 0; ip--) {
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
for (int iv = vpkgs.size() - 1; iv >= 0; iv--) {
final PackageState pkgState = vpkgs.valueAt(iv);
for (int iproc = pkgState.mProcesses.size() - 1; iproc >= 0; iproc--) {
final ProcessState ps = pkgState.mProcesses.valueAt(iproc);
if (ps.isInUse()) {
ps.resetSafely(now);
ps.getCommonProcess().tmpNumInUse++;
ps.getCommonProcess().tmpFoundSubProc = ps;
} else {
pkgState.mProcesses.valueAt(iproc).makeDead();
pkgState.mProcesses.removeAt(iproc);
}
}
for (int isvc = pkgState.mServices.size() - 1; isvc >= 0; isvc--) {
final ServiceState ss = pkgState.mServices.valueAt(isvc);
if (ss.isInUse()) {
ss.resetSafely(now);
} else {
pkgState.mServices.removeAt(isvc);
}
}
if (pkgState.mProcesses.size() <= 0 && pkgState.mServices.size() <= 0) {
vpkgs.removeAt(iv);
}
}
if (vpkgs.size() <= 0) {
uids.removeAt(iu);
}
}
if (uids.size() <= 0) {
pkgMap.removeAt(ip);
}
}
// Finally prune out any common processes that are no longer in use.
for (int ip = procMap.size() - 1; ip >= 0; ip--) {
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = uids.size() - 1; iu >= 0; iu--) {
ProcessState ps = uids.valueAt(iu);
if (ps.isInUse() || ps.tmpNumInUse > 0) {
// using it).
if (!ps.isActive() && ps.isMultiPackage() && ps.tmpNumInUse == 1) {
// Here we go...
ps = ps.tmpFoundSubProc;
ps.makeStandalone();
uids.setValueAt(iu, ps);
} else {
ps.resetSafely(now);
}
} else {
ps.makeDead();
uids.removeAt(iu);
}
}
if (uids.size() <= 0) {
procMap.removeAt(ip);
}
}
mStartTime = now;
if (DEBUG)
Slog.d(TAG, "State reset; now " + mTimePeriodStartClockStr);
}
use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by AOSPA.
the class ProcessStats method dumpLocked.
public void dumpLocked(PrintWriter pw, String reqPackage, long now, boolean dumpSummary, boolean dumpAll, boolean activeOnly) {
long totalTime = DumpUtils.dumpSingleTime(null, null, mMemFactorDurations, mMemFactor, mStartTime, now);
boolean sepNeeded = false;
if (mSysMemUsage.getKeyCount() > 0) {
pw.println("System memory usage:");
mSysMemUsage.dump(pw, " ", ALL_SCREEN_ADJ, ALL_MEM_ADJ);
sepNeeded = true;
}
ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
boolean printedHeader = false;
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
final int vers = vpkgs.keyAt(iv);
final PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
final int NSRVS = pkgState.mServices.size();
final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
if (!pkgMatch) {
boolean procMatch = false;
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (reqPackage.equals(proc.getName())) {
procMatch = true;
break;
}
}
if (!procMatch) {
continue;
}
}
if (NPROCS > 0 || NSRVS > 0) {
if (!printedHeader) {
if (sepNeeded)
pw.println();
pw.println("Per-Package Stats:");
printedHeader = true;
sepNeeded = true;
}
pw.print(" * ");
pw.print(pkgName);
pw.print(" / ");
UserHandle.formatUid(pw, uid);
pw.print(" / v");
pw.print(vers);
pw.println(":");
}
if (!dumpSummary || dumpAll) {
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
pw.print(" (Not active: ");
pw.print(pkgState.mProcesses.keyAt(iproc));
pw.println(")");
continue;
}
pw.print(" Process ");
pw.print(pkgState.mProcesses.keyAt(iproc));
if (proc.getCommonProcess().isMultiPackage()) {
pw.print(" (multi, ");
} else {
pw.print(" (unique, ");
}
pw.print(proc.getDurationsBucketCount());
pw.print(" entries)");
pw.println(":");
proc.dumpProcessState(pw, " ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES, now);
proc.dumpPss(pw, " ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES);
proc.dumpInternalLocked(pw, " ", dumpAll);
}
} else {
ArrayList<ProcessState> procs = new ArrayList<ProcessState>();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
continue;
}
procs.add(proc);
}
DumpUtils.dumpProcessSummaryLocked(pw, " ", procs, ALL_SCREEN_ADJ, ALL_MEM_ADJ, NON_CACHED_PROC_STATES, now, totalTime);
}
for (int isvc = 0; isvc < NSRVS; isvc++) {
ServiceState svc = pkgState.mServices.valueAt(isvc);
if (!pkgMatch && !reqPackage.equals(svc.getProcessName())) {
continue;
}
if (activeOnly && !svc.isInUse()) {
pw.print(" (Not active: ");
pw.print(pkgState.mServices.keyAt(isvc));
pw.println(")");
continue;
}
if (dumpAll) {
pw.print(" Service ");
} else {
pw.print(" * ");
}
pw.print(pkgState.mServices.keyAt(isvc));
pw.println(":");
pw.print(" Process: ");
pw.println(svc.getProcessName());
svc.dumpStats(pw, " ", " ", " ", now, totalTime, dumpSummary, dumpAll);
}
}
}
}
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
printedHeader = false;
int numShownProcs = 0, numTotalProcs = 0;
for (int ip = 0; ip < procMap.size(); ip++) {
String procName = procMap.keyAt(ip);
SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
int uid = uids.keyAt(iu);
numTotalProcs++;
final ProcessState proc = uids.valueAt(iu);
if (proc.hasAnyData()) {
continue;
}
if (!proc.isMultiPackage()) {
continue;
}
if (reqPackage != null && !reqPackage.equals(procName) && !reqPackage.equals(proc.getPackage())) {
continue;
}
numShownProcs++;
if (sepNeeded) {
pw.println();
}
sepNeeded = true;
if (!printedHeader) {
pw.println("Multi-Package Common Processes:");
printedHeader = true;
}
if (activeOnly && !proc.isInUse()) {
pw.print(" (Not active: ");
pw.print(procName);
pw.println(")");
continue;
}
pw.print(" * ");
pw.print(procName);
pw.print(" / ");
UserHandle.formatUid(pw, uid);
pw.print(" (");
pw.print(proc.getDurationsBucketCount());
pw.print(" entries)");
pw.println(":");
proc.dumpProcessState(pw, " ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES, now);
proc.dumpPss(pw, " ", ALL_SCREEN_ADJ, ALL_MEM_ADJ, ALL_PROC_STATES);
proc.dumpInternalLocked(pw, " ", dumpAll);
}
}
if (dumpAll) {
pw.println();
pw.print(" Total procs: ");
pw.print(numShownProcs);
pw.print(" shown of ");
pw.print(numTotalProcs);
pw.println(" total");
}
if (sepNeeded) {
pw.println();
}
if (dumpSummary) {
pw.println("Summary:");
dumpSummaryLocked(pw, reqPackage, now, activeOnly);
} else {
dumpTotalsLocked(pw, now);
}
if (dumpAll) {
pw.println();
pw.println("Internal state:");
/*
pw.print(" Num long arrays: "); pw.println(mLongs.size());
pw.print(" Next long entry: "); pw.println(mNextLong);
*/
pw.print(" mRunning=");
pw.println(mRunning);
}
dumpFragmentationLocked(pw);
}
use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by ResurrectionRemix.
the class ProcessRecord method resetPackageList.
/*
* Delete all packages from list except the package indicated in info
*/
public void resetPackageList(ProcessStatsService tracker) {
final int N = pkgList.size();
if (baseProcessTracker != null) {
long now = SystemClock.uptimeMillis();
baseProcessTracker.setState(ProcessStats.STATE_NOTHING, tracker.getMemFactorLocked(), now, pkgList);
if (N != 1) {
for (int i = 0; i < N; i++) {
ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
if (holder.state != null && holder.state != baseProcessTracker) {
holder.state.makeInactive();
}
}
pkgList.clear();
ProcessState ps = tracker.getProcessStateLocked(info.packageName, uid, info.versionCode, processName);
ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(info.versionCode);
holder.state = ps;
pkgList.put(info.packageName, holder);
if (ps != baseProcessTracker) {
ps.makeActive();
}
}
} else if (N != 1) {
pkgList.clear();
pkgList.put(info.packageName, new ProcessStats.ProcessStateHolder(info.versionCode));
}
}
Aggregations