summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Rafal Slawik <rslawik@google.com> 2021-02-11 10:54:24 +0000
committer Rafal Slawik <rslawik@google.com> 2021-02-11 12:54:48 +0000
commit1cff69d2c9b6f5c39830c6ce6e079217a9f22a7c (patch)
treed9a062fafcb3fb30bde79a2dc92ea4aac94970e1
parent8f5e00025778f3b34af9095edb173b0939e7f0b4 (diff)
Do not keep the input array with CPU times
CpuTimePerUidFreq puller kept the input array with CPU times to avoid copies, but that array is owned by the reader and is mutated for each callback invocation. This corrupted the aggregated data. Bug: 157535126 Test: cmd stats pull-source 10010 Test: atest CpuStatsTests Change-Id: Icda6a71f558e582c5d5b497e2cca1d84deed8b99 Merged-In: Icda6a71f558e582c5d5b497e2cca1d84deed8b99
-rw-r--r--services/core/java/com/android/server/stats/pull/StatsPullAtomService.java27
1 files changed, 8 insertions, 19 deletions
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 96b53f0baa35..eb6b734807b0 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -1565,9 +1565,6 @@ public class StatsPullAtomService extends SystemService {
// Aggregate times for the same uids.
SparseArray<long[]> aggregated = new SparseArray<>();
mCpuUidFreqTimeReader.readAbsolute((uid, cpuFreqTimeMs) -> {
- // For uids known to be aggregated from many entries allow mutating in place to avoid
- // many copies. Otherwise, copy before aggregating.
- boolean mutateInPlace = false;
if (UserHandle.isIsolated(uid)) {
// Skip individual isolated uids because they are recycled and quickly removed from
// the underlying data source.
@@ -1575,26 +1572,18 @@ public class StatsPullAtomService extends SystemService {
} else if (UserHandle.isSharedAppGid(uid)) {
// All shared app gids are accounted together.
uid = LAST_SHARED_APPLICATION_GID;
- mutateInPlace = true;
- } else if (UserHandle.isApp(uid)) {
- // Apps are accounted under their app id.
+ } else {
+ // Everything else is accounted under their base uid.
uid = UserHandle.getAppId(uid);
}
long[] aggCpuFreqTimeMs = aggregated.get(uid);
- if (aggCpuFreqTimeMs != null) {
- if (!mutateInPlace) {
- aggCpuFreqTimeMs = Arrays.copyOf(aggCpuFreqTimeMs, cpuFreqTimeMs.length);
- aggregated.put(uid, aggCpuFreqTimeMs);
- }
- for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) {
- aggCpuFreqTimeMs[freqIndex] += cpuFreqTimeMs[freqIndex];
- }
- } else {
- if (mutateInPlace) {
- cpuFreqTimeMs = Arrays.copyOf(cpuFreqTimeMs, cpuFreqTimeMs.length);
- }
- aggregated.put(uid, cpuFreqTimeMs);
+ if (aggCpuFreqTimeMs == null) {
+ aggCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
+ aggregated.put(uid, aggCpuFreqTimeMs);
+ }
+ for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) {
+ aggCpuFreqTimeMs[freqIndex] += cpuFreqTimeMs[freqIndex];
}
});