aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2011-09-30 13:55:31 -0700
committerSiva Velusamy <vsiva@google.com>2011-10-06 11:34:26 -0700
commit9a8de7350e1f8fb3a99c62c769e448d8e277f8fb (patch)
tree226fe66f682a3cc4300264019d3b48014c0cc903 /ddms/libs
parent14b0907ed9b802a1d9ecc3ad543203f1b4788532 (diff)
downloadsdk-9a8de7350e1f8fb3a99c62c769e448d8e277f8fb.zip
sdk-9a8de7350e1f8fb3a99c62c769e448d8e277f8fb.tar.gz
sdk-9a8de7350e1f8fb3a99c62c769e448d8e277f8fb.tar.bz2
Model diff snapshot as a subtype of a regular snapshot.
Change-Id: Ic701255c586530214b51a1553b66aa60c6c7b538
Diffstat (limited to 'ddms/libs')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/Addr2Line.java2
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java65
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java40
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapSnapshot.java14
4 files changed, 94 insertions, 27 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/Addr2Line.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/Addr2Line.java
index e5f4bf8..10799ec 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/Addr2Line.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/Addr2Line.java
@@ -211,7 +211,7 @@ public class Addr2Line {
String fullPath = getLibraryPath(mLibrary.getLibraryName());
if (fullPath == null) {
- String msg = String.format(LIBRARY_NOT_FOUND_MESSAGE_FORMAT, mLibrary);
+ String msg = String.format(LIBRARY_NOT_FOUND_MESSAGE_FORMAT, mLibrary.getLibraryName());
Log.e("ddm-Addr2Line", msg);
return false;
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java
new file mode 100644
index 0000000..9eb6ddf
--- /dev/null
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapDiffSnapshot.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 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 java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Models a heap snapshot that is the difference between two snapshots.
+ */
+public class NativeHeapDiffSnapshot extends NativeHeapSnapshot {
+ private long mCommonAllocationsTotalMemory;
+
+ public NativeHeapDiffSnapshot(NativeHeapSnapshot newSnapshot, NativeHeapSnapshot oldSnapshot) {
+ // The diff snapshots behaves like a snapshot that only contains the new allocations
+ // not present in the old snapshot
+ super(getNewAllocations(newSnapshot, oldSnapshot));
+
+ Set<NativeAllocationInfo> commonAllocations =
+ new HashSet<NativeAllocationInfo>(oldSnapshot.getAllocations());
+ commonAllocations.retainAll(newSnapshot.getAllocations());
+
+ // Memory common between the old and new snapshots
+ mCommonAllocationsTotalMemory = getTotalMemory(commonAllocations);
+ }
+
+ private static List<NativeAllocationInfo> getNewAllocations(NativeHeapSnapshot newSnapshot,
+ NativeHeapSnapshot oldSnapshot) {
+ Set<NativeAllocationInfo> allocations =
+ new HashSet<NativeAllocationInfo>(newSnapshot.getAllocations());
+ allocations.removeAll(oldSnapshot.getAllocations());
+ return new ArrayList<NativeAllocationInfo>(allocations);
+ }
+
+ @Override
+ public String getFormattedMemorySize() {
+ // for a diff snapshot, we report the following string for display:
+ // xxx bytes new allocation + yyy bytes retained from previous allocation
+ // = zzz bytes total
+
+ long newAllocations = getTotalSize();
+ return String.format("%s bytes new + %s bytes retained = %s bytes total",
+ formatMemorySize(newAllocations),
+ formatMemorySize(mCommonAllocationsTotalMemory),
+ formatMemorySize(newAllocations + mCommonAllocationsTotalMemory));
+ }
+}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java
index 2bab43b..6af195c 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java
@@ -67,7 +67,6 @@ import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
-import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -94,8 +93,6 @@ public class NativeHeapPanel extends BaseHeapPanel {
"Colon separated paths that contain unstripped libraries with debug symbols.\n"
+ "e.g.: <android-src>/out/target/product/generic/symbols/system/lib:/path/to/my/app/obj/local/armeabi";
- private static final NumberFormat NUMBER_FORMATTER = NumberFormat.getInstance();
-
private static final String PREFS_SHOW_DIFFS_ONLY = "nativeheap.show.diffs.only";
private static final String PREFS_SHOW_ZYGOTE_ALLOCATIONS = "nativeheap.show.zygote";
private static final String PREFS_GROUP_BY_LIBRARY = "nativeheap.grouby.library";
@@ -245,36 +242,31 @@ public class NativeHeapPanel extends BaseHeapPanel {
snapshot = getDiffSnapshot(index);
}
- long totalSize = snapshot.getTotalSize();
+ mMemoryAllocatedText.setText(snapshot.getFormattedMemorySize());
+ mMemoryAllocatedText.pack();
- mDetailsTreeLabelProvider.setTotalSize(totalSize);
+ mDetailsTreeLabelProvider.setTotalSize(snapshot.getTotalSize());
mDetailsTreeViewer.setInput(snapshot);
- mMemoryAllocatedText.setText(formatMemorySize(totalSize));
- mMemoryAllocatedText.pack();
mDetailsTreeViewer.refresh();
}
/** Obtain the diff of snapshot[index] & snapshot[index-1] */
private NativeHeapSnapshot getDiffSnapshot(int index) {
// if it was already computed, simply return that
- NativeHeapSnapshot snapshot = mDiffSnapshots.get(index);
- if (snapshot != null) {
- return snapshot;
+ NativeHeapSnapshot diffSnapshot = mDiffSnapshots.get(index);
+ if (diffSnapshot != null) {
+ return diffSnapshot;
}
// compute the diff
- List<NativeAllocationInfo> cur = mNativeHeapSnapshots.get(index).getAllocations();
- List<NativeAllocationInfo> prev = mNativeHeapSnapshots.get(index - 1).getAllocations();
-
- List<NativeAllocationInfo> allocations = new ArrayList<NativeAllocationInfo>();
- allocations.addAll(cur);
- allocations.removeAll(prev);
- snapshot = new NativeHeapSnapshot(allocations);
+ NativeHeapSnapshot cur = mNativeHeapSnapshots.get(index);
+ NativeHeapSnapshot prev = mNativeHeapSnapshots.get(index - 1);
+ diffSnapshot = new NativeHeapDiffSnapshot(cur, prev);
// cache for future use
- mDiffSnapshots.set(index, snapshot);
+ mDiffSnapshots.set(index, diffSnapshot);
- return snapshot;
+ return diffSnapshot;
}
private void updateDisplayGrouping() {
@@ -300,10 +292,6 @@ public class NativeHeapPanel extends BaseHeapPanel {
mDetailsTreeViewer.refresh();
}
- private String formatMemorySize(long totalMemory) {
- return NUMBER_FORMATTER.format(totalMemory) + " bytes";
- }
-
private void updateSnapshotIndexCombo() {
List<String> items = new ArrayList<String>();
@@ -569,10 +557,13 @@ public class NativeHeapPanel extends BaseHeapPanel {
/** Export currently displayed snapshot to a file */
private void exportSnapshot() {
+ int idx = mSnapshotIndexCombo.getSelectionIndex();
+ String snapshotName = mSnapshotIndexCombo.getItem(idx);
+
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(),
SWT.SAVE);
- fileDialog.setText("Save Allocations");
+ fileDialog.setText("Save " + snapshotName);
fileDialog.setFileName("allocations.txt");
final String fileName = fileDialog.open();
@@ -580,7 +571,6 @@ public class NativeHeapPanel extends BaseHeapPanel {
return;
}
- int idx = mSnapshotIndexCombo.getSelectionIndex();
final NativeHeapSnapshot snapshot = mNativeHeapSnapshots.get(idx);
Thread t = new Thread(new Runnable() {
public void run() {
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapSnapshot.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapSnapshot.java
index ce340ba..e2023d2 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapSnapshot.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapSnapshot.java
@@ -18,7 +18,9 @@ package com.android.ddmuilib.heap;
import com.android.ddmlib.NativeAllocationInfo;
+import java.text.NumberFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
/**
@@ -28,6 +30,8 @@ import java.util.List;
* other objects of interest to the UI are computed and cached for future use.
*/
public class NativeHeapSnapshot {
+ private static final NumberFormat NUMBER_FORMATTER = NumberFormat.getInstance();
+
private List<NativeAllocationInfo> mHeapAllocations;
private List<NativeLibraryAllocationInfo> mHeapAllocationsByLibrary;
@@ -43,7 +47,7 @@ public class NativeHeapSnapshot {
mTotalSize = getTotalMemory(heapAllocations);
}
- private long getTotalMemory(List<NativeAllocationInfo> heapSnapshot) {
+ protected long getTotalMemory(Collection<NativeAllocationInfo> heapSnapshot) {
long total = 0;
for (NativeAllocationInfo info : heapSnapshot) {
@@ -87,6 +91,14 @@ public class NativeHeapSnapshot {
return mTotalSize;
}
+ public String getFormattedMemorySize() {
+ return String.format("%s bytes", formatMemorySize(getTotalSize()));
+ }
+
+ protected String formatMemorySize(long memSize) {
+ return NUMBER_FORMATTER.format(memSize);
+ }
+
public List<NativeAllocationInfo> getNonZygoteAllocations() {
if (mNonZygoteHeapAllocations != null) {
return mNonZygoteHeapAllocations;