use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by ResurrectionRemix.
the class ActiveServices method bumpServiceExecutingLocked.
private final void bumpServiceExecutingLocked(ServiceRecord r, boolean fg, String why) {
if (DEBUG_SERVICE)
Slog.v(TAG_SERVICE, ">>> EXECUTING " + why + " of " + r + " in app " + r.app);
else if (DEBUG_SERVICE_EXECUTING)
Slog.v(TAG_SERVICE_EXECUTING, ">>> EXECUTING " + why + " of " + r.shortName);
long now = SystemClock.uptimeMillis();
if (r.executeNesting == 0) {
r.executeFg = fg;
ServiceState stracker = r.getTracker();
if (stracker != null) {
stracker.setExecuting(true, mAm.mProcessStats.getMemFactorLocked(), now);
}
if (r.app != null) {
r.app.executingServices.add(r);
r.app.execServicesFg |= fg;
if (r.app.executingServices.size() == 1) {
scheduleServiceTimeoutLocked(r.app);
}
}
} else if (r.app != null && fg && !r.app.execServicesFg) {
r.app.execServicesFg = true;
scheduleServiceTimeoutLocked(r.app);
}
r.executeFg |= fg;
r.executeNesting++;
r.executingStart = now;
}
use of com.android.internal.app.procstats.ServiceState in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ProcStatsData method getProcs.
private ArrayList<ProcStatsEntry> getProcs(ProcessDataCollection bgTotals, ProcessDataCollection runTotals) {
final ArrayList<ProcStatsEntry> procEntries = new ArrayList<>();
if (DEBUG)
Log.d(TAG, "-------------------- PULLING PROCESSES");
final ProcessMap<ProcStatsEntry> entriesMap = new ProcessMap<ProcStatsEntry>();
for (int ipkg = 0, N = mStats.mPackages.getMap().size(); ipkg < N; ipkg++) {
final SparseArray<SparseArray<ProcessStats.PackageState>> pkgUids = mStats.mPackages.getMap().valueAt(ipkg);
for (int iu = 0; iu < pkgUids.size(); iu++) {
final SparseArray<ProcessStats.PackageState> vpkgs = pkgUids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
final ProcessStats.PackageState st = vpkgs.valueAt(iv);
for (int iproc = 0; iproc < st.mProcesses.size(); iproc++) {
final ProcessState pkgProc = st.mProcesses.valueAt(iproc);
final ProcessState proc = mStats.mProcesses.get(pkgProc.getName(), pkgProc.getUid());
if (proc == null) {
Log.w(TAG, "No process found for pkg " + st.mPackageName + "/" + st.mUid + " proc name " + pkgProc.getName());
continue;
}
ProcStatsEntry ent = entriesMap.get(proc.getName(), proc.getUid());
if (ent == null) {
ent = new ProcStatsEntry(proc, st.mPackageName, bgTotals, runTotals, mUseUss);
if (ent.mRunWeight > 0) {
if (DEBUG)
Log.d(TAG, "Adding proc " + proc.getName() + "/" + proc.getUid() + ": time=" + ProcessStatsUi.makeDuration(ent.mRunDuration) + " (" + ((((double) ent.mRunDuration) / memTotalTime) * 100) + "%)" + " pss=" + ent.mAvgRunMem);
entriesMap.put(proc.getName(), proc.getUid(), ent);
procEntries.add(ent);
}
} else {
ent.addPackage(st.mPackageName);
}
}
}
}
}
if (DEBUG)
Log.d(TAG, "-------------------- MAPPING SERVICES");
// Add in service info.
for (int ip = 0, N = mStats.mPackages.getMap().size(); ip < N; ip++) {
SparseArray<SparseArray<ProcessStats.PackageState>> uids = mStats.mPackages.getMap().valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
SparseArray<ProcessStats.PackageState> vpkgs = uids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
ProcessStats.PackageState ps = vpkgs.valueAt(iv);
for (int is = 0, NS = ps.mServices.size(); is < NS; is++) {
ServiceState ss = ps.mServices.valueAt(is);
if (ss.getProcessName() != null) {
ProcStatsEntry ent = entriesMap.get(ss.getProcessName(), uids.keyAt(iu));
if (ent != null) {
if (DEBUG)
Log.d(TAG, "Adding service " + ps.mPackageName + "/" + ss.getName() + "/" + uids.keyAt(iu) + " to proc " + ss.getProcessName());
ent.addService(ss);
} else {
Log.w(TAG, "No process " + ss.getProcessName() + "/" + uids.keyAt(iu) + " for service " + ss.getName());
}
}
}
}
}
}
return procEntries;
}
use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by ResurrectionRemix.
the class ProcessStatsService method setMemFactorLocked.
public boolean setMemFactorLocked(int memFactor, boolean screenOn, long now) {
mMemFactorLowered = memFactor < mLastMemOnlyState;
mLastMemOnlyState = memFactor;
if (screenOn) {
memFactor += ProcessStats.ADJ_SCREEN_ON;
}
if (memFactor != mProcessStats.mMemFactor) {
if (mProcessStats.mMemFactor != ProcessStats.STATE_NOTHING) {
mProcessStats.mMemFactorDurations[mProcessStats.mMemFactor] += now - mProcessStats.mStartTime;
}
mProcessStats.mMemFactor = memFactor;
mProcessStats.mStartTime = now;
final ArrayMap<String, SparseArray<SparseArray<ProcessStats.PackageState>>> pmap = mProcessStats.mPackages.getMap();
for (int ipkg = pmap.size() - 1; ipkg >= 0; ipkg--) {
final SparseArray<SparseArray<ProcessStats.PackageState>> uids = pmap.valueAt(ipkg);
for (int iuid = uids.size() - 1; iuid >= 0; iuid--) {
final SparseArray<ProcessStats.PackageState> vers = uids.valueAt(iuid);
for (int iver = vers.size() - 1; iver >= 0; iver--) {
final ProcessStats.PackageState pkg = vers.valueAt(iver);
final ArrayMap<String, ServiceState> services = pkg.mServices;
for (int isvc = services.size() - 1; isvc >= 0; isvc--) {
final ServiceState service = services.valueAt(isvc);
service.setMemFactor(memFactor, now);
}
}
}
}
return true;
}
return false;
}
use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by ResurrectionRemix.
the class ProcessStats method add.
public void add(ProcessStats other) {
ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = other.mPackages.getMap();
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> versions = uids.valueAt(iu);
for (int iv = 0; iv < versions.size(); iv++) {
final int vers = versions.keyAt(iv);
final PackageState otherState = versions.valueAt(iv);
final int NPROCS = otherState.mProcesses.size();
final int NSRVS = otherState.mServices.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState otherProc = otherState.mProcesses.valueAt(iproc);
if (otherProc.getCommonProcess() != otherProc) {
if (DEBUG)
Slog.d(TAG, "Adding pkg " + pkgName + " uid " + uid + " vers " + vers + " proc " + otherProc.getName());
ProcessState thisProc = getProcessStateLocked(pkgName, uid, vers, otherProc.getName());
if (thisProc.getCommonProcess() == thisProc) {
if (DEBUG)
Slog.d(TAG, "Existing process is single-package, splitting");
thisProc.setMultiPackage(true);
long now = SystemClock.uptimeMillis();
final PackageState pkgState = getPackageStateLocked(pkgName, uid, vers);
thisProc = thisProc.clone(now);
pkgState.mProcesses.put(thisProc.getName(), thisProc);
}
thisProc.add(otherProc);
}
}
for (int isvc = 0; isvc < NSRVS; isvc++) {
ServiceState otherSvc = otherState.mServices.valueAt(isvc);
if (DEBUG)
Slog.d(TAG, "Adding pkg " + pkgName + " uid " + uid + " service " + otherSvc.getName());
ServiceState thisSvc = getServiceStateLocked(pkgName, uid, vers, otherSvc.getProcessName(), otherSvc.getName());
thisSvc.add(otherSvc);
}
}
}
}
ArrayMap<String, SparseArray<ProcessState>> procMap = other.mProcesses.getMap();
for (int ip = 0; ip < procMap.size(); ip++) {
SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
int uid = uids.keyAt(iu);
ProcessState otherProc = uids.valueAt(iu);
final String name = otherProc.getName();
final String pkg = otherProc.getPackage();
final int vers = otherProc.getVersion();
ProcessState thisProc = mProcesses.get(name, uid);
if (DEBUG)
Slog.d(TAG, "Adding uid " + uid + " proc " + name);
if (thisProc == null) {
if (DEBUG)
Slog.d(TAG, "Creating new process!");
thisProc = new ProcessState(this, pkg, uid, vers, name);
mProcesses.put(name, uid, thisProc);
PackageState thisState = getPackageStateLocked(pkg, uid, vers);
if (!thisState.mProcesses.containsKey(name)) {
thisState.mProcesses.put(name, thisProc);
}
}
thisProc.add(otherProc);
}
}
for (int i = 0; i < ADJ_COUNT; i++) {
if (DEBUG)
Slog.d(TAG, "Total duration #" + i + " inc by " + other.mMemFactorDurations[i] + " from " + mMemFactorDurations[i]);
mMemFactorDurations[i] += other.mMemFactorDurations[i];
}
mSysMemUsage.mergeStats(other.mSysMemUsage);
if (other.mTimePeriodStartClock < mTimePeriodStartClock) {
mTimePeriodStartClock = other.mTimePeriodStartClock;
mTimePeriodStartClockStr = other.mTimePeriodStartClockStr;
}
mTimePeriodEndRealtime += other.mTimePeriodEndRealtime - other.mTimePeriodStartRealtime;
mTimePeriodEndUptime += other.mTimePeriodEndUptime - other.mTimePeriodStartUptime;
mHasSwappedOutPss |= other.mHasSwappedOutPss;
}
use of com.android.internal.app.procstats.ServiceState in project android_frameworks_base by ResurrectionRemix.
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);
}
Aggregations