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

Commit 9a30c11b authored by Misha Wagner's avatar Misha Wagner
Browse files

Revert "Filter threads that have low total CPU usage for CpuTimePerThreadFreq"

This reverts commit 474e7bec.

Reason for revert: Thresholding could cause confusion in data, and doesn't reduce data enough to solve problems.

Change-Id: I5bc8774212aced24e3a07fc3096402708e0d6418
parent 474e7bec
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -108,13 +108,6 @@ public class KernelCpuThreadReader {
    private static final Predicate<Integer> DEFAULT_UID_PREDICATE =
            uid -> 1000 <= uid && uid < 2000;

    /**
     * Do not report any threads that have a total CPU usage (across all frequencies) less than or
     * equal to this number. This significantly reduces the amount of reported threads without
     * losing any important information
     */
    private static final int TOTAL_CPU_USAGE_THRESHOLD_MILLIS = 20;

    /**
     * Value returned when there was an error getting an integer ID value (e.g. PID, UID)
     */
@@ -346,15 +339,6 @@ public class KernelCpuThreadReader {
        }
        int[] cpuUsages = mFrequencyBucketCreator.getBucketedValues(cpuUsagesLong);

        // Filter threads that have low total CPU usage
        int cpuUsageSum = 0;
        for (int i = 0; i < cpuUsages.length; i++) {
            cpuUsageSum += cpuUsages[i];
        }
        if (cpuUsageSum <= TOTAL_CPU_USAGE_THRESHOLD_MILLIS) {
            return null;
        }

        return new ThreadCpuUsage(threadId, threadName, cpuUsages);
    }

+4 −42
Original line number Diff line number Diff line
@@ -39,9 +39,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -58,8 +56,8 @@ public class KernelCpuThreadReaderTest {
            1000, 2000, 3000, 4000,
    };
    private static final int[][] THREAD_CPU_TIMES = {
            {100, 0, 0, 100},
            {0, 0, 9999999, 0},
            {1, 0, 0, 1},
            {0, 0, 0, 0},
            {1000, 1000, 1000, 1000},
            {0, 1, 2, 3},
    };
@@ -109,42 +107,6 @@ public class KernelCpuThreadReaderTest {
                THREAD_IDS, PROCESS_NAME, THREAD_NAMES, THREAD_CPU_FREQUENCIES, THREAD_CPU_TIMES);
    }

    @Test
    public void testReader_filtersLowTotalCpuUsage() throws IOException {
        KernelCpuThreadReader.Injector processUtils =
                new KernelCpuThreadReader.Injector() {
                    @Override
                    public int myPid() {
                        return PROCESS_ID;
                    }

                    @Override
                    public int myUid() {
                        return UID;
                    }

                    @Override
                    public int getUidForPid(int pid) {
                        return 0;
                    }
                };
        setupDirectory(mProcDirectory.toPath().resolve("self"), new int[]{1, 2}, PROCESS_NAME,
                THREAD_NAMES, new int[]{1000, 2000}, new int[][]{{0, 1}, {100, 0}});

        final KernelCpuThreadReader kernelCpuThreadReader = new KernelCpuThreadReader(
                mProcDirectory.toPath(),
                mProcDirectory.toPath().resolve("self/task/1/time_in_state"),
                processUtils);
        final KernelCpuThreadReader.ProcessCpuUsage processCpuUsage =
                kernelCpuThreadReader.getCurrentProcessCpuUsage();

        List<Integer> threadIds = processCpuUsage.threadCpuUsages.stream()
                .map(t -> t.threadId)
                .collect(Collectors.toList());
        assertEquals(1, threadIds.size());
        assertEquals(2, (long) threadIds.get(0));
    }

    @Test
    public void testReader_byUids() throws IOException {
        int[] uids = new int[]{0, 2, 3, 4, 5, 6000};
@@ -172,7 +134,7 @@ public class KernelCpuThreadReaderTest {
            setupDirectory(mProcDirectory.toPath().resolve(String.valueOf(uid)),
                    new int[]{uid * 10},
                    "process" + uid, new String[]{"thread" + uid}, new int[]{1000},
                    new int[][]{{uid + 100}});
                    new int[][]{{uid}});
        }
        final KernelCpuThreadReader kernelCpuThreadReader = new KernelCpuThreadReader(
                mProcDirectory.toPath(),
@@ -189,7 +151,7 @@ public class KernelCpuThreadReaderTest {
            int uid = expectedUids[i];
            checkResults(processCpuUsage, kernelCpuThreadReader.getCpuFrequenciesKhz(),
                    uid, uid, new int[]{uid * 10}, "process" + uid, new String[]{"thread" + uid},
                    new int[]{1000}, new int[][]{{uid + 100}});
                    new int[]{1000}, new int[][]{{uid}});
        }
    }