Search in sources :

Example 21 with ProcessState

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

the class ProcessRecord method makeActive.

public void makeActive(IApplicationThread _thread, ProcessStatsService tracker) {
    if (thread == null) {
        final ProcessState origBase = baseProcessTracker;
        if (origBase != null) {
            origBase.setState(ProcessStats.STATE_NOTHING, tracker.getMemFactorLocked(), SystemClock.uptimeMillis(), pkgList);
            origBase.makeInactive();
        }
        baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid, info.versionCode, processName);
        baseProcessTracker.makeActive();
        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 = tracker.getProcessStateLocked(pkgList.keyAt(i), uid, info.versionCode, processName);
            if (holder.state != baseProcessTracker) {
                holder.state.makeActive();
            }
        }
    }
    thread = _thread;
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ProcessStats(com.android.internal.app.procstats.ProcessStats)

Example 22 with ProcessState

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

the class ProcessRecord method makeInactive.

public void makeInactive(ProcessStatsService tracker) {
    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 23 with ProcessState

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

the class ProcessStatsService method readLocked.

boolean readLocked(ProcessStats stats, AtomicFile file) {
    try {
        FileInputStream stream = file.openRead();
        stats.read(stream);
        stream.close();
        if (stats.mReadError != null) {
            Slog.w(TAG, "Ignoring existing stats; " + stats.mReadError);
            if (DEBUG) {
                ArrayMap<String, SparseArray<ProcessState>> procMap = stats.mProcesses.getMap();
                final int NPROC = procMap.size();
                for (int ip = 0; ip < NPROC; ip++) {
                    Slog.w(TAG, "Process: " + procMap.keyAt(ip));
                    SparseArray<ProcessState> uids = procMap.valueAt(ip);
                    final int NUID = uids.size();
                    for (int iu = 0; iu < NUID; iu++) {
                        Slog.w(TAG, "  Uid " + uids.keyAt(iu) + ": " + uids.valueAt(iu));
                    }
                }
                ArrayMap<String, SparseArray<SparseArray<ProcessStats.PackageState>>> pkgMap = stats.mPackages.getMap();
                final int NPKG = pkgMap.size();
                for (int ip = 0; ip < NPKG; ip++) {
                    Slog.w(TAG, "Package: " + pkgMap.keyAt(ip));
                    SparseArray<SparseArray<ProcessStats.PackageState>> uids = pkgMap.valueAt(ip);
                    final int NUID = uids.size();
                    for (int iu = 0; iu < NUID; iu++) {
                        Slog.w(TAG, "  Uid: " + uids.keyAt(iu));
                        SparseArray<ProcessStats.PackageState> vers = uids.valueAt(iu);
                        final int NVERS = vers.size();
                        for (int iv = 0; iv < NVERS; iv++) {
                            Slog.w(TAG, "    Vers: " + vers.keyAt(iv));
                            ProcessStats.PackageState pkgState = vers.valueAt(iv);
                            final int NPROCS = pkgState.mProcesses.size();
                            for (int iproc = 0; iproc < NPROCS; iproc++) {
                                Slog.w(TAG, "      Process " + pkgState.mProcesses.keyAt(iproc) + ": " + pkgState.mProcesses.valueAt(iproc));
                            }
                            final int NSRVS = pkgState.mServices.size();
                            for (int isvc = 0; isvc < NSRVS; isvc++) {
                                Slog.w(TAG, "      Service " + pkgState.mServices.keyAt(isvc) + ": " + pkgState.mServices.valueAt(isvc));
                            }
                        }
                    }
                }
            }
            return false;
        }
    } catch (Throwable e) {
        stats.mReadError = "caught exception: " + e;
        Slog.e(TAG, "Error reading process statistics", e);
        return false;
    }
    return true;
}
Also used : IProcessStats(com.android.internal.app.procstats.IProcessStats) ProcessStats(com.android.internal.app.procstats.ProcessStats) FileInputStream(java.io.FileInputStream) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 24 with ProcessState

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

the class ProcessStats method writeToParcel.

/** @hide */
public void writeToParcel(Parcel out, long now, int flags) {
    out.writeInt(MAGIC);
    out.writeInt(PARCEL_VERSION);
    out.writeInt(STATE_COUNT);
    out.writeInt(ADJ_COUNT);
    out.writeInt(PSS_COUNT);
    out.writeInt(SYS_MEM_USAGE_COUNT);
    out.writeInt(SparseMappingTable.ARRAY_SIZE);
    mCommonStringToIndex = new ArrayMap<String, Integer>(mProcesses.size());
    // First commit all running times.
    ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
    final int NPROC = procMap.size();
    for (int ip = 0; ip < NPROC; ip++) {
        SparseArray<ProcessState> uids = procMap.valueAt(ip);
        final int NUID = uids.size();
        for (int iu = 0; iu < NUID; iu++) {
            uids.valueAt(iu).commitStateTime(now);
        }
    }
    final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
    final int NPKG = pkgMap.size();
    for (int ip = 0; ip < NPKG; ip++) {
        final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
        final int NUID = uids.size();
        for (int iu = 0; iu < NUID; iu++) {
            final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
            final int NVERS = vpkgs.size();
            for (int iv = 0; iv < NVERS; iv++) {
                PackageState pkgState = vpkgs.valueAt(iv);
                final int NPROCS = pkgState.mProcesses.size();
                for (int iproc = 0; iproc < NPROCS; iproc++) {
                    ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                    if (proc.getCommonProcess() != proc) {
                        proc.commitStateTime(now);
                    }
                }
                final int NSRVS = pkgState.mServices.size();
                for (int isvc = 0; isvc < NSRVS; isvc++) {
                    pkgState.mServices.valueAt(isvc).commitStateTime(now);
                }
            }
        }
    }
    out.writeLong(mTimePeriodStartClock);
    out.writeLong(mTimePeriodStartRealtime);
    out.writeLong(mTimePeriodEndRealtime);
    out.writeLong(mTimePeriodStartUptime);
    out.writeLong(mTimePeriodEndUptime);
    out.writeString(mRuntime);
    out.writeInt(mHasSwappedOutPss ? 1 : 0);
    out.writeInt(mFlags);
    mTableData.writeToParcel(out);
    if (mMemFactor != STATE_NOTHING) {
        mMemFactorDurations[mMemFactor] += now - mStartTime;
        mStartTime = now;
    }
    writeCompactedLongArray(out, mMemFactorDurations, mMemFactorDurations.length);
    mSysMemUsage.writeToParcel(out);
    out.writeInt(NPROC);
    for (int ip = 0; ip < NPROC; ip++) {
        writeCommonString(out, procMap.keyAt(ip));
        final SparseArray<ProcessState> uids = procMap.valueAt(ip);
        final int NUID = uids.size();
        out.writeInt(NUID);
        for (int iu = 0; iu < NUID; iu++) {
            out.writeInt(uids.keyAt(iu));
            final ProcessState proc = uids.valueAt(iu);
            writeCommonString(out, proc.getPackage());
            out.writeInt(proc.getVersion());
            proc.writeToParcel(out, now);
        }
    }
    out.writeInt(NPKG);
    for (int ip = 0; ip < NPKG; ip++) {
        writeCommonString(out, pkgMap.keyAt(ip));
        final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
        final int NUID = uids.size();
        out.writeInt(NUID);
        for (int iu = 0; iu < NUID; iu++) {
            out.writeInt(uids.keyAt(iu));
            final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
            final int NVERS = vpkgs.size();
            out.writeInt(NVERS);
            for (int iv = 0; iv < NVERS; iv++) {
                out.writeInt(vpkgs.keyAt(iv));
                final PackageState pkgState = vpkgs.valueAt(iv);
                final int NPROCS = pkgState.mProcesses.size();
                out.writeInt(NPROCS);
                for (int iproc = 0; iproc < NPROCS; iproc++) {
                    writeCommonString(out, pkgState.mProcesses.keyAt(iproc));
                    final ProcessState proc = pkgState.mProcesses.valueAt(iproc);
                    if (proc.getCommonProcess() == proc) {
                        // This is the same as the common process we wrote above.
                        out.writeInt(0);
                    } else {
                        // There is separate data for this package's process.
                        out.writeInt(1);
                        proc.writeToParcel(out, now);
                    }
                }
                final int NSRVS = pkgState.mServices.size();
                out.writeInt(NSRVS);
                for (int isvc = 0; isvc < NSRVS; isvc++) {
                    out.writeString(pkgState.mServices.keyAt(isvc));
                    final ServiceState svc = pkgState.mServices.valueAt(isvc);
                    writeCommonString(out, svc.getProcessName());
                    svc.writeToParcel(out, now);
                }
            }
        }
    }
    // Fragmentation info (/proc/pagetypeinfo)
    final int NPAGETYPES = mPageTypeLabels.size();
    out.writeInt(NPAGETYPES);
    for (int i = 0; i < NPAGETYPES; i++) {
        out.writeInt(mPageTypeZones.get(i));
        out.writeString(mPageTypeLabels.get(i));
        out.writeIntArray(mPageTypeSizes.get(i));
    }
    mCommonStringToIndex = null;
}
Also used : ServiceState(com.android.internal.app.procstats.ServiceState) ProcessState(com.android.internal.app.procstats.ProcessState) SparseArray(android.util.SparseArray)

Example 25 with ProcessState

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

the class ProcessStats method readFromParcel.

public void readFromParcel(Parcel in) {
    final boolean hadData = mPackages.getMap().size() > 0 || mProcesses.getMap().size() > 0;
    if (hadData) {
        resetSafely();
    }
    if (!readCheckedInt(in, MAGIC, "magic number")) {
        return;
    }
    int version = in.readInt();
    if (version != PARCEL_VERSION) {
        mReadError = "bad version: " + version;
        return;
    }
    if (!readCheckedInt(in, STATE_COUNT, "state count")) {
        return;
    }
    if (!readCheckedInt(in, ADJ_COUNT, "adj count")) {
        return;
    }
    if (!readCheckedInt(in, PSS_COUNT, "pss count")) {
        return;
    }
    if (!readCheckedInt(in, SYS_MEM_USAGE_COUNT, "sys mem usage count")) {
        return;
    }
    if (!readCheckedInt(in, SparseMappingTable.ARRAY_SIZE, "longs size")) {
        return;
    }
    mIndexToCommonString = new ArrayList<String>();
    mTimePeriodStartClock = in.readLong();
    buildTimePeriodStartClockStr();
    mTimePeriodStartRealtime = in.readLong();
    mTimePeriodEndRealtime = in.readLong();
    mTimePeriodStartUptime = in.readLong();
    mTimePeriodEndUptime = in.readLong();
    mRuntime = in.readString();
    mHasSwappedOutPss = in.readInt() != 0;
    mFlags = in.readInt();
    mTableData.readFromParcel(in);
    readCompactedLongArray(in, version, mMemFactorDurations, mMemFactorDurations.length);
    if (!mSysMemUsage.readFromParcel(in)) {
        return;
    }
    int NPROC = in.readInt();
    if (NPROC < 0) {
        mReadError = "bad process count: " + NPROC;
        return;
    }
    while (NPROC > 0) {
        NPROC--;
        final String procName = readCommonString(in, version);
        if (procName == null) {
            mReadError = "bad process name";
            return;
        }
        int NUID = in.readInt();
        if (NUID < 0) {
            mReadError = "bad uid count: " + NUID;
            return;
        }
        while (NUID > 0) {
            NUID--;
            final int uid = in.readInt();
            if (uid < 0) {
                mReadError = "bad uid: " + uid;
                return;
            }
            final String pkgName = readCommonString(in, version);
            if (pkgName == null) {
                mReadError = "bad process package name";
                return;
            }
            final int vers = in.readInt();
            ProcessState proc = hadData ? mProcesses.get(procName, uid) : null;
            if (proc != null) {
                if (!proc.readFromParcel(in, false)) {
                    return;
                }
            } else {
                proc = new ProcessState(this, pkgName, uid, vers, procName);
                if (!proc.readFromParcel(in, true)) {
                    return;
                }
            }
            if (DEBUG_PARCEL)
                Slog.d(TAG, "Adding process: " + procName + " " + uid + " " + proc);
            mProcesses.put(procName, uid, proc);
        }
    }
    if (DEBUG_PARCEL)
        Slog.d(TAG, "Read " + mProcesses.getMap().size() + " processes");
    int NPKG = in.readInt();
    if (NPKG < 0) {
        mReadError = "bad package count: " + NPKG;
        return;
    }
    while (NPKG > 0) {
        NPKG--;
        final String pkgName = readCommonString(in, version);
        if (pkgName == null) {
            mReadError = "bad package name";
            return;
        }
        int NUID = in.readInt();
        if (NUID < 0) {
            mReadError = "bad uid count: " + NUID;
            return;
        }
        while (NUID > 0) {
            NUID--;
            final int uid = in.readInt();
            if (uid < 0) {
                mReadError = "bad uid: " + uid;
                return;
            }
            int NVERS = in.readInt();
            if (NVERS < 0) {
                mReadError = "bad versions count: " + NVERS;
                return;
            }
            while (NVERS > 0) {
                NVERS--;
                final int vers = in.readInt();
                PackageState pkgState = new PackageState(pkgName, uid);
                SparseArray<PackageState> vpkg = mPackages.get(pkgName, uid);
                if (vpkg == null) {
                    vpkg = new SparseArray<PackageState>();
                    mPackages.put(pkgName, uid, vpkg);
                }
                vpkg.put(vers, pkgState);
                int NPROCS = in.readInt();
                if (NPROCS < 0) {
                    mReadError = "bad package process count: " + NPROCS;
                    return;
                }
                while (NPROCS > 0) {
                    NPROCS--;
                    String procName = readCommonString(in, version);
                    if (procName == null) {
                        mReadError = "bad package process name";
                        return;
                    }
                    int hasProc = in.readInt();
                    if (DEBUG_PARCEL)
                        Slog.d(TAG, "Reading package " + pkgName + " " + uid + " process " + procName + " hasProc=" + hasProc);
                    ProcessState commonProc = mProcesses.get(procName, uid);
                    if (DEBUG_PARCEL)
                        Slog.d(TAG, "Got common proc " + procName + " " + uid + ": " + commonProc);
                    if (commonProc == null) {
                        mReadError = "no common proc: " + procName;
                        return;
                    }
                    if (hasProc != 0) {
                        // The process for this package is unique to the package; we
                        // need to load it.  We don't need to do anything about it if
                        // it is not unique because if someone later looks for it
                        // they will find and use it from the global procs.
                        ProcessState proc = hadData ? pkgState.mProcesses.get(procName) : null;
                        if (proc != null) {
                            if (!proc.readFromParcel(in, false)) {
                                return;
                            }
                        } else {
                            proc = new ProcessState(commonProc, pkgName, uid, vers, procName, 0);
                            if (!proc.readFromParcel(in, true)) {
                                return;
                            }
                        }
                        if (DEBUG_PARCEL)
                            Slog.d(TAG, "Adding package " + pkgName + " process: " + procName + " " + uid + " " + proc);
                        pkgState.mProcesses.put(procName, proc);
                    } else {
                        if (DEBUG_PARCEL)
                            Slog.d(TAG, "Adding package " + pkgName + " process: " + procName + " " + uid + " " + commonProc);
                        pkgState.mProcesses.put(procName, commonProc);
                    }
                }
                int NSRVS = in.readInt();
                if (NSRVS < 0) {
                    mReadError = "bad package service count: " + NSRVS;
                    return;
                }
                while (NSRVS > 0) {
                    NSRVS--;
                    String serviceName = in.readString();
                    if (serviceName == null) {
                        mReadError = "bad package service name";
                        return;
                    }
                    String processName = version > 9 ? readCommonString(in, version) : null;
                    ServiceState serv = hadData ? pkgState.mServices.get(serviceName) : null;
                    if (serv == null) {
                        serv = new ServiceState(this, pkgName, serviceName, processName, null);
                    }
                    if (!serv.readFromParcel(in)) {
                        return;
                    }
                    if (DEBUG_PARCEL)
                        Slog.d(TAG, "Adding package " + pkgName + " service: " + serviceName + " " + uid + " " + serv);
                    pkgState.mServices.put(serviceName, serv);
                }
            }
        }
    }
    // Fragmentation info
    final int NPAGETYPES = in.readInt();
    mPageTypeZones.clear();
    mPageTypeZones.ensureCapacity(NPAGETYPES);
    mPageTypeLabels.clear();
    mPageTypeLabels.ensureCapacity(NPAGETYPES);
    mPageTypeSizes.clear();
    mPageTypeSizes.ensureCapacity(NPAGETYPES);
    for (int i = 0; i < NPAGETYPES; i++) {
        mPageTypeZones.add(in.readInt());
        mPageTypeLabels.add(in.readString());
        mPageTypeSizes.add(in.createIntArray());
    }
    mIndexToCommonString = null;
    if (DEBUG_PARCEL)
        Slog.d(TAG, "Successfully read procstats!");
}
Also used : ProcessState(com.android.internal.app.procstats.ProcessState) ServiceState(com.android.internal.app.procstats.ServiceState)

Aggregations

ProcessState (com.android.internal.app.procstats.ProcessState)72 SparseArray (android.util.SparseArray)41 ServiceState (com.android.internal.app.procstats.ServiceState)41 ProcessStats (com.android.internal.app.procstats.ProcessStats)22 ArrayList (java.util.ArrayList)12 IProcessStats (com.android.internal.app.procstats.IProcessStats)6 ArraySet (android.util.ArraySet)5 FileInputStream (java.io.FileInputStream)5 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 ProcessMap (com.android.internal.app.ProcessMap)1