Search in sources :

Example 1 with HNode

use of com.android.tools.adtui.model.HNode in project android by JetBrains.

the class Sampler method endOngoingCalls.

private void endOngoingCalls() {
    lastSampleTime = currSampleTime;
    currSampleTime = currentTimeMicroSec();
    for (HNode n : forest.values()) {
        HNode cursor = n;
        while (cursor != null) {
            cursor.setEnd(getLastMidTime());
            cursor = cursor.getLastChild();
        }
    }
}
Also used : HNode(com.android.tools.adtui.model.HNode)

Example 2 with HNode

use of com.android.tools.adtui.model.HNode in project android by JetBrains.

the class TraceSimplePerf method markCallEnds.

private void markCallEnds(SparseArray<Long> maxSampleTimes) {
    for (int i = 0; i < forest.size(); i++) {
        int threadId = forest.keyAt(i);
        HNode node = forest.get(threadId);
        long sampleTime = maxSampleTimes.get(threadId);
        markCallEnds(node, sampleTime);
    }
}
Also used : HNode(com.android.tools.adtui.model.HNode)

Example 3 with HNode

use of com.android.tools.adtui.model.HNode in project android by JetBrains.

the class TraceSimplePerf method addRecordToModel.

private void addRecordToModel(SimpleperfReport.Record record, SparseArray<Long> maxSampleTime) {
    SimpleperfReport.Sample sample = record.getSample();
    if (sample == null) {
        return;
    }
    if (sample.getCallchainCount() == 0) {
        return;
    }
    int threadId = sample.getThreadId();
    long sampleTime = sample.getTime();
    maxSampleTime.put(threadId, sampleTime);
    // Retrieve the ongoing tree associate with this thread.
    HNode<Method> tree = forest.get(sample.getThreadId());
    if (tree == null) {
        tree = new HNode();
        tree.setStart(sampleTime);
        Method rootMethod = new Method();
        rootMethod.setName("root()");
        rootMethod.setNamespace("root.package.foo.bar");
        tree.setData(rootMethod);
        forest.put(sample.getThreadId(), tree);
    }
    // Compare last captured stack with current stack. Stop as soon as they diverge.
    int depth = sample.getCallchainCount() - 1;
    HNode<Method> previousNode = tree;
    HNode<Method> currentNode = previousNode.getLastChild();
    while (currentNode != null && depth >= 0 && isSameMethod(currentNode.getData(), sample.getCallchain(depth))) {
        depth--;
        previousNode = currentNode;
        currentNode = currentNode.getLastChild();
    }
    // We found the point where the stacks diverge. We need to:
    // 1. Mark previous calls are ended via timestamps.
    // 2. Insert all new calls which are currently ongoing.
    //1. Mark all previous calls as ended.
    markCallEnds(currentNode, sampleTime);
    //2. Those are new calls on the stack: Add them to the tree.
    while (depth >= 0) {
        SimpleperfReport.Sample.CallChainEntry invocation = sample.getCallchain(depth);
        // Discard all kernel stack frames
        if (KERNEL_SYMBOL.equals(invocation.getFile())) {
            break;
        }
        // New node data is a Method.
        Method m = new Method();
        parseInvocation(invocation, m);
        m.setFilename(invocation.getFile());
        HNode<Method> newNode = new HNode<>();
        newNode.setStart(sampleTime);
        newNode.setData(m);
        newNode.setDepth(sample.getCallchainCount() - depth - 1);
        previousNode.addHNode(newNode);
        previousNode = newNode;
        depth--;
    }
}
Also used : HNode(com.android.tools.adtui.model.HNode) SimpleperfReport(com.android.tools.profiler.proto.SimpleperfReport) Method(com.android.tools.adtui.chart.hchart.Method)

Example 4 with HNode

use of com.android.tools.adtui.model.HNode 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 5 with HNode

use of com.android.tools.adtui.model.HNode 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)

Aggregations

HNode (com.android.tools.adtui.model.HNode)12 Method (com.android.tools.adtui.chart.hchart.Method)4 MethodUsage (com.android.tools.adtui.chart.hchart.MethodUsage)4 SampledMethodUsage (com.android.tools.adtui.flamegraph.SampledMethodUsage)1 AppTrace (com.android.tools.idea.monitor.ui.cpu.model.AppTrace)1 Call (com.android.tools.perflib.vmtrace.Call)1 SimpleperfReport (com.android.tools.profiler.proto.SimpleperfReport)1 ThreadStateDataSeries (com.android.tools.profilers.cpu.ThreadStateDataSeries)1 Stack (java.util.Stack)1