use of com.android.internal.app.procstats.ProcessState in project android_packages_apps_Settings by SudaMod.
the class ProcStatsEntry method evaluateTargetPackage.
public void evaluateTargetPackage(PackageManager pm, ProcessStats stats, ProcessStats.ProcessDataCollection bgTotals, ProcessStats.ProcessDataCollection runTotals, Comparator<ProcStatsEntry> compare, boolean useUss) {
mBestTargetPackage = null;
if (mPackages.size() == 1) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": single pkg " + mPackages.get(0));
mBestTargetPackage = mPackages.get(0);
return;
}
// See if there is one significant package that was running here.
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
if ("android".equals(mPackages.get(ipkg))) {
mBestTargetPackage = mPackages.get(ipkg);
return;
}
}
// Collect information about each package running in the process.
ArrayList<ProcStatsEntry> subProcs = new ArrayList<>();
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
SparseArray<ProcessStats.PackageState> vpkgs = stats.mPackages.get(mPackages.get(ipkg), mUid);
for (int ivers = 0; ivers < vpkgs.size(); ivers++) {
ProcessStats.PackageState pkgState = vpkgs.valueAt(ivers);
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ", pkg " + pkgState + ":");
if (pkgState == null) {
Log.w(TAG, "No package state found for " + mPackages.get(ipkg) + "/" + mUid + " in process " + mName);
continue;
}
ProcessState pkgProc = pkgState.mProcesses.get(mName);
if (pkgProc == null) {
Log.w(TAG, "No process " + mName + " found in package state " + mPackages.get(ipkg) + "/" + mUid);
continue;
}
subProcs.add(new ProcStatsEntry(pkgProc, pkgState.mPackageName, bgTotals, runTotals, useUss));
}
}
if (subProcs.size() > 1) {
Collections.sort(subProcs, compare);
if (subProcs.get(0).mRunWeight > (subProcs.get(1).mRunWeight * 3)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": best pkg " + subProcs.get(0).mPackage + " weight " + subProcs.get(0).mRunWeight + " better than " + subProcs.get(1).mPackage + " weight " + subProcs.get(1).mRunWeight);
mBestTargetPackage = subProcs.get(0).mPackage;
return;
}
// Couldn't find one that is best by weight, let's decide on best another
// way: the one that has the longest running service, accounts for at least
// half of the maximum weight, and has specified an explicit app icon.
double maxWeight = subProcs.get(0).mRunWeight;
long bestRunTime = -1;
boolean bestPersistent = false;
for (int i = 0; i < subProcs.size(); i++) {
final ProcStatsEntry subProc = subProcs.get(i);
if (subProc.mRunWeight < (maxWeight / 2)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " weight " + subProc.mRunWeight + " too small");
continue;
}
try {
ApplicationInfo ai = pm.getApplicationInfo(subProc.mPackage, 0);
if (ai.icon == 0) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " has no icon");
continue;
}
if ((ai.flags & ApplicationInfo.FLAG_PERSISTENT) != 0) {
long thisRunTime = subProc.mRunDuration;
if (!bestPersistent || thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best pers run time " + thisRunTime);
bestRunTime = thisRunTime;
bestPersistent = true;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " pers run time " + thisRunTime + " not as good as last " + bestRunTime);
}
continue;
} else if (bestPersistent) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " is not persistent");
continue;
}
} catch (PackageManager.NameNotFoundException e) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " failed finding app info");
continue;
}
ArrayList<Service> subProcServices = null;
for (int isp = 0, NSP = mServices.size(); isp < NSP; isp++) {
ArrayList<Service> subServices = mServices.valueAt(isp);
if (subServices.get(0).mPackage.equals(subProc.mPackage)) {
subProcServices = subServices;
break;
}
}
long thisRunTime = 0;
if (subProcServices != null) {
for (int iss = 0, NSS = subProcServices.size(); iss < NSS; iss++) {
Service service = subProcServices.get(iss);
if (service.mDuration > thisRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " service " + service.mName + " run time is " + service.mDuration);
thisRunTime = service.mDuration;
break;
}
}
}
if (thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best run time " + thisRunTime);
mBestTargetPackage = subProc.mPackage;
bestRunTime = thisRunTime;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " run time " + thisRunTime + " not as good as last " + bestRunTime);
}
}
// Final fallback, just pick the first subProc.
if (TextUtils.isEmpty(mBestTargetPackage)) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
} else if (subProcs.size() == 1) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
}
use of com.android.internal.app.procstats.ProcessState in project platform_packages_apps_Settings by BlissRoms.
the class ProcStatsEntry method evaluateTargetPackage.
public void evaluateTargetPackage(PackageManager pm, ProcessStats stats, ProcessStats.ProcessDataCollection bgTotals, ProcessStats.ProcessDataCollection runTotals, Comparator<ProcStatsEntry> compare, boolean useUss) {
mBestTargetPackage = null;
if (mPackages.size() == 1) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": single pkg " + mPackages.get(0));
mBestTargetPackage = mPackages.get(0);
return;
}
// See if there is one significant package that was running here.
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
if ("android".equals(mPackages.get(ipkg))) {
mBestTargetPackage = mPackages.get(ipkg);
return;
}
}
// Collect information about each package running in the process.
ArrayList<ProcStatsEntry> subProcs = new ArrayList<>();
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
SparseArray<ProcessStats.PackageState> vpkgs = stats.mPackages.get(mPackages.get(ipkg), mUid);
for (int ivers = 0; ivers < vpkgs.size(); ivers++) {
ProcessStats.PackageState pkgState = vpkgs.valueAt(ivers);
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ", pkg " + pkgState + ":");
if (pkgState == null) {
Log.w(TAG, "No package state found for " + mPackages.get(ipkg) + "/" + mUid + " in process " + mName);
continue;
}
ProcessState pkgProc = pkgState.mProcesses.get(mName);
if (pkgProc == null) {
Log.w(TAG, "No process " + mName + " found in package state " + mPackages.get(ipkg) + "/" + mUid);
continue;
}
subProcs.add(new ProcStatsEntry(pkgProc, pkgState.mPackageName, bgTotals, runTotals, useUss));
}
}
if (subProcs.size() > 1) {
Collections.sort(subProcs, compare);
if (subProcs.get(0).mRunWeight > (subProcs.get(1).mRunWeight * 3)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": best pkg " + subProcs.get(0).mPackage + " weight " + subProcs.get(0).mRunWeight + " better than " + subProcs.get(1).mPackage + " weight " + subProcs.get(1).mRunWeight);
mBestTargetPackage = subProcs.get(0).mPackage;
return;
}
// Couldn't find one that is best by weight, let's decide on best another
// way: the one that has the longest running service, accounts for at least
// half of the maximum weight, and has specified an explicit app icon.
double maxWeight = subProcs.get(0).mRunWeight;
long bestRunTime = -1;
boolean bestPersistent = false;
for (int i = 0; i < subProcs.size(); i++) {
final ProcStatsEntry subProc = subProcs.get(i);
if (subProc.mRunWeight < (maxWeight / 2)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " weight " + subProc.mRunWeight + " too small");
continue;
}
try {
ApplicationInfo ai = pm.getApplicationInfo(subProc.mPackage, 0);
if (ai.icon == 0) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " has no icon");
continue;
}
if ((ai.flags & ApplicationInfo.FLAG_PERSISTENT) != 0) {
long thisRunTime = subProc.mRunDuration;
if (!bestPersistent || thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best pers run time " + thisRunTime);
bestRunTime = thisRunTime;
bestPersistent = true;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " pers run time " + thisRunTime + " not as good as last " + bestRunTime);
}
continue;
} else if (bestPersistent) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " is not persistent");
continue;
}
} catch (PackageManager.NameNotFoundException e) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " failed finding app info");
continue;
}
ArrayList<Service> subProcServices = null;
for (int isp = 0, NSP = mServices.size(); isp < NSP; isp++) {
ArrayList<Service> subServices = mServices.valueAt(isp);
if (subServices.get(0).mPackage.equals(subProc.mPackage)) {
subProcServices = subServices;
break;
}
}
long thisRunTime = 0;
if (subProcServices != null) {
for (int iss = 0, NSS = subProcServices.size(); iss < NSS; iss++) {
Service service = subProcServices.get(iss);
if (service.mDuration > thisRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " service " + service.mName + " run time is " + service.mDuration);
thisRunTime = service.mDuration;
break;
}
}
}
if (thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best run time " + thisRunTime);
mBestTargetPackage = subProc.mPackage;
bestRunTime = thisRunTime;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " run time " + thisRunTime + " not as good as last " + bestRunTime);
}
}
// Final fallback, just pick the first subProc.
if (TextUtils.isEmpty(mBestTargetPackage)) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
} else if (subProcs.size() == 1) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
}
use of com.android.internal.app.procstats.ProcessState in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ProcStatsEntry method evaluateTargetPackage.
public void evaluateTargetPackage(PackageManager pm, ProcessStats stats, ProcessStats.ProcessDataCollection bgTotals, ProcessStats.ProcessDataCollection runTotals, Comparator<ProcStatsEntry> compare, boolean useUss) {
mBestTargetPackage = null;
if (mPackages.size() == 1) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": single pkg " + mPackages.get(0));
mBestTargetPackage = mPackages.get(0);
return;
}
// See if there is one significant package that was running here.
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
if ("android".equals(mPackages.get(ipkg))) {
mBestTargetPackage = mPackages.get(ipkg);
return;
}
}
// Collect information about each package running in the process.
ArrayList<ProcStatsEntry> subProcs = new ArrayList<>();
for (int ipkg = 0; ipkg < mPackages.size(); ipkg++) {
LongSparseArray<ProcessStats.PackageState> vpkgs = stats.mPackages.get(mPackages.get(ipkg), mUid);
for (int ivers = 0; ivers < vpkgs.size(); ivers++) {
ProcessStats.PackageState pkgState = vpkgs.valueAt(ivers);
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ", pkg " + pkgState + ":");
if (pkgState == null) {
Log.w(TAG, "No package state found for " + mPackages.get(ipkg) + "/" + mUid + " in process " + mName);
continue;
}
ProcessState pkgProc = pkgState.mProcesses.get(mName);
if (pkgProc == null) {
Log.w(TAG, "No process " + mName + " found in package state " + mPackages.get(ipkg) + "/" + mUid);
continue;
}
subProcs.add(new ProcStatsEntry(pkgProc, pkgState.mPackageName, bgTotals, runTotals, useUss));
}
}
if (subProcs.size() > 1) {
Collections.sort(subProcs, compare);
if (subProcs.get(0).mRunWeight > (subProcs.get(1).mRunWeight * 3)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": best pkg " + subProcs.get(0).mPackage + " weight " + subProcs.get(0).mRunWeight + " better than " + subProcs.get(1).mPackage + " weight " + subProcs.get(1).mRunWeight);
mBestTargetPackage = subProcs.get(0).mPackage;
return;
}
// Couldn't find one that is best by weight, let's decide on best another
// way: the one that has the longest running service, accounts for at least
// half of the maximum weight, and has specified an explicit app icon.
double maxWeight = subProcs.get(0).mRunWeight;
long bestRunTime = -1;
boolean bestPersistent = false;
for (int i = 0; i < subProcs.size(); i++) {
final ProcStatsEntry subProc = subProcs.get(i);
if (subProc.mRunWeight < (maxWeight / 2)) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " weight " + subProc.mRunWeight + " too small");
continue;
}
try {
ApplicationInfo ai = pm.getApplicationInfo(subProc.mPackage, 0);
if (ai.icon == 0) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " has no icon");
continue;
}
if ((ai.flags & ApplicationInfo.FLAG_PERSISTENT) != 0) {
long thisRunTime = subProc.mRunDuration;
if (!bestPersistent || thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best pers run time " + thisRunTime);
bestRunTime = thisRunTime;
bestPersistent = true;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " pers run time " + thisRunTime + " not as good as last " + bestRunTime);
}
continue;
} else if (bestPersistent) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " is not persistent");
continue;
}
} catch (PackageManager.NameNotFoundException e) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " failed finding app info");
continue;
}
ArrayList<Service> subProcServices = null;
for (int isp = 0, NSP = mServices.size(); isp < NSP; isp++) {
ArrayList<Service> subServices = mServices.valueAt(isp);
if (subServices.get(0).mPackage.equals(subProc.mPackage)) {
subProcServices = subServices;
break;
}
}
long thisRunTime = 0;
if (subProcServices != null) {
for (int iss = 0, NSS = subProcServices.size(); iss < NSS; iss++) {
Service service = subProcServices.get(iss);
if (service.mDuration > thisRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " service " + service.mName + " run time is " + service.mDuration);
thisRunTime = service.mDuration;
break;
}
}
}
if (thisRunTime > bestRunTime) {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " new best run time " + thisRunTime);
mBestTargetPackage = subProc.mPackage;
bestRunTime = thisRunTime;
} else {
if (DEBUG)
Log.d(TAG, "Eval pkg of " + mName + ": pkg " + subProc.mPackage + " run time " + thisRunTime + " not as good as last " + bestRunTime);
}
}
// Final fallback, just pick the first subProc.
if (TextUtils.isEmpty(mBestTargetPackage)) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
} else if (subProcs.size() == 1) {
mBestTargetPackage = subProcs.get(0).mPackage;
}
}
use of com.android.internal.app.procstats.ProcessState 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<LongSparseArray<ProcessStats.PackageState>> pkgUids = mStats.mPackages.getMap().valueAt(ipkg);
for (int iu = 0; iu < pkgUids.size(); iu++) {
final LongSparseArray<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<LongSparseArray<ProcessStats.PackageState>> uids = mStats.mPackages.getMap().valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
LongSparseArray<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;
}
Aggregations