Search in sources :

Example 41 with ProcessStats

use of com.android.internal.app.procstats.ProcessStats in project platform_packages_apps_Settings by AospExtended.

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;
    }
}
Also used : ProcessStats(com.android.internal.app.procstats.ProcessStats) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) ProcessState(com.android.internal.app.procstats.ProcessState) PackageManager(android.content.pm.PackageManager)

Example 42 with ProcessStats

use of com.android.internal.app.procstats.ProcessStats in project android_packages_apps_Settings by AOSPA.

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;
    }
}
Also used : ProcessStats(com.android.internal.app.procstats.ProcessStats) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) ProcessState(com.android.internal.app.procstats.ProcessState) PackageManager(android.content.pm.PackageManager)

Example 43 with ProcessStats

use of com.android.internal.app.procstats.ProcessStats in project android_packages_apps_Settings by AOSPA.

the class ProcStatsData method load.

private void load() {
    try {
        ParcelFileDescriptor pfd = mProcessStats.getStatsOverTime(mDuration);
        mStats = new ProcessStats(false);
        InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
        mStats.read(is);
        try {
            is.close();
        } catch (IOException e) {
        }
        if (mStats.mReadError != null) {
            Log.w(TAG, "Failure reading process stats: " + mStats.mReadError);
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException:", e);
    }
}
Also used : IProcessStats(com.android.internal.app.procstats.IProcessStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) InputStream(java.io.InputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) RemoteException(android.os.RemoteException)

Example 44 with ProcessStats

use of com.android.internal.app.procstats.ProcessStats in project packages_apps_Settings by Evolution-X.

the class ProcStatsData method load.

private void load() {
    try {
        ParcelFileDescriptor pfd = mProcessStats.getStatsOverTime(mDuration);
        mStats = new ProcessStats(false);
        InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
        mStats.read(is);
        try {
            is.close();
        } catch (IOException e) {
        }
        if (mStats.mReadError != null) {
            Log.w(TAG, "Failure reading process stats: " + mStats.mReadError);
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException:", e);
    }
}
Also used : IProcessStats(com.android.internal.app.procstats.IProcessStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) InputStream(java.io.InputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) RemoteException(android.os.RemoteException)

Example 45 with ProcessStats

use of com.android.internal.app.procstats.ProcessStats in project packages_apps_Settings by Spark-Rom.

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;
    }
}
Also used : ProcessStats(com.android.internal.app.procstats.ProcessStats) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) ProcessState(com.android.internal.app.procstats.ProcessState) PackageManager(android.content.pm.PackageManager)

Aggregations

ProcessStats (com.android.internal.app.procstats.ProcessStats)50 IProcessStats (com.android.internal.app.procstats.IProcessStats)35 ParcelFileDescriptor (android.os.ParcelFileDescriptor)25 ProcessState (com.android.internal.app.procstats.ProcessState)20 IOException (java.io.IOException)20 InputStream (java.io.InputStream)20 ArrayList (java.util.ArrayList)20 ApplicationInfo (android.content.pm.ApplicationInfo)15 PackageManager (android.content.pm.PackageManager)15 RemoteException (android.os.RemoteException)15 AtomicFile (android.util.AtomicFile)10 File (java.io.File)10 FileInputStream (java.io.FileInputStream)10 Parcel (android.os.Parcel)5 SparseArray (android.util.SparseArray)5 BackgroundThread (com.android.internal.os.BackgroundThread)5 FileOutputStream (java.io.FileOutputStream)5