From 59504338fc5e85dead2c08af6dc70501e4adb224 Mon Sep 17 00:00:00 2001 From: Rafal Slawik Date: Fri, 30 Oct 2020 14:35:13 +0000 Subject: [PATCH] CPU time min threshold for CpuTimePerUidFreq Introduce a threshold to exclude small CPU time values in CpuTimePerUidFreq. They come from more precise accounting in a BPF program. The threshold is 10 ms to match the behavior of the time_in_state BPF predecessor. The reducation in data size is expected be at least 20%. Bug: 157535126 Test: adb shell cmd stats pull-source 10010 Change-Id: Ia7f2a2ad71831387cffdd6db30da4ce501219d0e Merged-In: Ia7f2a2ad71831387cffdd6db30da4ce501219d0e (cherry picked from commit a79cf88cb7ec363691ceba889ab9d2a85d8ca113) --- .../android/server/stats/pull/StatsPullAtomService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java index 8f3ed7411f171..3b73c1e92cc2e 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -249,6 +249,13 @@ public class StatsPullAtomService extends SystemService { // 20% as a conservative estimate. private static final int MAX_PROCSTATS_RAW_SHARD_SIZE = (int) (MAX_PROCSTATS_SHARD_SIZE * 1.20); + /** + * Threshold to filter out small CPU times at frequency per UID. Those small values appear + * because of more precise accounting in a BPF program. Discarding them reduces the data by at + * least 20% with negligible error. + */ + private static final int MIN_CPU_TIME_PER_UID_FREQ = 10; + private final Object mThermalLock = new Object(); @GuardedBy("mThermalLock") private IThermalService mThermalService; @@ -1556,7 +1563,7 @@ public class StatsPullAtomService extends SystemService { int pullCpuTimePerUidFreqLocked(int atomTag, List pulledData) { mCpuUidFreqTimeReader.readAbsolute((uid, cpuFreqTimeMs) -> { for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) { - if (cpuFreqTimeMs[freqIndex] != 0) { + if (cpuFreqTimeMs[freqIndex] >= MIN_CPU_TIME_PER_UID_FREQ) { StatsEvent e = StatsEvent.newBuilder() .setAtomId(atomTag) .writeInt(uid)