Search in sources :

Example 46 with ProcessState

use of com.android.internal.app.procstats.ProcessState in project platform_packages_apps_Settings by BlissRoms.

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;
}
Also used : IProcessStats(com.android.internal.app.procstats.IProcessStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) ServiceState(com.android.internal.app.procstats.ServiceState) ArrayList(java.util.ArrayList) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray) ProcessMap(com.android.internal.app.ProcessMap)

Example 47 with ProcessState

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;
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ServiceState(com.android.internal.app.procstats.ServiceState)

Example 48 with ProcessState

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();
    }
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 49 with ProcessState

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);
        }
    }
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 50 with ProcessState

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;
}
Also used : ArraySet(android.util.ArraySet) ArrayList(java.util.ArrayList) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Aggregations

ProcessState (com.android.internal.app.procstats.ProcessState)84 ServiceState (com.android.internal.app.procstats.ServiceState)47 SparseArray (android.util.SparseArray)46 ProcessStats (com.android.internal.app.procstats.ProcessStats)34 ArrayList (java.util.ArrayList)24 IProcessStats (com.android.internal.app.procstats.IProcessStats)12 ApplicationInfo (android.content.pm.ApplicationInfo)7 PackageManager (android.content.pm.PackageManager)7 ProcessMap (com.android.internal.app.ProcessMap)7 ArraySet (android.util.ArraySet)5 FileInputStream (java.io.FileInputStream)5 LongSparseArray (android.util.LongSparseArray)1