Search in sources :

Example 1 with MemoryInfoTreeNode

use of com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode in project android by JetBrains.

the class ClassHistogramView method createComponentsList.

@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
    myTreeModel = new DefaultTreeModel(myRoot);
    myTree = new Tree(myTreeModel);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    ColumnTreeBuilder builder = new ColumnTreeBuilder(myTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Class").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(0, myRoot))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Count").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(1, myRoot)).setInitialOrder(SortOrder.DESCENDING).setComparator((MemoryInfoTreeNode a, MemoryInfoTreeNode b) -> a.getCount() - b.getCount()));
    builder.setTreeSorter((Comparator<MemoryInfoTreeNode> comparator, SortOrder sortOrder) -> {
        myRoot.sort(comparator);
        myTreeModel.nodeStructureChanged(myRoot);
    });
    myColumnTree = builder.build();
}
Also used : ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 2 with MemoryInfoTreeNode

use of com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode in project android by JetBrains.

the class MemoryDetailSegment method createComponentsList.

@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
    mTreeModel = new DefaultTreeModel(mRoot);
    mTree = new Tree(mTreeModel);
    mTree.setRootVisible(false);
    mTree.setShowsRootHandles(true);
    ColumnTreeBuilder builder = new ColumnTreeBuilder(mTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Class").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(0, mRoot))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Count").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(1, mRoot)).setInitialOrder(SortOrder.DESCENDING).setComparator((MemoryInfoTreeNode a, MemoryInfoTreeNode b) -> a.getCount() - b.getCount()));
    builder.setTreeSorter((Comparator<MemoryInfoTreeNode> comparator, SortOrder sortOrder) -> {
        mRoot.sort(comparator);
        mTreeModel.nodeStructureChanged(mRoot);
    });
    mColumnTree = builder.build();
}
Also used : ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Comparator(java.util.Comparator)

Example 3 with MemoryInfoTreeNode

use of com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode in project android by JetBrains.

the class ClassHistogramView method generateClassHistogram.

/**
   * Updates a {@link MemoryDetailSegment} to show the allocations (and changes)
   */
private void generateClassHistogram(@NotNull Map<String, Integer> instanceMap) {
    myRoot.setCount(0);
    myRoot.removeAllChildren();
    int maxInstanceCount = Integer.MIN_VALUE;
    for (Map.Entry<String, Integer> entry : instanceMap.entrySet()) {
        int instanceCount = entry.getValue();
        if (instanceCount != 0) {
            MemoryInfoTreeNode child = new MemoryInfoTreeNode(entry.getKey());
            child.setCount(instanceCount);
            insertNode(myRoot, child);
            maxInstanceCount = Math.max(maxInstanceCount, Math.abs(instanceCount));
        }
    }
    myRoot.setCount(maxInstanceCount);
    refreshNode(myRoot);
}
Also used : MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode)

Example 4 with MemoryInfoTreeNode

use of com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode in project android by JetBrains.

the class MemoryProfilerVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    long startTimeUs = mDataStore.getLatestTimeUs();
    Range timeCurrentRangeUs = new Range(startTimeUs - RangeScrollbar.DEFAULT_VIEW_LENGTH_US, startTimeUs);
    AnimatedTimeRange animatedTimeRange = new AnimatedTimeRange(timeCurrentRangeUs, 0);
    EventDispatcher<ProfilerEventListener> dummyDispatcher = EventDispatcher.create(ProfilerEventListener.class);
    mSegment = new MemorySegment(timeCurrentRangeUs, mDataStore, dummyDispatcher);
    mRoot = new MemoryInfoTreeNode("Root");
    mDetailSegment = new MemoryDetailSegment(timeCurrentRangeUs, mRoot, dummyDispatcher);
    List<Animatable> animatables = new ArrayList<>();
    animatables.add(animatedTimeRange);
    mSegment.createComponentsList(animatables);
    mDetailSegment.createComponentsList(animatables);
    // Simulate allocation data with stack frames.
    mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    updateTree(mRoot);
                    Thread.sleep(10);
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    return animatables;
}
Also used : AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) MemorySegment(com.android.tools.idea.monitor.ui.memory.view.MemorySegment) MemoryDetailSegment(com.android.tools.idea.monitor.ui.memory.view.MemoryDetailSegment) Animatable(com.android.tools.adtui.Animatable) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener)

Example 5 with MemoryInfoTreeNode

use of com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode in project android by JetBrains.

the class MemoryProfilerVisualTest method constructAndIncrementNodes.

private boolean constructAndIncrementNodes(MemoryInfoTreeNode parent, StackTraceElement[] traces, int depth) {
    if (depth < 0) {
        // Reached top of stack - early return.
        return false;
    }
    StackTraceElement trace = traces[depth];
    String nameSpace = trace.getClassName();
    // Skip non-user code namespace to avoid deep stack frames.
    if (nameSpace.startsWith("java.") || nameSpace.startsWith("sun.") || nameSpace.startsWith("javax.") || nameSpace.startsWith("apple.") || nameSpace.startsWith("com.apple.")) {
        return constructAndIncrementNodes(parent, traces, --depth);
    }
    // Attempt to find an existing matching child node - create one if it does not exist.
    MemoryInfoTreeNode matchedChild = null;
    boolean isNewNode = false;
    String fullName = nameSpace + "." + trace.getMethodName();
    Enumeration children = parent.children();
    while (children.hasMoreElements()) {
        MemoryInfoTreeNode child = (MemoryInfoTreeNode) children.nextElement();
        if (child != null && child.getName().equals(fullName)) {
            matchedChild = child;
            break;
        }
    }
    if (matchedChild == null) {
        matchedChild = new MemoryInfoTreeNode(fullName);
        isNewNode = true;
    }
    // Increase the occurrence count of this node.
    matchedChild.setCount(matchedChild.getCount() + 1);
    boolean childrenChanged = constructAndIncrementNodes(matchedChild, traces, --depth);
    if (isNewNode) {
        // If the current node is new, simply insert it and propagates back up to the parent to refresh.
        mDetailSegment.insertNode(parent, matchedChild);
    } else if (childrenChanged) {
        // If the node is not new and its children has changed, refresh itself and restore the previous expansion state.
        boolean expanded = mDetailSegment.getExpandState(matchedChild);
        mDetailSegment.refreshNode(matchedChild);
        if (expanded) {
            mDetailSegment.setExpandState(matchedChild, expanded);
        }
    }
    return isNewNode;
}
Also used : Enumeration(java.util.Enumeration) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode)

Aggregations

MemoryInfoTreeNode (com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode)5 ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)2 Tree (com.intellij.ui.treeStructure.Tree)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 Animatable (com.android.tools.adtui.Animatable)1 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)1 Range (com.android.tools.adtui.model.Range)1 ProfilerEventListener (com.android.tools.idea.monitor.tool.ProfilerEventListener)1 MemoryDetailSegment (com.android.tools.idea.monitor.ui.memory.view.MemoryDetailSegment)1 MemorySegment (com.android.tools.idea.monitor.ui.memory.view.MemorySegment)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Enumeration (java.util.Enumeration)1