aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs/ddmuilib
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2011-09-22 14:37:47 -0700
committerSiva Velusamy <vsiva@google.com>2011-09-22 14:37:47 -0700
commit58df9bbf4195747df6edf0eecc9cb6c8a27eb63f (patch)
treeae88cb220655ad94b54ecdc5d91b8f51a3593629 /ddms/libs/ddmuilib
parenta27ad80ba7b0384e9fc21de39296bbd9b7aa0c7f (diff)
downloadsdk-58df9bbf4195747df6edf0eecc9cb6c8a27eb63f.zip
sdk-58df9bbf4195747df6edf0eecc9cb6c8a27eb63f.tar.gz
sdk-58df9bbf4195747df6edf0eecc9cb6c8a27eb63f.tar.bz2
Show percentage of total heap size for each row.
Change-Id: Iabfb5f246ca5c22cf0097300e66ba128b5174562
Diffstat (limited to 'ddms/libs/ddmuilib')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapLabelProvider.java27
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java12
2 files changed, 34 insertions, 5 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapLabelProvider.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapLabelProvider.java
index 53aebc6..2e9c274 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapLabelProvider.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapLabelProvider.java
@@ -27,6 +27,8 @@ import org.eclipse.swt.graphics.Image;
* A Label Provider for the Native Heap TreeViewer in {@link NativeHeapPanel}.
*/
public class NativeHeapLabelProvider extends LabelProvider implements ITableLabelProvider {
+ private long mTotalSize;
+
public Image getColumnImage(Object arg0, int arg1) {
return null;
}
@@ -52,10 +54,12 @@ public class NativeHeapLabelProvider extends LabelProvider implements ITableLabe
case 1:
return Integer.toString(info.getSize() * info.getAllocationCount());
case 2:
- return Integer.toString(info.getAllocationCount());
+ return getPercentageString(info.getSize() * info.getAllocationCount(), mTotalSize);
case 3:
- return Integer.toString(info.getSize());
+ return Integer.toString(info.getAllocationCount());
case 4:
+ return Integer.toString(info.getSize());
+ case 5:
return stackInfo == null ? stackResolutionStatus(info) : stackInfo.getMethodName();
default:
return null;
@@ -68,11 +72,21 @@ public class NativeHeapLabelProvider extends LabelProvider implements ITableLabe
return info.getLibraryName();
case 1:
return Long.toString(info.getTotalSize());
+ case 2:
+ return getPercentageString(info.getTotalSize(), mTotalSize);
default:
return null;
}
}
+ private String getPercentageString(long size, long total) {
+ if (total == 0) {
+ return "";
+ }
+
+ return String.format("%.1f%%", (float)(size * 100)/(float)total);
+ }
+
private String stackResolutionStatus(NativeAllocationInfo info) {
if (info.isStackCallResolved()) {
return "?"; // resolved and unknown
@@ -80,4 +94,13 @@ public class NativeHeapLabelProvider extends LabelProvider implements ITableLabe
return "Resolving..."; // still resolving...
}
}
+
+ /**
+ * Set the total size of the heap dump for use in percentage calculations.
+ * This value should be set whenever the input to the tree changes so that the percentages
+ * are computed correctly.
+ */
+ public void setTotalSize(long totalSize) {
+ mTotalSize = totalSize;
+ }
}
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 ec35c8d..21d8a9e 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/heap/NativeHeapPanel.java
@@ -100,6 +100,7 @@ public class NativeHeapPanel extends BaseHeapPanel {
private TreeViewer mStackTraceTreeViewer;
private ILazyTreeContentProvider mContentProviderByAllocations;
private ILazyTreeContentProvider mContentProviderByLibrary;
+ private NativeHeapLabelProvider mDetailsTreeLabelProvider;
private ToolBar mDetailsToolBar;
private ToolItem mGroupByButton;
@@ -208,12 +209,13 @@ public class NativeHeapPanel extends BaseHeapPanel {
}
private void displaySnapshot(NativeHeapSnapshot snapshot) {
- mDetailsTreeViewer.setInput(snapshot);
-
if (snapshot != null) {
+ mDetailsTreeLabelProvider.setTotalSize(snapshot.getTotalSize());
+ mDetailsTreeViewer.setInput(snapshot);
mMemoryAllocatedText.setText(formatMemorySize(snapshot.getTotalSize()));
mMemoryAllocatedText.pack();
} else {
+ mDetailsTreeViewer.setInput(null);
mMemoryAllocatedText.setText("");
}
}
@@ -480,6 +482,7 @@ public class NativeHeapPanel extends BaseHeapPanel {
List<String> properties = Arrays.asList(new String[] {
"Library",
"Total",
+ "Percentage",
"Count",
"Size",
"Method",
@@ -488,6 +491,7 @@ public class NativeHeapPanel extends BaseHeapPanel {
List<String> sampleValues = Arrays.asList(new String[] {
"/path/in/device/to/system/library.so",
"123456789",
+ " 100%",
"123456789",
"123456789",
"PossiblyLongDemangledMethodName",
@@ -499,6 +503,7 @@ public class NativeHeapPanel extends BaseHeapPanel {
SWT.RIGHT,
SWT.RIGHT,
SWT.RIGHT,
+ SWT.RIGHT,
SWT.LEFT,
});
@@ -521,7 +526,8 @@ public class NativeHeapPanel extends BaseHeapPanel {
mDetailsTreeViewer.setContentProvider(mContentProviderByAllocations);
}
- mDetailsTreeViewer.setLabelProvider(new NativeHeapLabelProvider());
+ mDetailsTreeLabelProvider = new NativeHeapLabelProvider();
+ mDetailsTreeViewer.setLabelProvider(mDetailsTreeLabelProvider);
mDetailsTreeViewer.setInput(null);