use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by AOSPA.
the class ProcessStatsService method readLocked.
boolean readLocked(ProcessStats stats, AtomicFile file) {
try {
FileInputStream stream = file.openRead();
stats.read(stream);
stream.close();
if (stats.mReadError != null) {
Slog.w(TAG, "Ignoring existing stats; " + stats.mReadError);
if (DEBUG) {
ArrayMap<String, SparseArray<ProcessState>> procMap = stats.mProcesses.getMap();
final int NPROC = procMap.size();
for (int ip = 0; ip < NPROC; ip++) {
Slog.w(TAG, "Process: " + procMap.keyAt(ip));
SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid " + uids.keyAt(iu) + ": " + uids.valueAt(iu));
}
}
ArrayMap<String, SparseArray<SparseArray<ProcessStats.PackageState>>> pkgMap = stats.mPackages.getMap();
final int NPKG = pkgMap.size();
for (int ip = 0; ip < NPKG; ip++) {
Slog.w(TAG, "Package: " + pkgMap.keyAt(ip));
SparseArray<SparseArray<ProcessStats.PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid: " + uids.keyAt(iu));
SparseArray<ProcessStats.PackageState> vers = uids.valueAt(iu);
final int NVERS = vers.size();
for (int iv = 0; iv < NVERS; iv++) {
Slog.w(TAG, " Vers: " + vers.keyAt(iv));
ProcessStats.PackageState pkgState = vers.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
Slog.w(TAG, " Process " + pkgState.mProcesses.keyAt(iproc) + ": " + pkgState.mProcesses.valueAt(iproc));
}
final int NSRVS = pkgState.mServices.size();
for (int isvc = 0; isvc < NSRVS; isvc++) {
Slog.w(TAG, " Service " + pkgState.mServices.keyAt(isvc) + ": " + pkgState.mServices.valueAt(isvc));
}
}
}
}
}
return false;
}
} catch (Throwable e) {
stats.mReadError = "caught exception: " + e;
Slog.e(TAG, "Error reading process statistics", e);
return false;
}
return true;
}
use of com.android.internal.app.procstats.ProcessState in project platform_frameworks_base by android.
the class ProcessStats method getProcessStateLocked.
public ProcessState getProcessStateLocked(String packageName, int uid, int vers, String processName) {
final PackageState pkgState = getPackageStateLocked(packageName, uid, vers);
ProcessState ps = pkgState.mProcesses.get(processName);
if (ps != null) {
return ps;
}
ProcessState commonProc = mProcesses.get(processName, uid);
if (commonProc == null) {
commonProc = new ProcessState(this, packageName, uid, vers, processName);
mProcesses.put(processName, uid, commonProc);
if (DEBUG)
Slog.d(TAG, "GETPROC created new common " + commonProc);
}
if (!commonProc.isMultiPackage()) {
if (packageName.equals(commonProc.getPackage()) && vers == commonProc.getVersion()) {
// This common process is not in use by multiple packages, and
// is for the calling package, so we can just use it directly.
ps = commonProc;
if (DEBUG)
Slog.d(TAG, "GETPROC also using for pkg " + commonProc);
} else {
if (DEBUG)
Slog.d(TAG, "GETPROC need to split common proc!");
// This common process has not been in use by multiple packages,
// but it was created for a different package than the caller.
// We need to convert it to a multi-package process.
commonProc.setMultiPackage(true);
// To do this, we need to make two new process states, one a copy
// of the current state for the process under the original package
// name, and the second a free new process state for it as the
// new package name.
long now = SystemClock.uptimeMillis();
// First let's make a copy of the current process state and put
// that under the now unique state for its original package name.
final PackageState commonPkgState = getPackageStateLocked(commonProc.getPackage(), uid, commonProc.getVersion());
if (commonPkgState != null) {
ProcessState cloned = commonProc.clone(now);
if (DEBUG)
Slog.d(TAG, "GETPROC setting clone to pkg " + commonProc.getPackage() + ": " + cloned);
commonPkgState.mProcesses.put(commonProc.getName(), cloned);
// to point to the new package-specific process state.
for (int i = commonPkgState.mServices.size() - 1; i >= 0; i--) {
ServiceState ss = commonPkgState.mServices.valueAt(i);
if (ss.getProcess() == commonProc) {
if (DEBUG)
Slog.d(TAG, "GETPROC switching service to cloned: " + ss);
ss.setProcess(cloned);
} else if (DEBUG) {
Slog.d(TAG, "GETPROC leaving proc of " + ss);
}
}
} else {
Slog.w(TAG, "Cloning proc state: no package state " + commonProc.getPackage() + "/" + uid + " for proc " + commonProc.getName());
}
// And now make a fresh new process state for the new package name.
ps = new ProcessState(commonProc, packageName, uid, vers, processName, now);
if (DEBUG)
Slog.d(TAG, "GETPROC created new pkg " + ps);
}
} else {
// The common process is for multiple packages, we need to create a
// separate object for the per-package data.
ps = new ProcessState(commonProc, packageName, uid, vers, processName, SystemClock.uptimeMillis());
if (DEBUG)
Slog.d(TAG, "GETPROC created new pkg " + ps);
}
pkgState.mProcesses.put(processName, ps);
if (DEBUG)
Slog.d(TAG, "GETPROC adding new pkg " + ps);
return ps;
}
use of com.android.internal.app.procstats.ProcessState in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class ProcessStats method collectProcessesLocked.
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates, int[] memStates, int[] procStates, int[] sortProcStates, long now, String reqPackage, boolean activeOnly) {
final ArraySet<ProcessState> foundProcs = new ArraySet<ProcessState>();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> procs = pkgMap.valueAt(ip);
for (int iu = 0; iu < procs.size(); iu++) {
final SparseArray<PackageState> vpkgs = procs.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
final PackageState state = vpkgs.valueAt(iv);
final int NPROCS = state.mProcesses.size();
final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
for (int iproc = 0; iproc < NPROCS; iproc++) {
final ProcessState proc = state.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
continue;
}
foundProcs.add(proc.getCommonProcess());
}
}
}
}
ArrayList<ProcessState> outProcs = new ArrayList<ProcessState>(foundProcs.size());
for (int i = 0; i < foundProcs.size(); i++) {
ProcessState proc = foundProcs.valueAt(i);
if (proc.computeProcessTimeLocked(screenStates, memStates, procStates, now) > 0) {
outProcs.add(proc);
if (procStates != sortProcStates) {
proc.computeProcessTimeLocked(screenStates, memStates, sortProcStates, now);
}
}
}
Collections.sort(outProcs, ProcessState.COMPARATOR);
return outProcs;
}
Aggregations