summaryrefslogtreecommitdiff
path: root/ddms
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2013-05-30 08:47:58 -0700
committerSiva Velusamy <vsiva@google.com>2013-05-30 14:46:33 -0700
commitba20722ff9dfc852afeb85e253c3e2f9943c0a61 (patch)
treebd9872496930676421314e3ea6d56a9929e08566 /ddms
parente9648a04f796e1485150aa42821e6c7b22b5253e (diff)
downloadswt-ba20722ff9dfc852afeb85e253c3e2f9943c0a61.tar.gz
Better tracking of differences in heap allocations
The previous change to track differences between two allocations was incorrect - it would change the allocation info itself. This CL fixes that by actually having a separate object that stores the differences in allocation count between two snapshots, but delegating to one of the snapshots for all other information. Change-Id: I7106a6b2060739db1b3e1d8c048ffc3d082a0d25
Diffstat (limited to 'ddms')
-rw-r--r--ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeDiffAllocationInfo.java67
-rw-r--r--ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java30
2 files changed, 90 insertions, 7 deletions
diff --git a/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeDiffAllocationInfo.java b/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeDiffAllocationInfo.java
new file mode 100644
index 0000000..bdd9b39
--- /dev/null
+++ b/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeDiffAllocationInfo.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ddmuilib.heap;
+
+import com.android.ddmlib.NativeAllocationInfo;
+import com.android.ddmlib.NativeStackCallInfo;
+
+import java.util.List;
+
+/**
+ * {@link NativeDiffAllocationInfo} stores the difference in the allocation
+ * counts between two allocations with the same stack trace.
+ *
+ * Since only the allocation counts are different, it delegates all other functionality to
+ * one of the allocations and just maintains the allocation count.
+ */
+public class NativeDiffAllocationInfo extends NativeAllocationInfo {
+ private final NativeAllocationInfo info;
+
+ public NativeDiffAllocationInfo(NativeAllocationInfo cur, NativeAllocationInfo prev) {
+ super(cur.getSize(), getNewAllocations(cur, prev));
+ info = cur;
+ }
+
+ private static int getNewAllocations(NativeAllocationInfo n1, NativeAllocationInfo n2) {
+ return n1.getAllocationCount() - n2.getAllocationCount();
+ }
+
+ @Override
+ public boolean isStackCallResolved() {
+ return info.isStackCallResolved();
+ }
+
+ @Override
+ public List<Long> getStackCallAddresses() {
+ return info.getStackCallAddresses();
+ }
+
+ @Override
+ public synchronized List<NativeStackCallInfo> getResolvedStackCall() {
+ return info.getResolvedStackCall();
+ }
+
+ @Override
+ public synchronized NativeStackCallInfo getRelevantStackCallInfo() {
+ return info.getRelevantStackCallInfo();
+ }
+
+ @Override
+ public boolean isZygoteChild() {
+ return info.isZygoteChild();
+ }
+}
diff --git a/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java b/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java
index 783e5e4..e7977bb 100644
--- a/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java
+++ b/ddms/ddmuilib/src/main/java/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java
@@ -17,6 +17,7 @@
package com.android.ddmuilib.heap;
import com.android.ddmlib.NativeAllocationInfo;
+import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.HashSet;
@@ -58,17 +59,32 @@ public class NativeHeapDiffSnapshot extends NativeHeapSnapshot {
// 5 allocations at the stack trace. We need to subtract out the 3 from the first allocation
Set<NativeAllocationInfo> onlyInPrevious =
new HashSet<NativeAllocationInfo>(oldSnapshot.getAllocations());
+ Set<NativeAllocationInfo> newAllocations =
+ Sets.newHashSetWithExpectedSize(allocations.size());
+
onlyInPrevious.removeAll(newSnapshot.getAllocations());
- for (NativeAllocationInfo allocation : allocations) {
- for (NativeAllocationInfo old : onlyInPrevious) {
- if (allocation.stackEquals(old)) {
- allocation.subtract(old);
- break;
- }
+ for (NativeAllocationInfo current : allocations) {
+ NativeAllocationInfo old = getOldAllocationWithSameStack(current, onlyInPrevious);
+ if (old == null) {
+ newAllocations.add(current);
+ } else if (current.getAllocationCount() > old.getAllocationCount()) {
+ newAllocations.add(new NativeDiffAllocationInfo(current, old));
+ }
+ }
+
+ return new ArrayList<NativeAllocationInfo>(newAllocations);
+ }
+
+ private static NativeAllocationInfo getOldAllocationWithSameStack(
+ NativeAllocationInfo info,
+ Set<NativeAllocationInfo> allocations) {
+ for (NativeAllocationInfo a : allocations) {
+ if (info.getSize() == a.getSize() && info.stackEquals(a)) {
+ return a;
}
}
- return new ArrayList<NativeAllocationInfo>(allocations);
+ return null;
}
@Override