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

Commit 306af678 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix some problems with proc stats collection.

Also start debugging why we aren't being able to open
/proc files.

Change-Id: I4655904691ac22108c29858cbd01153a251ccbf5
parent 3dab92c5
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -442,8 +442,9 @@ public class ProcessCpuTracker {
                final String[] procStatsString = mProcessFullStatsStringData;
                final long[] procStats = mProcessFullStatsData;
                st.base_uptime = SystemClock.uptimeMillis();
                if (Process.readProcFile(st.statFile.toString(),
                        PROCESS_FULL_STATS_FORMAT, procStatsString,
                String path = st.statFile.toString();
                //Slog.d(TAG, "Reading proc file: " + path);
                if (Process.readProcFile(path, PROCESS_FULL_STATS_FORMAT, procStatsString,
                        procStats, null)) {
                    // This is a possible way to filter out processes that
                    // are actually kernel threads...  do we want to?  Some
+7 −3
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@
#define POLICY_DEBUG 0
#define GUARD_THREAD_PRIORITY 0

#define DEBUG_PROC(x) //x

using namespace android;

#if GUARD_THREAD_PRIORITY
@@ -725,6 +727,7 @@ jboolean android_os_Process_parseProcLineArray(JNIEnv* env, jobject clazz,
        const char term = (char)(mode&PROC_TERM_MASK);
        const jsize start = i;
        if (i >= endIndex) {
            DEBUG_PROC(ALOGW("Ran off end of data @%d", i));
            res = JNI_FALSE;
            break;
        }
@@ -822,19 +825,20 @@ jboolean android_os_Process_readProcFile(JNIEnv* env, jobject clazz,
        return JNI_FALSE;
    }
    int fd = open(file8, O_RDONLY);
    env->ReleaseStringUTFChars(file, file8);

    if (fd < 0) {
        //ALOGW("Unable to open process file: %s\n", file8);
        DEBUG_PROC(ALOGW("Unable to open process file: %s\n", file8));
        env->ReleaseStringUTFChars(file, file8);
        return JNI_FALSE;
    }
    env->ReleaseStringUTFChars(file, file8);

    char buffer[256];
    const int len = read(fd, buffer, sizeof(buffer)-1);
    close(fd);

    if (len < 0) {
        //ALOGW("Unable to open process file: %s fd=%d\n", file8, fd);
        DEBUG_PROC(ALOGW("Unable to open process file: %s fd=%d\n", file8, fd));
        return JNI_FALSE;
    }
    buffer[len] = 0;
+3 −6
Original line number Diff line number Diff line
@@ -1832,8 +1832,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        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) {
                            if (st.vsize <= 0 || st.uid >= Process.FIRST_APPLICATION_UID) {
                                // This is definitely an application process; skip it.
                                continue;
                            }
@@ -1851,8 +1850,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        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.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                                memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()
                                        +memInfo.getSlabSizeKb(),
                                nativeTotalPss);
@@ -12823,8 +12821,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (nativeProcTotalPss > 0) {
                synchronized (this) {
                    mProcessStats.addSysMemUsageLocked(memInfo.getCachedSizeKb(),
                            memInfo.getFreeSizeKb(),
                            memInfo.getSwapTotalSizeKb()-memInfo.getSwapFreeSizeKb(),
                            memInfo.getFreeSizeKb(), memInfo.getZramTotalSizeKb(),
                            memInfo.getBuffersSizeKb()+memInfo.getShmemSizeKb()+memInfo.getSlabSizeKb(),
                            nativeProcTotalPss);
                }