Search in sources :

Example 6 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class SampleNode method addToSampleNode.

public static void addToSampleNode(final SampleNode node, final StackTraceElement... stackTrace) {
    SampleNode prevResult = node;
    prevResult.sampleCount++;
    for (int i = stackTrace.length - 1; i >= 0; i--) {
        StackTraceElement elem = stackTrace[i];
        final Method method = Methods.getMethod(elem);
        SampleNode nNode = prevResult.get(method);
        if (nNode != null) {
            nNode.sampleCount++;
        } else {
            nNode = new SampleNode(1);
            prevResult.put(method, nNode);
        }
        prevResult = nNode;
    }
}
Also used : Method(org.spf4j.base.avro.Method)

Example 7 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class SampleNode method traverse.

public static void traverse(final Method m, final SampleNode node, final Invocation handler, final Function<Deque, TraversalData> func) {
    Deque<TraversalData> dq = new ArrayDeque<>();
    dq.add(new TraversalData(m, node));
    TraversalData t;
    while ((t = func.apply(dq)) != null) {
        if (!t.n.isEmpty()) {
            Method from = t.m;
            boolean conti = t.n.forEachEntry(new TObjectObjectProcedure<Method, SampleNode>() {

                @Override
                public boolean execute(final Method a, final SampleNode b) {
                    boolean result = handler.invocation(from, a, b.sampleCount);
                    if (result) {
                        dq.addLast(new TraversalData(a, b));
                    }
                    return result;
                }
            });
            if (!conti) {
                return;
            }
        }
    }
}
Also used : Method(org.spf4j.base.avro.Method) ArrayDeque(java.util.ArrayDeque)

Example 8 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class SampleGraphTest method testAggLogic.

@Test
public void testAggLogic() throws IOException {
    SampleNode samples = org.spf4j.ssdump2.Converter.load(Resources.getResource("org.spf4j.concurrent.ThreadPoolBenchmark.spfLifoTpBenchmark-Throughput_m4.ssdump2").openStream());
    Method method = Methods.getMethod("org.spf4j.concurrent.LifoThreadPoolExecutorSQP$QueuedThread", "doRun");
    AtomicInteger ai = new AtomicInteger();
    SampleNode.traverse(Methods.ROOT, samples, (f, t, s) -> {
        if (f.equals(method)) {
            LOG.debug("from = {}, to = {}, samples = {}", f, t, s);
            ai.getAndIncrement();
        }
        return true;
    });
    SampleGraph sg = new SampleGraph(Methods.ROOT, samples);
    SampleGraph.SampleKey sampleKey = new SampleGraph.SampleKey(method, 0);
    SampleGraph.AggSample aggNode = sg.getAggNode(sampleKey);
    Set<SampleGraph.AggSample> children = sg.getChildren(aggNode);
    LOG.debug("parent = {}, children = {}", aggNode, children);
    Assert.assertEquals(ai.get(), children.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Method(org.spf4j.base.avro.Method) Test(org.junit.Test)

Example 9 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class FlameStackPanel method filter.

@Override
public void filter() {
    List<Pair<Method, SampleNode>> tips = search(xx, yy, 0, 0);
    if (tips.size() >= 1) {
        final Method value = tips.get(0).getFirst();
        updateSamples(getMethod(), getSamples().filteredBy(new EqualsPredicate<Method>(value)));
        repaint();
    }
}
Also used : EqualsPredicate(org.spf4j.base.EqualsPredicate) Method(org.spf4j.base.avro.Method) Pair(org.spf4j.base.Pair)

Example 10 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class FlameStackPanel method paintNode.

@SuppressFBWarnings("ISB_TOSTRING_APPENDING")
private int paintNode(final Method method, final SampleNode node, final Graphics2D g2, final int x, final int py, final int width, final int height, final int depth) {
    if (node == null) {
        return 0;
    }
    int y = py;
    int sampleCount = node.getSampleCount();
    String val = Methods.toString(method) + '-' + sampleCount;
    setElementColor(depth, g2);
    g2.setClip(x, y, width, height);
    g2.fillRect(x, y, width, height);
    insert(x, y, width, height, Pair.of(method, node));
    g2.setPaint(Color.BLACK);
    g2.drawString(val, x, y + height - 1);
    g2.setClip(null);
    g2.setPaint(LINK_COLOR);
    g2.drawRect(x, y, width, height);
    int result = height;
    if (!node.isEmpty()) {
        y += height;
        int relX = x;
        double scale = (double) width / sampleCount;
        int maxY = 0;
        for (Map.Entry<Method, SampleNode> entry : node.entrySet()) {
            SampleNode cnode = entry.getValue();
            // sampleCount -> width
            // childSampleCount -> childWidth
            int childWidth = (int) (scale * cnode.getSampleCount());
            if (childWidth > 0) {
                maxY = Math.max(maxY, paintNode(entry.getKey(), cnode, g2, relX, y, childWidth, height, depth + 1));
                relX += childWidth;
            }
        }
        result += maxY;
    }
    return result;
}
Also used : Method(org.spf4j.base.avro.Method) SampleNode(org.spf4j.stackmonitor.SampleNode) Map(java.util.Map) Point(java.awt.Point) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Method (org.spf4j.base.avro.Method)29 Test (org.junit.Test)8 SampleNode (org.spf4j.stackmonitor.SampleNode)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 Map (java.util.Map)5 TMap (gnu.trove.map.TMap)3 IOException (java.io.IOException)3 Pair (org.spf4j.base.Pair)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)2 Point (java.awt.Point)2 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 UncheckedIOException (java.io.UncheckedIOException)2 Nullable (javax.annotation.Nullable)2 StackSampleElement (org.spf4j.base.avro.StackSampleElement)2 AvroStackSampleSupplier (org.spf4j.stackmonitor.AvroStackSampleSupplier)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 Clipboard (java.awt.datatransfer.Clipboard)1