Search in sources :

Example 11 with HNode

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

the class Sampler method sample.

private void sample() {
    lastSampleTime = currSampleTime;
    currSampleTime = currentTimeMicroSec();
    Set<java.lang.Thread> threadSet = java.lang.Thread.getAllStackTraces().keySet();
    for (java.lang.Thread sampledThread : threadSet) {
        StackTraceElement[] elements = sampledThread.getStackTrace();
        // Some threads (e.g: SignalDispatcher) have no elements.
        if (elements.length == 0) {
            continue;
        }
        // Retrieve the ongoing tree associate with this thread.
        HNode<Method> tree = forest.get(sampledThread.getName());
        if (tree == null) {
            tree = new HNode();
            tree.setStart(getLastMidTime());
            Method rootMethod = new Method();
            rootMethod.setName("rootMethod");
            rootMethod.setNamespace("root.package.foo.bar");
            tree.setData(rootMethod);
            forest.put(sampledThread.getName(), tree);
        }
        // Compare last captured stack with current stack. Stop as soon as they diverge.
        int depth = elements.length - 1;
        HNode<Method> previousNode = tree;
        HNode<Method> currentNode = previousNode.getLastChild();
        while (currentNode != null && depth >= 0 && isSameMethod(currentNode, elements[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.
        HNode endedCall = currentNode;
        while (endedCall != null) {
            endedCall.setEnd(getLastMidTime());
            endedCall = endedCall.getLastChild();
        }
        //2. Those are new calls on the stack: Add them to the tree.
        while (depth != -1) {
            StackTraceElement trace = elements[depth];
            // New node data is a Method.
            Method m = new Method();
            m.setNamespace(trace.getClassName());
            m.setName(trace.getMethodName());
            HNode<Method> newNode = new HNode<>();
            newNode.setStart(getLastMidTime());
            newNode.setData(m);
            newNode.setDepth(elements.length - depth - 1);
            previousNode.addHNode(newNode);
            previousNode = newNode;
            depth--;
        }
    }
}
Also used : HNode(com.android.tools.adtui.model.HNode) Method(com.android.tools.adtui.chart.hchart.Method)

Example 12 with HNode

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

the class CpuTraceArt method convertCallsToNode.

private HNode<MethodModel> convertCallsToNode(VmTraceData data, Call call, int depth) {
    HNode<MethodModel> node = new HNode<>();
    // ART stores timestamp in a compressed fashion: All timestamp are 32 bits relative to a startTime.
    // We need to reconstruct the full timestamp by adding each of them to startTime.
    node.setStart((call.getEntryTime(ClockType.GLOBAL, TimeUnit.MICROSECONDS) + data.getStartTimeUs()));
    node.setEnd((call.getExitTime(ClockType.GLOBAL, TimeUnit.MICROSECONDS) + data.getStartTimeUs()));
    node.setDepth(depth);
    MethodModel method = new MethodModel();
    method.setName(data.getMethod(call.getMethodId()).methodName);
    method.setNamespace(data.getMethod(call.getMethodId()).className);
    node.setData(method);
    for (Call callee : call.getCallees()) {
        node.addHNode(convertCallsToNode(data, callee, depth + 1));
    }
    return node;
}
Also used : HNode(com.android.tools.adtui.model.HNode) Call(com.android.tools.perflib.vmtrace.Call)

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