Search in sources :

Example 1 with AnalysisResultEntry

use of com.android.tools.perflib.analyzer.AnalysisResultEntry 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 AnalysisResultEntry

use of com.android.tools.perflib.analyzer.AnalysisResultEntry in project android by JetBrains.

the class AnalysisContentsDelegate method performAnalysis.

/**
   * This method is responsible for resetting the results panel, messaging the main window to perform the analysis, and
   * collecting/displaying the results.
   */
public void performAnalysis() {
    myCanRunAnalysis = false;
    UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(EventCategory.PROFILING).setKind(EventKind.PROFILING_ANALYSIS_RUN));
    final DefaultTreeModel model = (DefaultTreeModel) myResultsTree.getModel();
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    myCategoryNodes.clear();
    Set<AnalysisReport.Listener> singletonListener = Collections.<AnalysisReport.Listener>singleton(new AnalysisReport.Listener() {

        @Override
        public void onResultsAdded(@NonNull final List<AnalysisResultEntry<?>> entries) {
            UIUtil.invokeLaterIfNeeded(new Runnable() {

                @Override
                public void run() {
                    boolean rootChanged = false;
                    Set<DefaultMutableTreeNode> changedCategories = new HashSet<DefaultMutableTreeNode>();
                    for (AnalysisResultEntry<?> entry : entries) {
                        String category = entry.getCategory();
                        DefaultMutableTreeNode categoryNode;
                        if (!myCategoryNodes.containsKey(category)) {
                            categoryNode = new DefaultMutableTreeNode(new String(category));
                            myCategoryNodes.put(category, categoryNode);
                            root.add(categoryNode);
                            rootChanged = true;
                        } else {
                            categoryNode = myCategoryNodes.get(category);
                        }
                        DefaultMutableTreeNode node = myCapturePanel.getContentsDelegate().getNodeForEntry(categoryNode.getChildCount(), entry);
                        if (node != null) {
                            changedCategories.add(categoryNode);
                            categoryNode.add(node);
                        }
                    }
                    if (rootChanged) {
                        model.nodeStructureChanged(root);
                    } else {
                        for (DefaultMutableTreeNode categoryNode : changedCategories) {
                            model.nodeStructureChanged(categoryNode);
                        }
                    }
                }
            });
        }

        @Override
        public void onAnalysisComplete() {
        }

        @Override
        public void onAnalysisCancelled() {
        }
    });
    myCapturePanel.performAnalysis(myEnabledTasks, singletonListener);
}
Also used : ItemListener(java.awt.event.ItemListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AnalysisReport(com.android.tools.perflib.analyzer.AnalysisReport) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AnalysisResultEntry(com.android.tools.perflib.analyzer.AnalysisResultEntry) HashSet(com.intellij.util.containers.HashSet)

Aggregations

AnalysisResultEntry (com.android.tools.perflib.analyzer.AnalysisResultEntry)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AnalysisReport (com.android.tools.perflib.analyzer.AnalysisReport)1 DuplicatedStringsEntry (com.android.tools.perflib.heap.memoryanalyzer.DuplicatedStringsAnalyzerTask.DuplicatedStringsEntry)1 MemoryAnalysisResultEntry (com.android.tools.perflib.heap.memoryanalyzer.MemoryAnalysisResultEntry)1 HashSet (com.intellij.util.containers.HashSet)1 ItemListener (java.awt.event.ItemListener)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1