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();
}
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();
}
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);
}
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;
}
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;
}
Aggregations