Search in sources :

Example 66 with ProcessState

use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by ResurrectionRemix.

the class ProcessRecord method makeInactive.

public void makeInactive(ProcessStatsService tracker) {
    String seempStr = "app_uid=" + uid + ",app_pid=" + pid + ",oom_adj=" + curAdj + ",setAdj=" + setAdj + ",hasShownUi=" + (hasShownUi ? 1 : 0) + ",cached=" + (cached ? 1 : 0) + ",fA=" + (foregroundActivities ? 1 : 0) + ",fS=" + (foregroundServices ? 1 : 0) + ",systemNoUi=" + (systemNoUi ? 1 : 0) + ",curSchedGroup=" + curSchedGroup + ",curProcState=" + curProcState + ",setProcState=" + setProcState + ",killed=" + (killed ? 1 : 0) + ",killedByAm=" + (killedByAm ? 1 : 0) + ",debugging=" + (debugging ? 1 : 0);
    android.util.SeempLog.record_str(387, seempStr);
    thread = null;
    final ProcessState origBase = baseProcessTracker;
    if (origBase != null) {
        origBase.setState(ProcessStats.STATE_NOTHING, tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList);
        origBase.makeInactive();
    }
    baseProcessTracker = null;
    for (int i = 0; i < pkgList.size(); i++) {
        ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
        if (holder.state != null && holder.state != origBase) {
            holder.state.makeInactive();
        }
        holder.state = null;
    }
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ProcessStats(com.android.internal.app.procstats.ProcessStats)

Example 67 with ProcessState

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

Example 68 with ProcessState

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

Example 69 with ProcessState

use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by ResurrectionRemix.

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 70 with ProcessState

use of com.android.internal.app.procstats.ProcessState in project android_frameworks_base by crdroidandroid.

the class ProcessRecord method makeInactive.

public void makeInactive(ProcessStatsService tracker) {
    String seempStr = "app_uid=" + uid + ",app_pid=" + pid + ",oom_adj=" + curAdj + ",setAdj=" + setAdj + ",hasShownUi=" + (hasShownUi ? 1 : 0) + ",cached=" + (cached ? 1 : 0) + ",fA=" + (foregroundActivities ? 1 : 0) + ",fS=" + (foregroundServices ? 1 : 0) + ",systemNoUi=" + (systemNoUi ? 1 : 0) + ",curSchedGroup=" + curSchedGroup + ",curProcState=" + curProcState + ",setProcState=" + setProcState + ",killed=" + (killed ? 1 : 0) + ",killedByAm=" + (killedByAm ? 1 : 0) + ",debugging=" + (debugging ? 1 : 0);
    android.util.SeempLog.record_str(387, seempStr);
    thread = null;
    final ProcessState origBase = baseProcessTracker;
    if (origBase != null) {
        origBase.setState(ProcessStats.STATE_NOTHING, tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList);
        origBase.makeInactive();
    }
    baseProcessTracker = null;
    for (int i = 0; i < pkgList.size(); i++) {
        ProcessStats.ProcessStateHolder holder = pkgList.valueAt(i);
        if (holder.state != null && holder.state != origBase) {
            holder.state.makeInactive();
        }
        holder.state = null;
    }
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ProcessStats(com.android.internal.app.procstats.ProcessStats)

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