Search in sources :

Example 1 with MethodUsage

use of com.android.tools.adtui.chart.hchart.MethodUsage in project android by JetBrains.

the class AppTrace method reverseTopDownGraph.

private void reverseTopDownGraph(HNode<MethodUsage> topDownNode, HNode<MethodUsage> bottomUpGraph, Stack<HNode<MethodUsage>> stack) {
    stack.push(topDownNode);
    if (topDownNode.getData().getExclusivePercentage() > 0) {
        // Add node and all its ancestor to bottomup graph
        HNode<MethodUsage> tailNode = null;
        HNode<MethodUsage> headNode = null;
        for (int i = stack.size() - 1; i >= 0; i--) {
            HNode<MethodUsage> stackedNode = stack.get(i);
            HNode newNode = new HNode<>();
            if (headNode == null) {
                headNode = newNode;
            }
            // Copy stackedNode into new Node.
            newNode.setStart(stackedNode.getStart());
            newNode.setEnd(stackedNode.getEnd());
            newNode.setDepth(stack.size() - i);
            newNode.setData(stackedNode.getData());
            if (tailNode != null) {
                tailNode.addHNode(newNode);
            }
            tailNode = newNode;
        }
        // Try to see if this method call was already present in the bottomup. If this is the case we can merge it into the bottomup graph.
        boolean mergedInGraph = false;
        for (HNode<MethodUsage> child : bottomUpGraph.getChildren()) {
            if (child.getData().getName().equals(headNode.getData().getName()) && child.getData().getNameSpace().equals(headNode.getData().getNameSpace())) {
                if (headNode.getChildren().size() > 0) {
                    child.addHNode(headNode.getFirstChild());
                }
                mergedInGraph = true;
                break;
            }
        }
        if (!mergedInGraph) {
            bottomUpGraph.addHNode(headNode);
        }
    }
    for (HNode n : topDownNode.getChildren()) {
        reverseTopDownGraph(n, bottomUpGraph, stack);
    }
    stack.pop();
}
Also used : HNode(com.android.tools.adtui.model.HNode) MethodUsage(com.android.tools.adtui.chart.hchart.MethodUsage)

Example 2 with MethodUsage

use of com.android.tools.adtui.chart.hchart.MethodUsage in project android by JetBrains.

the class AppTrace method findOrCopyNodeInUsageGraph.

private HNode<MethodUsage> findOrCopyNodeInUsageGraph(HNode<Method> node, HNode<MethodUsage> usageGraph) {
    HNode<MethodUsage> foundNode = findNodeInUsageGraph(node, usageGraph);
    if (foundNode != null) {
        return foundNode;
    }
    // Node was not found. We need to create it and add it to the usageGraph before returning it.
    HNode<MethodUsage> newNode = new HNode<>();
    MethodUsage mu = new MethodUsage();
    if (node.getData() != null) {
        mu.setNamespace(node.getData().getNameSpace());
        mu.setName(node.getData().getName());
    }
    newNode.setData(mu);
    newNode.setDepth(node.getDepth());
    usageGraph.addHNode(newNode);
    return newNode;
}
Also used : HNode(com.android.tools.adtui.model.HNode) MethodUsage(com.android.tools.adtui.chart.hchart.MethodUsage)

Example 3 with MethodUsage

use of com.android.tools.adtui.chart.hchart.MethodUsage in project android by JetBrains.

the class AppTrace method convertGraphToTree.

private void convertGraphToTree(HNode<MethodUsage> graph, AppStatTreeNode treeNode) {
    MethodUsage top = graph.getData();
    if (top != null) {
        treeNode.setPercentageInclusive(top.getInclusivePercentage());
        treeNode.setPercentageExclusive(top.getExclusivePercentage());
        treeNode.setRuntimeExclusive(top.getExclusiveDuration());
        treeNode.setRuntimeInclusive(top.getInclusiveDuration());
        treeNode.setMethodName(top.getName());
        treeNode.setMethodNamespace(top.getNameSpace());
    }
    for (HNode<MethodUsage> n : graph.getChildren()) {
        AppStatTreeNode newNode = new AppStatTreeNode();
        treeNode.add(newNode);
        convertGraphToTree(n, newNode);
    }
}
Also used : AppStatTreeNode(com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode) MethodUsage(com.android.tools.adtui.chart.hchart.MethodUsage)

Example 4 with MethodUsage

use of com.android.tools.adtui.chart.hchart.MethodUsage in project android by JetBrains.

the class AppTrace method generateTopDownGraphs.

// TopDown graph are flamegraphs: The execution stacks merged together (on a per-thread basis).
// TopDown graphs are used in flamegraphs but also in top-down and bottom-up statistics display.
private void generateTopDownGraphs() {
    myTopDownStats = new SparseArray<>();
    SparseArray<HNode<Method>> threadGraphs = getThreadsGraph();
    for (int i = 0; i < threadGraphs.size(); i++) {
        int threadPid = threadGraphs.keyAt(i);
        HNode<Method> execGraph = threadGraphs.get(threadPid);
        HNode<MethodUsage> usageGraphRoot = new HNode<>();
        usageGraphRoot.setStart(0);
        usageGraphRoot.setEnd(execGraph.duration());
        usageGraphRoot.setData(new MethodUsage());
        long totalDuration = usageGraphRoot.duration();
        // Graph generation is a two passes algorithm:
        // 1/ Merge all the stackframes.
        // 2/ Generate all the node data and layout (start,end)
        mergeStackTraces(execGraph, usageGraphRoot);
        generateStats(usageGraphRoot, totalDuration);
        myTopDownStats.put(threadPid, usageGraphRoot);
    }
}
Also used : HNode(com.android.tools.adtui.model.HNode) Method(com.android.tools.adtui.chart.hchart.Method) MethodUsage(com.android.tools.adtui.chart.hchart.MethodUsage)

Example 5 with MethodUsage

use of com.android.tools.adtui.chart.hchart.MethodUsage in project android by JetBrains.

the class AppTrace method generateBottomUpGraph.

// Reverse a topdown graph into a bottom up graph.
private HNode<MethodUsage> generateBottomUpGraph(HNode<MethodUsage> topDownGraph) {
    HNode<MethodUsage> bottomUpGraph = new HNode<>();
    MethodUsage fakeMethodUsageRoot = new MethodUsage();
    fakeMethodUsageRoot.setNamespace("");
    fakeMethodUsageRoot.setName("");
    fakeMethodUsageRoot.setExclusivePercentage(1);
    bottomUpGraph.setData(fakeMethodUsageRoot);
    Stack<HNode<MethodUsage>> stack = new Stack<>();
    // Intentionaly removing the first child since it is just here to hold top level childs.
    topDownGraph = topDownGraph.getFirstChild();
    reverseTopDownGraph(topDownGraph, bottomUpGraph, stack);
    return bottomUpGraph;
}
Also used : HNode(com.android.tools.adtui.model.HNode) MethodUsage(com.android.tools.adtui.chart.hchart.MethodUsage) Stack(java.util.Stack)

Aggregations

MethodUsage (com.android.tools.adtui.chart.hchart.MethodUsage)6 HNode (com.android.tools.adtui.model.HNode)4 Method (com.android.tools.adtui.chart.hchart.Method)1 AppStatTreeNode (com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode)1 Stack (java.util.Stack)1