diff options
author | Xavier Ducrohet <xav@android.com> | 2010-09-13 13:46:34 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-09-13 14:08:39 -0700 |
commit | 37c10087d3a7adf9764b9d83a922d280dccf3824 (patch) | |
tree | 6f19effa31f84de9ed3bcb310774829df08eb17b /ddms | |
parent | df9ec36094bed53ff18dd389cf7b6ce86efc50a6 (diff) | |
download | sdk-37c10087d3a7adf9764b9d83a922d280dccf3824.zip sdk-37c10087d3a7adf9764b9d83a922d280dccf3824.tar.gz sdk-37c10087d3a7adf9764b9d83a922d280dccf3824.tar.bz2 |
Add alloc number in the alloc tracker.
This lets the user sort the allocation in the order they
happened (or reverse)
Change-Id: I85ca3b190f3a5d63828d78882ee833e5523c2154
Diffstat (limited to 'ddms')
3 files changed, 41 insertions, 11 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AllocationInfo.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AllocationInfo.java index ecf55ab..90bd7d4 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/AllocationInfo.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AllocationInfo.java @@ -22,13 +22,14 @@ import java.util.Comparator; * Holds an Allocation information. */ public class AllocationInfo implements IStackTraceInfo { - private String mAllocatedClass; - private int mAllocationSize; - private short mThreadId; - private StackTraceElement[] mStackTrace; + private final String mAllocatedClass; + private final int mAllocNumber; + private final int mAllocationSize; + private final short mThreadId; + private final StackTraceElement[] mStackTrace; public static enum SortMode { - SIZE, CLASS, THREAD, IN_CLASS, IN_METHOD; + NUMBER, SIZE, CLASS, THREAD, IN_CLASS, IN_METHOD; } public final static class AllocationSorter implements Comparator<AllocationInfo> { @@ -58,6 +59,9 @@ public class AllocationInfo implements IStackTraceInfo { public int compare(AllocationInfo o1, AllocationInfo o2) { int diff = 0; switch (mSortMode) { + case NUMBER: + diff = o1.mAllocNumber - o2.mAllocNumber; + break; case SIZE: // pass, since diff is init with 0, we'll use SIZE compare below // as a back up anyway. @@ -113,8 +117,9 @@ public class AllocationInfo implements IStackTraceInfo { /* * Simple constructor. */ - AllocationInfo(String allocatedClass, int allocationSize, + AllocationInfo(int allocNumber, String allocatedClass, int allocationSize, short threadId, StackTraceElement[] stackTrace) { + mAllocNumber = allocNumber; mAllocatedClass = allocatedClass; mAllocationSize = allocationSize; mThreadId = threadId; @@ -122,6 +127,14 @@ public class AllocationInfo implements IStackTraceInfo { } /** + * Returns the allocation number. Allocations are numbered as they happen with the most + * recent one having the highest number + */ + public int getAllocNumber() { + return mAllocNumber; + } + + /** * Returns the name of the allocated class. */ public String getAllocatedClass() { diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHeap.java b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHeap.java index 0964226..1761b79 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHeap.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHeap.java @@ -512,6 +512,7 @@ final class HandleHeap extends ChunkHandler { data.position(messageHdrLen); ArrayList<AllocationInfo> list = new ArrayList<AllocationInfo>(numEntries); + int allocNumber = numEntries; // order value for the entry. This is sent in reverse order. for (int i = 0; i < numEntries; i++) { int totalSize; int threadId, classNameIndex, stackDepth; @@ -552,7 +553,7 @@ final class HandleHeap extends ChunkHandler { data.get(); } - list.add(new AllocationInfo(classNames[classNameIndex], + list.add(new AllocationInfo(allocNumber--, classNames[classNameIndex], totalSize, (short) threadId, steArray)); } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/AllocationPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/AllocationPanel.java index d9492c3..e28b37e 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/AllocationPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/AllocationPanel.java @@ -67,6 +67,7 @@ import java.util.Arrays; */ public class AllocationPanel extends TablePanel { + private final static String PREFS_ALLOC_COL_NUMBER = "allocPanel.Col00"; //$NON-NLS-1$ private final static String PREFS_ALLOC_COL_SIZE = "allocPanel.Col0"; //$NON-NLS-1$ private final static String PREFS_ALLOC_COL_CLASS = "allocPanel.Col1"; //$NON-NLS-1$ private final static String PREFS_ALLOC_COL_THREAD = "allocPanel.Col2"; //$NON-NLS-1$ @@ -142,14 +143,16 @@ public class AllocationPanel extends TablePanel { AllocationInfo alloc = (AllocationInfo)element; switch (columnIndex) { case 0: - return Integer.toString(alloc.getSize()); + return Integer.toString(alloc.getAllocNumber()); case 1: - return alloc.getAllocatedClass(); + return Integer.toString(alloc.getSize()); case 2: - return Short.toString(alloc.getThreadId()); + return alloc.getAllocatedClass(); case 3: - return alloc.getFirstTraceClassName(); + return Short.toString(alloc.getThreadId()); case 4: + return alloc.getFirstTraceClassName(); + case 5: return alloc.getFirstTraceMethodName(); } } @@ -255,6 +258,19 @@ public class AllocationPanel extends TablePanel { mAllocationTable.setHeaderVisible(true); mAllocationTable.setLinesVisible(true); + final TableColumn numberCol = TableHelper.createTableColumn( + mAllocationTable, + "Alloc Order", + SWT.RIGHT, + "Alloc Order", //$NON-NLS-1$ + PREFS_ALLOC_COL_NUMBER, store); + numberCol.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + setSortColumn(numberCol, SortMode.NUMBER); + } + }); + final TableColumn sizeCol = TableHelper.createTableColumn( mAllocationTable, "Allocation Size", |