Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fd8ce49 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix a few issues with procstats associations:

- Use the correct state when comparing the association
  with the process.  (Was causing warning spam as well.)

- Don't wtf if we call startAssociationIfNeeded() no a
  ServiceRecord that doesn't have a process...  that is normal
  when first bringing up a service.

Also add a switch to turn this all off, which for now is
leaving it on.

Test: manual
Bug: 111391911
Bug: 111302807
Bug: 111131998

Change-Id: I2d3f43fd99c7ade24c867ad80a728d898ab0e6c5
parent 95031ef2
Loading
Loading
Loading
Loading
+31 −31
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ public final class ProcessState {
    private final PssTable mPssTable;
    private final PssTable mPssTable;


    private ProcessState mCommonProcess;
    private ProcessState mCommonProcess;
    private int mCurState = STATE_NOTHING;
    private int mCurCombinedState = STATE_NOTHING;
    private long mStartTime;
    private long mStartTime;


    private int mLastPssState = STATE_NOTHING;
    private int mLastPssState = STATE_NOTHING;
@@ -180,7 +180,7 @@ public final class ProcessState {
        mPackage = pkg;
        mPackage = pkg;
        mUid = uid;
        mUid = uid;
        mVersion = vers;
        mVersion = vers;
        mCurState = commonProcess.mCurState;
        mCurCombinedState = commonProcess.mCurCombinedState;
        mStartTime = now;
        mStartTime = now;
        mDurations = new DurationsTable(commonProcess.mStats.mTableData);
        mDurations = new DurationsTable(commonProcess.mStats.mTableData);
        mPssTable = new PssTable(commonProcess.mStats.mTableData);
        mPssTable = new PssTable(commonProcess.mStats.mTableData);
@@ -324,7 +324,7 @@ public final class ProcessState {


    public boolean isInUse() {
    public boolean isInUse() {
        return mActive || mNumActiveServices > 0 || mNumStartedServices > 0
        return mActive || mNumActiveServices > 0 || mNumStartedServices > 0
                || mCurState != STATE_NOTHING;
                || mCurCombinedState != STATE_NOTHING;
    }
    }


    public boolean isActive() {
    public boolean isActive() {
@@ -333,7 +333,7 @@ public final class ProcessState {


    public boolean hasAnyData() {
    public boolean hasAnyData() {
        return !(mDurations.getKeyCount() == 0
        return !(mDurations.getKeyCount() == 0
                && mCurState == STATE_NOTHING
                && mCurCombinedState == STATE_NOTHING
                && mPssTable.getKeyCount() == 0);
                && mPssTable.getKeyCount() == 0);
    }
    }


@@ -355,7 +355,7 @@ public final class ProcessState {
        }
        }


        // First update the common process.
        // First update the common process.
        mCommonProcess.setState(state, now);
        mCommonProcess.setCombinedState(state, now);


        // If the common process is not multi-package, there is nothing else to do.
        // If the common process is not multi-package, there is nothing else to do.
        if (!mCommonProcess.mMultiPackage) {
        if (!mCommonProcess.mMultiPackage) {
@@ -364,29 +364,29 @@ public final class ProcessState {


        if (pkgList != null) {
        if (pkgList != null) {
            for (int ip=pkgList.size()-1; ip>=0; ip--) {
            for (int ip=pkgList.size()-1; ip>=0; ip--) {
                pullFixedProc(pkgList, ip).setState(state, now);
                pullFixedProc(pkgList, ip).setCombinedState(state, now);
            }
            }
        }
        }
    }
    }


    public void setState(int state, long now) {
    public void setCombinedState(int state, long now) {
        ensureNotDead();
        ensureNotDead();
        if (!mDead && (mCurState != state)) {
        if (!mDead && (mCurCombinedState != state)) {
            //Slog.i(TAG, "Setting state in " + mName + "/" + mPackage + ": " + state);
            //Slog.i(TAG, "Setting state in " + mName + "/" + mPackage + ": " + state);
            commitStateTime(now);
            commitStateTime(now);
            mCurState = state;
            mCurCombinedState = state;
        }
        }
    }
    }


    public int getState() {
    public int getCombinedState() {
        return mCurState;
        return mCurCombinedState;
    }
    }


    public void commitStateTime(long now) {
    public void commitStateTime(long now) {
        if (mCurState != STATE_NOTHING) {
        if (mCurCombinedState != STATE_NOTHING) {
            long dur = now - mStartTime;
            long dur = now - mStartTime;
            if (dur > 0) {
            if (dur > 0) {
                mDurations.addDuration(mCurState, dur);
                mDurations.addDuration(mCurCombinedState, dur);
            }
            }
        }
        }
        mStartTime = now;
        mStartTime = now;
@@ -434,8 +434,8 @@ public final class ProcessState {
            mCommonProcess.incStartedServices(memFactor, now, serviceName);
            mCommonProcess.incStartedServices(memFactor, now, serviceName);
        }
        }
        mNumStartedServices++;
        mNumStartedServices++;
        if (mNumStartedServices == 1 && mCurState == STATE_NOTHING) {
        if (mNumStartedServices == 1 && mCurCombinedState == STATE_NOTHING) {
            setState(STATE_SERVICE_RESTARTING + (memFactor*STATE_COUNT), now);
            setCombinedState(STATE_SERVICE_RESTARTING + (memFactor*STATE_COUNT), now);
        }
        }
    }
    }


@@ -450,8 +450,8 @@ public final class ProcessState {
            mCommonProcess.decStartedServices(memFactor, now, serviceName);
            mCommonProcess.decStartedServices(memFactor, now, serviceName);
        }
        }
        mNumStartedServices--;
        mNumStartedServices--;
        if (mNumStartedServices == 0 && (mCurState%STATE_COUNT) == STATE_SERVICE_RESTARTING) {
        if (mNumStartedServices == 0 && (mCurCombinedState %STATE_COUNT) == STATE_SERVICE_RESTARTING) {
            setState(STATE_NOTHING, now);
            setCombinedState(STATE_NOTHING, now);
        } else if (mNumStartedServices < 0) {
        } else if (mNumStartedServices < 0) {
            Slog.wtfStack(TAG, "Proc started services underrun: pkg="
            Slog.wtfStack(TAG, "Proc started services underrun: pkg="
                    + mPackage + " uid=" + mUid + " name=" + mName);
                    + mPackage + " uid=" + mUid + " name=" + mName);
@@ -485,16 +485,16 @@ public final class ProcessState {
                break;
                break;
        }
        }
        if (!always) {
        if (!always) {
            if (mLastPssState == mCurState && SystemClock.uptimeMillis()
            if (mLastPssState == mCurCombinedState && SystemClock.uptimeMillis()
                    < (mLastPssTime+(30*1000))) {
                    < (mLastPssTime+(30*1000))) {
                return;
                return;
            }
            }
        }
        }
        mLastPssState = mCurState;
        mLastPssState = mCurCombinedState;
        mLastPssTime = SystemClock.uptimeMillis();
        mLastPssTime = SystemClock.uptimeMillis();
        if (mCurState != STATE_NOTHING) {
        if (mCurCombinedState != STATE_NOTHING) {
            // First update the common process.
            // First update the common process.
            mCommonProcess.mPssTable.mergeStats(mCurState, 1, pss, pss, pss, uss, uss, uss,
            mCommonProcess.mPssTable.mergeStats(mCurCombinedState, 1, pss, pss, pss, uss, uss, uss,
                    rss, rss, rss);
                    rss, rss, rss);


            // If the common process is not multi-package, there is nothing else to do.
            // If the common process is not multi-package, there is nothing else to do.
@@ -504,7 +504,7 @@ public final class ProcessState {


            if (pkgList != null) {
            if (pkgList != null) {
                for (int ip=pkgList.size()-1; ip>=0; ip--) {
                for (int ip=pkgList.size()-1; ip>=0; ip--) {
                    pullFixedProc(pkgList, ip).mPssTable.mergeStats(mCurState, 1,
                    pullFixedProc(pkgList, ip).mPssTable.mergeStats(mCurCombinedState, 1,
                            pss, pss, pss, uss, uss, uss, rss, rss, rss);
                            pss, pss, pss, uss, uss, uss, rss, rss, rss);
                }
                }
            }
            }
@@ -623,7 +623,7 @@ public final class ProcessState {


    public long getDuration(int state, long now) {
    public long getDuration(int state, long now) {
        long time = mDurations.getValueForId((byte)state);
        long time = mDurations.getValueForId((byte)state);
        if (mCurState == state) {
        if (mCurCombinedState == state) {
            time += now - mStartTime;
            time += now - mStartTime;
        }
        }
        return time;
        return time;
@@ -728,7 +728,7 @@ public final class ProcessState {
            final int key = mDurations.getKeyAt(i);
            final int key = mDurations.getKeyAt(i);
            final int type = SparseMappingTable.getIdFromKey(key);
            final int type = SparseMappingTable.getIdFromKey(key);
            long time = mDurations.getValue(key);
            long time = mDurations.getValue(key);
            if (mCurState == type) {
            if (mCurCombinedState == type) {
                time += now - mStartTime;
                time += now - mStartTime;
            }
            }
            final int procState = type % STATE_COUNT;
            final int procState = type % STATE_COUNT;
@@ -831,7 +831,7 @@ public final class ProcessState {
                    final int bucket = ((iscreen + imem) * STATE_COUNT) + procStates[ip];
                    final int bucket = ((iscreen + imem) * STATE_COUNT) + procStates[ip];
                    long time = mDurations.getValueForId((byte)bucket);
                    long time = mDurations.getValueForId((byte)bucket);
                    String running = "";
                    String running = "";
                    if (mCurState == bucket) {
                    if (mCurCombinedState == bucket) {
                        running = " (running)";
                        running = " (running)";
                    }
                    }
                    if (time != 0) {
                    if (time != 0) {
@@ -1181,14 +1181,14 @@ public final class ProcessState {
            final int key = mDurations.getKeyAt(i);
            final int key = mDurations.getKeyAt(i);
            final int type = SparseMappingTable.getIdFromKey(key);
            final int type = SparseMappingTable.getIdFromKey(key);
            long time = mDurations.getValue(key);
            long time = mDurations.getValue(key);
            if (mCurState == type) {
            if (mCurCombinedState == type) {
                didCurState = true;
                didCurState = true;
                time += now - mStartTime;
                time += now - mStartTime;
            }
            }
            DumpUtils.printProcStateTagAndValue(pw, type, time);
            DumpUtils.printProcStateTagAndValue(pw, type, time);
        }
        }
        if (!didCurState && mCurState != STATE_NOTHING) {
        if (!didCurState && mCurCombinedState != STATE_NOTHING) {
            DumpUtils.printProcStateTagAndValue(pw, mCurState, now - mStartTime);
            DumpUtils.printProcStateTagAndValue(pw, mCurCombinedState, now - mStartTime);
        }
        }
    }
    }


@@ -1255,14 +1255,14 @@ public final class ProcessState {
            final int key = mDurations.getKeyAt(i);
            final int key = mDurations.getKeyAt(i);
            final int type = SparseMappingTable.getIdFromKey(key);
            final int type = SparseMappingTable.getIdFromKey(key);
            long time = mDurations.getValue(key);
            long time = mDurations.getValue(key);
            if (mCurState == type) {
            if (mCurCombinedState == type) {
                didCurState = true;
                didCurState = true;
                time += now - mStartTime;
                time += now - mStartTime;
            }
            }
            durationByState.put(type, time);
            durationByState.put(type, time);
        }
        }
        if (!didCurState && mCurState != STATE_NOTHING) {
        if (!didCurState && mCurCombinedState != STATE_NOTHING) {
            durationByState.put(mCurState, now - mStartTime);
            durationByState.put(mCurCombinedState, now - mStartTime);
        }
        }


        for (int i=0; i<mPssTable.getKeyCount(); i++) {
        for (int i=0; i<mPssTable.getKeyCount(); i++) {
+4 −3
Original line number Original line Diff line number Diff line
@@ -1387,14 +1387,15 @@ public final class ProcessStats implements Parcelable {
            } else {
            } else {
                final ProcessState proc = act.getAssociationState().getProcess();
                final ProcessState proc = act.getAssociationState().getProcess();
                if (proc != null) {
                if (proc != null) {
                    if (act.mProcState == proc.getState()) {
                    final int procState = proc.getCombinedState() % STATE_COUNT;
                    if (act.mProcState == procState) {
                        act.startActive(now);
                        act.startActive(now);
                    } else {
                    } else {
                        act.stopActive(now);
                        act.stopActive(now);
                        if (act.mProcState < proc.getState()) {
                        if (act.mProcState < procState) {
                            Slog.w(TAG, "Tracking association " + act + " whose proc state "
                            Slog.w(TAG, "Tracking association " + act + " whose proc state "
                                    + act.mProcState + " is better than process " + proc
                                    + act.mProcState + " is better than process " + proc
                                    + " proc state " + proc.getState());
                                    + " proc state " + procState);
                        }
                        }
                    }
                    }
                } else {
                } else {
+3 −0
Original line number Original line Diff line number Diff line
@@ -520,6 +520,9 @@ public class ActivityManagerService extends IActivityManager.Stub
    // Used to indicate that an app transition should be animated.
    // Used to indicate that an app transition should be animated.
    static final boolean ANIMATE = true;
    static final boolean ANIMATE = true;
    // If set, we will push process association information in to procstats.
    static final boolean TRACK_PROCSTATS_ASSOCIATIONS = true;
    /**
    /**
     * Default value for {@link Settings.Global#NETWORK_ACCESS_TIMEOUT_MS}.
     * Default value for {@link Settings.Global#NETWORK_ACCESS_TIMEOUT_MS}.
     */
     */
+6 −4
Original line number Original line Diff line number Diff line
@@ -108,10 +108,12 @@ final class ConnectionRecord {
    public void startAssociationIfNeeded() {
    public void startAssociationIfNeeded() {
        // If we don't already have an active association, create one...  but only if this
        // If we don't already have an active association, create one...  but only if this
        // is an association between two different processes.
        // is an association between two different processes.
        if (association == null && (binding.service.appInfo.uid != clientUid
        if (ActivityManagerService.TRACK_PROCSTATS_ASSOCIATIONS
                && association == null && binding.service.app != null
                && (binding.service.appInfo.uid != clientUid
                        || !binding.service.processName.equals(clientProcessName))) {
                        || !binding.service.processName.equals(clientProcessName))) {
            ProcessStats.ProcessStateHolder holder = binding.service.app != null
            ProcessStats.ProcessStateHolder holder = binding.service.app.pkgList.get(
                    ? binding.service.app.pkgList.get(binding.service.name.getPackageName()) : null;
                    binding.service.name.getPackageName());
            if (holder == null) {
            if (holder == null) {
                Slog.wtf(TAG_AM, "No package in referenced service "
                Slog.wtf(TAG_AM, "No package in referenced service "
                        + binding.service.name.toShortString() + ": proc=" + binding.service.app);
                        + binding.service.name.toShortString() + ": proc=" + binding.service.app);
+6 −4
Original line number Original line Diff line number Diff line
@@ -55,10 +55,12 @@ public final class ContentProviderConnection extends Binder {
    public void startAssociationIfNeeded() {
    public void startAssociationIfNeeded() {
        // If we don't already have an active association, create one...  but only if this
        // If we don't already have an active association, create one...  but only if this
        // is an association between two different processes.
        // is an association between two different processes.
        if (association == null && (provider.appInfo.uid != client.uid
        if (ActivityManagerService.TRACK_PROCSTATS_ASSOCIATIONS
                && association == null && provider.proc != null
                && (provider.appInfo.uid != client.uid
                        || !provider.info.processName.equals(client.processName))) {
                        || !provider.info.processName.equals(client.processName))) {
            ProcessStats.ProcessStateHolder holder = provider.proc != null
            ProcessStats.ProcessStateHolder holder = provider.proc.pkgList.get(
                    ? provider.proc.pkgList.get(provider.name.getPackageName()) : null;
                    provider.name.getPackageName());
            if (holder == null) {
            if (holder == null) {
                Slog.wtf(TAG_AM, "No package in referenced provider "
                Slog.wtf(TAG_AM, "No package in referenced provider "
                        + provider.name.toShortString() + ": proc=" + provider.proc);
                        + provider.name.toShortString() + ": proc=" + provider.proc);
Loading