Search in sources :

Example 1 with SampledMethodUsage

use of com.android.tools.adtui.flamegraph.SampledMethodUsage in project android by JetBrains.

the class Sampler method sample.

private void sample() {
    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
    for (Thread sampledThread : threadSet) {
        StackTraceElement[] elements = sampledThread.getStackTrace();
        // Some threads (e.g: SignalDispatcher) have no elements.
        if (elements.length == 0) {
            continue;
        }
        // Retrieve the ongoing flame associate with this thread.
        HNode<SampledMethodUsage> flame = furnace.get(sampledThread.getName());
        if (flame == null) {
            flame = new HNode();
            SampledMethodUsage m = new SampledMethodUsage();
            flame.setData(m);
            furnace.put(sampledThread.getName(), flame);
        }
        // Make sure this stacktrace has nodes. Create them if needed.
        ensureNodesExist(elements, flame);
        // Increase invocation counter for all element in the tracktrace.
        int depth = elements.length - 1;
        while (depth >= 0) {
            flame = findChildWithMethod(elements[depth], flame);
            flame.getData().incInvocationCounter();
            depth--;
        }
    }
}
Also used : SampledMethodUsage(com.android.tools.adtui.flamegraph.SampledMethodUsage) HNode(com.android.tools.adtui.model.HNode)

Example 2 with SampledMethodUsage

use of com.android.tools.adtui.flamegraph.SampledMethodUsage in project android by JetBrains.

the class Sampler method ensureNodesExist.

private void ensureNodesExist(StackTraceElement[] trace, HNode<SampledMethodUsage> root) {
    HNode<SampledMethodUsage> previous;
    HNode<SampledMethodUsage> current = root;
    int depth = trace.length - 1;
    while (depth >= 0) {
        StackTraceElement currentMethod = trace[depth];
        previous = current;
        current = findChildWithMethod(currentMethod, previous);
        if (current == null) {
            // Create a new node.
            current = new HNode<>();
            current.setDepth(trace.length - depth);
            SampledMethodUsage m = new SampledMethodUsage();
            m.setInvocationCount(0);
            m.setNamespace(currentMethod.getClassName());
            m.setName(currentMethod.getMethodName());
            current.setData(m);
            // Add new node to parent
            previous.addHNode(current);
        }
        depth--;
    }
}
Also used : SampledMethodUsage(com.android.tools.adtui.flamegraph.SampledMethodUsage)

Aggregations

SampledMethodUsage (com.android.tools.adtui.flamegraph.SampledMethodUsage)2 HNode (com.android.tools.adtui.model.HNode)1