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

Commit f329d050 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Add kernel and native memory data to procstats."

parents b0586c92 f7097a5b
Loading
Loading
Loading
Loading
+481 −18

File changed.

Preview size limit exceeded, changes collapsed.

+3 −6
Original line number Diff line number Diff line
@@ -291,6 +291,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    final StopwatchTimer[] mBluetoothStateTimer = new StopwatchTimer[NUM_BLUETOOTH_STATES];

    int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
    long mMobileRadioActiveStartTime;
    StopwatchTimer mMobileRadioActiveTimer;
    StopwatchTimer mMobileRadioActivePerAppTimer;
    LongSamplingCounter mMobileRadioActiveAdjustedTime;
@@ -1425,10 +1426,6 @@ public final class BatteryStatsImpl extends BatteryStats {
            return 0;
        }

        long getLastUpdateTimeMs() {
            return mUpdateTime;
        }

        void stopRunningLocked(long elapsedRealtimeMs) {
            // Ignore attempt to stop a timer that isn't running
            if (mNesting == 0) {
@@ -2790,11 +2787,11 @@ public final class BatteryStatsImpl extends BatteryStats {
                    powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM
                            || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH;
            if (active) {
                realElapsedRealtimeMs = elapsedRealtime;
                mMobileRadioActiveStartTime = realElapsedRealtimeMs = elapsedRealtime;
                mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG;
            } else {
                realElapsedRealtimeMs = timestampNs / (1000*1000);
                long lastUpdateTimeMs = mMobileRadioActiveTimer.getLastUpdateTimeMs();
                long lastUpdateTimeMs = mMobileRadioActiveStartTime;
                if (realElapsedRealtimeMs < lastUpdateTimeMs) {
                    Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs
                            + " is before start time " + lastUpdateTimeMs);
+3 −2
Original line number Diff line number Diff line
@@ -1328,7 +1328,7 @@ public final class ActiveServices {
                        + " app=" + app);
            if (app != null && app.thread != null) {
                try {
                    app.addPackage(r.appInfo.packageName, mAm.mProcessStats);
                    app.addPackage(r.appInfo.packageName, r.appInfo.versionCode, mAm.mProcessStats);
                    realStartServiceLocked(r, app, execInFg);
                    return null;
                } catch (RemoteException e) {
@@ -1883,7 +1883,8 @@ public final class ActiveServices {

                    mPendingServices.remove(i);
                    i--;
                    proc.addPackage(sr.appInfo.packageName, mAm.mProcessStats);
                    proc.addPackage(sr.appInfo.packageName, sr.appInfo.versionCode,
                            mAm.mProcessStats);
                    realStartServiceLocked(sr, proc, sr.createdFromFg);
                    didSomething = true;
                }
+65 −4
Original line number Diff line number Diff line
@@ -569,6 +569,12 @@ public final class ActivityManagerService extends ActivityManagerNative
     */
    long mLastFullPssTime = SystemClock.uptimeMillis();
    /**
     * If set, the next time we collect PSS data we should do a full collection
     * with data from native processes and the kernel.
     */
    boolean mFullPssPending = false;
    /**
     * This is the process holding what we currently consider to be
     * the "home" activity.
@@ -1801,8 +1807,49 @@ public final class ActivityManagerService extends ActivityManagerNative
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case COLLECT_PSS_BG_MSG: {
                int i=0, num=0;
                long start = SystemClock.uptimeMillis();
                MemInfoReader memInfo = null;
                synchronized (ActivityManagerService.this) {
                    if (mFullPssPending) {
                        mFullPssPending = false;
                        memInfo = new MemInfoReader();
                    }
                }
                if (memInfo != null) {
                    updateCpuStatsNow();
                    long nativeTotalPss = 0;
                    synchronized (mProcessCpuThread) {
                        final int N = mProcessCpuTracker.countStats();
                        for (int j=0; j<N; j++) {
                            ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(j);
                            if (st.vsize <= 0 || st.uid >= Process.FIRST_APPLICATION_UID
                                    || st.uid == Process.SYSTEM_UID) {
                                // This is definitely an application process; skip it.
                                continue;
                            }
                            synchronized (mPidsSelfLocked) {
                                if (mPidsSelfLocked.indexOfKey(st.pid) >= 0) {
                                    // This is one of our own processes; skip it.
                                    continue;
                                }
                            }
                            nativeTotalPss += Debug.getPss(st.pid, null);
                        }
                    }
                    memInfo.readMemInfo();
                    synchronized (this) {
                        if (DEBUG_PSS) Slog.d(TAG, "Collected native and kernel memory in "
                                + (SystemClock.uptimeMillis()-start) + "ms");
                        mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                                memInfo.getFreeSizeKb(),
                                memInfo.getSwapTotalSizeKb()-memInfo.getSwapFreeSizeKb(),
                                memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()
                                        +memInfo.getSlabSizeKb(),
                                nativeTotalPss);
                    }
                }
                int i=0, num=0;
                long[] tmp = new long[1];
                do {
                    ProcessRecord proc;
@@ -2769,7 +2816,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                // come up (we have a pid but not yet its thread), so keep it.
                if (DEBUG_PROCESSES) Slog.v(TAG, "App already running: " + app);
                // If this is a new package in the process, add the package to the list
                app.addPackage(info.packageName, mProcessStats);
                app.addPackage(info.packageName, info.versionCode, mProcessStats);
                return app;
            }
@@ -2824,7 +2871,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        } else {
            // If this is a new package in the process, add the package to the list
            app.addPackage(info.packageName, mProcessStats);
            app.addPackage(info.packageName, info.versionCode, mProcessStats);
        }
        // If the system is not ready yet, then hold off on starting this
@@ -7780,7 +7827,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                    // to run in multiple processes, because this is actually
                    // part of the framework so doesn't make sense to track as a
                    // separate apk in the process.
                    app.addPackage(cpi.applicationInfo.packageName, mProcessStats);
                    app.addPackage(cpi.applicationInfo.packageName, cpi.applicationInfo.versionCode,
                            mProcessStats);
                }
                ensurePackageDexOpt(cpi.applicationInfo.packageName);
            }
@@ -12588,6 +12636,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        }
        long nativeProcTotalPss = 0;
        if (!isCheckinRequest && procs.size() > 1) {
            // If we are showing aggregations, also look for native processes to
            // include so that our aggregations are more accurate.
@@ -12609,6 +12659,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        final long myTotalPss = mi.getTotalPss();
                        totalPss += myTotalPss;
                        nativeProcTotalPss += myTotalPss;
                        MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")",
                                st.name, myTotalPss, st.pid, false);
@@ -12676,6 +12727,15 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            MemInfoReader memInfo = new MemInfoReader();
            memInfo.readMemInfo();
            if (nativeProcTotalPss > 0) {
                synchronized (this) {
                    mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                            memInfo.getFreeSizeKb(),
                            memInfo.getSwapTotalSizeKb()-memInfo.getSwapFreeSizeKb(),
                            memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()+memInfo.getSlabSizeKb(),
                            nativeProcTotalPss);
                }
            }
            if (!brief) {
                if (!isCompact) {
                    pw.print("Total RAM: "); pw.print(memInfo.getTotalSizeKb());
@@ -15456,6 +15516,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        if (DEBUG_PSS) Slog.d(TAG, "Requesting PSS of all procs!  memLowered=" + memLowered);
        mLastFullPssTime = now;
        mFullPssPending = true;
        mPendingPssProcesses.ensureCapacity(mLruProcesses.size());
        mPendingPssProcesses.clear();
        for (int i=mLruProcesses.size()-1; i>=0; i--) {
+2 −1
Original line number Diff line number Diff line
@@ -1178,7 +1178,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    // to run in multiple processes, because this is actually
                    // part of the framework so doesn't make sense to track as a
                    // separate apk in the process.
                    app.addPackage(r.info.packageName, mService.mProcessStats);
                    app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode,
                            mService.mProcessStats);
                }
                realStartActivityLocked(r, app, andResume, checkConfig);
                return;
Loading