Merge "Do not keep the input array with CPU times" into rvc-qpr-dev am: 5db3029c29

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13553569

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I878dc5bf4fd13736cf77de0a48c20ac60ceb1c62
This commit is contained in:
Rafal Slawik
2021-02-12 17:17:52 +00:00
committed by Automerger Merge Worker

View File

@@ -1565,9 +1565,6 @@ public class StatsPullAtomService extends SystemService {
// Aggregate times for the same uids. // Aggregate times for the same uids.
SparseArray<long[]> aggregated = new SparseArray<>(); SparseArray<long[]> aggregated = new SparseArray<>();
mCpuUidFreqTimeReader.readAbsolute((uid, cpuFreqTimeMs) -> { 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)) { if (UserHandle.isIsolated(uid)) {
// Skip individual isolated uids because they are recycled and quickly removed from // Skip individual isolated uids because they are recycled and quickly removed from
// the underlying data source. // the underlying data source.
@@ -1575,26 +1572,18 @@ public class StatsPullAtomService extends SystemService {
} else if (UserHandle.isSharedAppGid(uid)) { } else if (UserHandle.isSharedAppGid(uid)) {
// All shared app gids are accounted together. // All shared app gids are accounted together.
uid = LAST_SHARED_APPLICATION_GID; uid = LAST_SHARED_APPLICATION_GID;
mutateInPlace = true; } else {
} else if (UserHandle.isApp(uid)) { // Everything else is accounted under their base uid.
// Apps are accounted under their app id.
uid = UserHandle.getAppId(uid); uid = UserHandle.getAppId(uid);
} }
long[] aggCpuFreqTimeMs = aggregated.get(uid); long[] aggCpuFreqTimeMs = aggregated.get(uid);
if (aggCpuFreqTimeMs != null) { if (aggCpuFreqTimeMs == null) {
if (!mutateInPlace) { aggCpuFreqTimeMs = new long[cpuFreqTimeMs.length];
aggCpuFreqTimeMs = Arrays.copyOf(aggCpuFreqTimeMs, cpuFreqTimeMs.length); aggregated.put(uid, aggCpuFreqTimeMs);
aggregated.put(uid, aggCpuFreqTimeMs); }
} for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) {
for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) { aggCpuFreqTimeMs[freqIndex] += cpuFreqTimeMs[freqIndex];
aggCpuFreqTimeMs[freqIndex] += cpuFreqTimeMs[freqIndex];
}
} else {
if (mutateInPlace) {
cpuFreqTimeMs = Arrays.copyOf(cpuFreqTimeMs, cpuFreqTimeMs.length);
}
aggregated.put(uid, cpuFreqTimeMs);
} }
}); });