use of com.android.internal.app.procstats.ProcessState in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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));
}
}
use of com.android.internal.app.procstats.ProcessState in project platform_frameworks_base by android.
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 android_frameworks_base by DirtyUnicorns.
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));
}
}
use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by DirtyUnicorns.
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);
}
}
}
Aggregations