Search in sources :

Example 1 with ASample

use of org.spf4j.ssdump2.avro.ASample 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 2 with ASample

use of org.spf4j.ssdump2.avro.ASample 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)

Example 3 with ASample

use of org.spf4j.ssdump2.avro.ASample in project spf4j by zolyfarkas.

the class Converter method load.

@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public static SampleNode load(final File file) throws IOException {
    try (MemorizingBufferedInputStream bis = new MemorizingBufferedInputStream(Files.newInputStream(file.toPath()))) {
        final PushbackInputStream pis = new PushbackInputStream(bis);
        final SpecificDatumReader<ASample> reader = new SpecificDatumReader<>(ASample.SCHEMA$);
        final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(pis, null);
        return convert(new Iterator<ASample>() {

            @Override
            public boolean hasNext() {
                try {
                    int read = pis.read();
                    pis.unread(read);
                    return read >= 0;
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }

            @Override
            @SuppressFBWarnings
            public ASample next() {
                try {
                    return reader.read(null, decoder);
                } catch (IOException ex) {
                    NoSuchElementException e = new NoSuchElementException();
                    e.addSuppressed(ex);
                    throw e;
                }
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        });
    }
}
Also used : MemorizingBufferedInputStream(org.spf4j.io.MemorizingBufferedInputStream) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ASample(org.spf4j.ssdump2.avro.ASample) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BinaryDecoder(org.apache.avro.io.BinaryDecoder) PushbackInputStream(java.io.PushbackInputStream) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) NoSuchElementException(java.util.NoSuchElementException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ASample (org.spf4j.ssdump2.avro.ASample)3 Method (org.spf4j.base.Method)2 AMethod (org.spf4j.ssdump2.avro.AMethod)2 SampleNode (org.spf4j.stackmonitor.SampleNode)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 IOException (java.io.IOException)1 PushbackInputStream (java.io.PushbackInputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayDeque (java.util.ArrayDeque)1 NoSuchElementException (java.util.NoSuchElementException)1 BinaryDecoder (org.apache.avro.io.BinaryDecoder)1 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)1 MemorizingBufferedInputStream (org.spf4j.io.MemorizingBufferedInputStream)1