Loading core/java/com/android/internal/os/KernelCpuThreadReader.java +0 −16 Original line number Diff line number Diff line Loading @@ -107,13 +107,6 @@ public class KernelCpuThreadReader { */ private static final Predicate<Integer> DEFAULT_UID_PREDICATE = uid -> uid == 1000; /** * 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) */ Loading Loading @@ -345,15 +338,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); } Loading core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java +4 −42 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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}, }; Loading Loading @@ -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}; Loading Loading @@ -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(), Loading @@ -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}}); } } Loading Loading
core/java/com/android/internal/os/KernelCpuThreadReader.java +0 −16 Original line number Diff line number Diff line Loading @@ -107,13 +107,6 @@ public class KernelCpuThreadReader { */ private static final Predicate<Integer> DEFAULT_UID_PREDICATE = uid -> uid == 1000; /** * 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) */ Loading Loading @@ -345,15 +338,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); } Loading
core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java +4 −42 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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}, }; Loading Loading @@ -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}; Loading Loading @@ -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(), Loading @@ -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}}); } } Loading