Search in sources :

Example 6 with SampleNode

use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.

the class ConverterTest method test.

@Test
public void test() {
    SampleNode testSample = testSample();
    final List<StackSampleElement> samples = new ArrayList<>();
    Converters.convert(Methods.ROOT, testSample, -1, 0, samples::add);
    SampleNode back = Converter.convert(samples.iterator());
    Assert.assertEquals(testSample, back);
}
Also used : ArrayList(java.util.ArrayList) SampleNode(org.spf4j.stackmonitor.SampleNode) StackSampleElement(org.spf4j.base.avro.StackSampleElement) Test(org.junit.Test)

Example 7 with SampleNode

use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.

the class ConverterTest method testSample.

private SampleNode testSample() {
    StackTraceElement[] st1 = new StackTraceElement[3];
    st1[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
    st1[1] = new StackTraceElement("C1", "m2", "C1.java", 11);
    st1[2] = new StackTraceElement("C1", "m3", "C1.java", 12);
    SampleNode node = SampleNode.createSampleNode(st1);
    StackTraceElement[] st2 = new StackTraceElement[1];
    st2[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
    SampleNode.addToSampleNode(node, st2);
    StackTraceElement[] st3 = new StackTraceElement[3];
    st3[0] = new StackTraceElement("C2", "m1", "C2.java", 10);
    st3[1] = new StackTraceElement("C2", "m2", "C2.java", 11);
    st3[2] = new StackTraceElement("C2", "m3", "C2.java", 12);
    SampleNode.addToSampleNode(node, st3);
    StackTraceElement[] st4 = new StackTraceElement[3];
    st4[0] = new StackTraceElement("C1", "m1", "C1.java", 10);
    st4[1] = new StackTraceElement("C1", "m2", "C1.java", 11);
    st4[2] = new StackTraceElement("C1", "m4", "C1.java", 14);
    SampleNode.addToSampleNode(node, st4);
    return node;
}
Also used : SampleNode(org.spf4j.stackmonitor.SampleNode)

Example 8 with SampleNode

use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.

the class ConverterTest method testLoad.

@Test
public void testLoad() throws IOException {
    Map<String, SampleNode> labeledDumps = Converter.loadLabeledDumps(new File("./src/test/resources/test.ssdump3"));
    Assert.assertNotNull(labeledDumps);
    LOG.debug("dumps", labeledDumps);
    Assert.assertThat(labeledDumps.toString(), Matchers.containsString("getUnchecked@org.spf4j.concurrent.UnboundedLoadingCache"));
}
Also used : SampleNode(org.spf4j.stackmonitor.SampleNode) File(java.io.File) Test(org.junit.Test)

Example 9 with SampleNode

use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.

the class Converter method convert.

public static SampleNode convert(final Iterator<ASample> samples) {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    while (samples.hasNext()) {
        ASample asmp = samples.next();
        SampleNode sn = new SampleNode(asmp.count, new THashMap<Method, SampleNode>(4));
        SampleNode parent = index.get(asmp.parentId);
        if (parent != null) {
            AMethod method = asmp.getMethod();
            Method m = Method.getMethod(method.declaringClass, method.getName());
            final Map<Method, SampleNode> subNodes = parent.getSubNodes();
            if (subNodes == null) {
                throw new IllegalStateException("Bug, state " + index + "; at node " + asmp);
            }
            subNodes.put(m, sn);
        }
        index.put(asmp.id, sn);
    }
    return index.get(0);
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ASample(org.spf4j.ssdump2.avro.ASample) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.Method) AMethod(org.spf4j.ssdump2.avro.AMethod) AMethod(org.spf4j.ssdump2.avro.AMethod)

Example 10 with SampleNode

use of org.spf4j.stackmonitor.SampleNode in project spf4j by zolyfarkas.

the class Converter method convert.

public static <E extends Exception> int convert(final Method method, final SampleNode node, final int parentId, final int id, final Handler<ASample, E> handler) throws E {
    final Deque<TraversalNode> dq = new ArrayDeque<>();
    dq.addLast(new TraversalNode(method, node, parentId));
    int nid = id;
    while (!dq.isEmpty()) {
        TraversalNode first = dq.removeFirst();
        Method m = first.getMethod();
        ASample sample = new ASample();
        sample.id = nid;
        SampleNode n = first.getNode();
        sample.count = n.getSampleCount();
        AMethod am = new AMethod();
        am.setName(m.getMethodName());
        am.setDeclaringClass(m.getDeclaringClass());
        sample.method = am;
        sample.parentId = first.getParentId();
        final TMap<Method, SampleNode> subNodes = n.getSubNodes();
        final int pid = nid;
        if (subNodes != null) {
            subNodes.forEachEntry((a, b) -> {
                dq.addLast(new TraversalNode(a, b, pid));
                return true;
            });
        }
        handler.handle(sample, parentId);
        nid++;
    }
    return nid;
}
Also used : ASample(org.spf4j.ssdump2.avro.ASample) Method(org.spf4j.base.Method) AMethod(org.spf4j.ssdump2.avro.AMethod) SampleNode(org.spf4j.stackmonitor.SampleNode) AMethod(org.spf4j.ssdump2.avro.AMethod) ArrayDeque(java.util.ArrayDeque)

Aggregations

SampleNode (org.spf4j.stackmonitor.SampleNode)19 Method (org.spf4j.base.avro.Method)9 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)5 StackSampleElement (org.spf4j.base.avro.StackSampleElement)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 Test (org.junit.Test)4 Point (java.awt.Point)3 File (java.io.File)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BufferedInputStream (java.io.BufferedInputStream)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 PushbackInputStream (java.io.PushbackInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 Nullable (javax.annotation.Nullable)2 BinaryDecoder (org.apache.avro.io.BinaryDecoder)2 Method (org.spf4j.base.Method)2