Search in sources :

Example 1 with DuplicatedStringsEntry

use of com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry in project android by JetBrains.

the class HprofAnalysisContentsDelegate method customizeCellRenderer.

@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if (value instanceof DefaultMutableTreeNode) {
        Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        if (userObject instanceof EntryListItem) {
            int index = ((EntryListItem) userObject).myIndex;
            AnalysisResultEntry resultEntry = ((EntryListItem) userObject).myEntry;
            if (resultEntry instanceof DuplicatedStringsEntry) {
                DuplicatedStringsEntry entry = (DuplicatedStringsEntry) resultEntry;
                append(Integer.toString(index), XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
                append(" = ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
                append(String.format("\"%s\" (%d instances)", entry.getOffender().getOffendingDescription(), entry.getOffender().getOffenders().size()), SimpleTextAttributes.fromTextAttributes(DebuggerUIUtil.getColorScheme(null).getAttributes(JavaHighlightingColors.STRING)));
            }
        } else if (userObject instanceof InstanceListItem) {
            int index = ((InstanceListItem) userObject).myIndex;
            Instance instance = ((InstanceListItem) userObject).myInstance;
            append(Integer.toString(index), XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
            append(" = ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
            String className = null;
            if (instance instanceof ClassInstance) {
                setIcon(AllIcons.Debugger.Value);
                className = instance.getClassObj().getClassName();
            } else if (instance instanceof ClassObj) {
                setIcon(PlatformIcons.CLASS_ICON);
                className = ((ClassObj) instance).getClassName();
            } else if (instance instanceof ArrayInstance) {
                setIcon(AllIcons.Debugger.Db_array);
                className = instance.getClassObj().getClassName();
            }
            if (className != null) {
                int i = className.lastIndexOf(".");
                if (i != -1) {
                    className = className.substring(i + 1);
                }
                long id = instance.getUniqueId();
                append(String.format("{%s@%d (0x%x)}", className, id, id), SimpleTextAttributes.REGULAR_ATTRIBUTES);
            }
        } else if (userObject instanceof String) {
            append((String) userObject, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        } else if (userObject != null) {
            LOG.warn("Unhandled user object type: " + userObject.getClass().getSimpleName());
        }
    } else if (value != null) {
        LOG.warn("Invalid tree node type: " + value.getClass().getSimpleName());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AnalysisResultEntry(com.android.tools.perflib.analyzer.AnalysisResultEntry) MemoryAnalysisResultEntry(com.android.tools.perflib.heap.memoryanalyzer.MemoryAnalysisResultEntry) DuplicatedStringsEntry(com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry)

Example 2 with DuplicatedStringsEntry

use of com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry in project android by JetBrains.

the class HprofAnalysisContentsDelegate method getNodeForEntry.

@Override
@Nullable
public DefaultMutableTreeNode getNodeForEntry(int index, @NotNull AnalysisResultEntry entry) {
    if (!(entry instanceof MemoryAnalysisResultEntry)) {
        return null;
    }
    DefaultMutableTreeNode subtreeRoot = new DefaultMutableTreeNode();
    if (entry instanceof DuplicatedStringsEntry) {
        DuplicatedStringsEntry duplicatedStringsEntry = (DuplicatedStringsEntry) entry;
        subtreeRoot.setUserObject(new EntryListItem(index, duplicatedStringsEntry));
        for (Instance instance : duplicatedStringsEntry.getOffender().getOffenders()) {
            subtreeRoot.add(new DefaultMutableTreeNode(new InstanceListItem(subtreeRoot.getChildCount(), instance)));
        }
    } else if (entry instanceof LeakedActivityEntry) {
        LeakedActivityEntry leakedActivityEntry = (LeakedActivityEntry) entry;
        subtreeRoot.setUserObject(new InstanceListItem(index, leakedActivityEntry.getOffender().getOffenders().get(0)));
    } else {
        throw new RuntimeException("Failed to handle a subtype of MemoryAnalysisResultEntry \"" + entry.getClass().getSimpleName() + "\". Perhaps this method needs to be updated?");
    }
    return subtreeRoot;
}
Also used : MemoryAnalysisResultEntry(com.android.tools.perflib.heap.memoryanalyzer.MemoryAnalysisResultEntry) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LeakedActivityEntry(com.android.tools.perflib.heap.memoryanalyzer.LeakedActivityAnalyzerTask.LeakedActivityEntry) DuplicatedStringsEntry(com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DuplicatedStringsEntry (com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry)2 MemoryAnalysisResultEntry (com.android.tools.perflib.heap.memoryanalyzer.MemoryAnalysisResultEntry)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AnalysisResultEntry (com.android.tools.perflib.analyzer.AnalysisResultEntry)1 LeakedActivityEntry (com.android.tools.perflib.heap.memoryanalyzer.LeakedActivityAnalyzerTask.LeakedActivityEntry)1 Nullable (org.jetbrains.annotations.Nullable)1