Search in sources :

Example 6 with StackSampleElement

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

the class Converter method loadLabeledDump.

/**
 * Load samples forrm file containing multiple labeled stack samples.
 * @param file the ssdump3 file.
 * @return
 * @throws IOException
 */
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
@Nullable
public static SampleNode loadLabeledDump(final File file, final String label) throws IOException {
    try (InputStream bis = newInputStream(file)) {
        final SpecificDatumReader<StackSampleElement> reader = new SpecificDatumReader<>(StackSampleElement.SCHEMA$);
        final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(bis, null);
        long nrItems = decoder.readMapStart();
        StackSampleElement asmp = new StackSampleElement();
        while (nrItems > 0) {
            for (int i = 0; i < nrItems; i++) {
                String key = decoder.readString();
                if (label.equals(key)) {
                    return loadSamples(decoder, asmp, reader).get(0);
                } else {
                    skipDump(decoder, reader, asmp);
                }
            }
            nrItems = decoder.mapNext();
        }
        return null;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) PushbackInputStream(java.io.PushbackInputStream) MemorizingBufferedInputStream(org.spf4j.io.MemorizingBufferedInputStream) InputStream(java.io.InputStream) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) StackSampleElement(org.spf4j.base.avro.StackSampleElement) BinaryDecoder(org.apache.avro.io.BinaryDecoder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Nullable(javax.annotation.Nullable)

Example 7 with StackSampleElement

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

the class Converter method loadLabeledDumps.

/**
 * Load samples forrm file containing multiple labeled stack samples.
 * @param file the ssdump3 file.
 * @return
 * @throws IOException
 */
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public static Map<String, SampleNode> loadLabeledDumps(final File file) throws IOException {
    try (InputStream bis = newInputStream(file)) {
        final SpecificDatumReader<StackSampleElement> reader = new SpecificDatumReader<>(StackSampleElement.SCHEMA$);
        final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(bis, null);
        long nrItems = decoder.readMapStart();
        StackSampleElement asmp = new StackSampleElement();
        Map<String, SampleNode> result = new HashMap<>((int) nrItems);
        while (nrItems > 0) {
            for (int i = 0; i < nrItems; i++) {
                String key = decoder.readString();
                TIntObjectMap<SampleNode> index = loadSamples(decoder, asmp, reader);
                result.put(key, index.get(0));
            }
            nrItems = decoder.mapNext();
        }
        return result;
    }
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) PushbackInputStream(java.io.PushbackInputStream) MemorizingBufferedInputStream(org.spf4j.io.MemorizingBufferedInputStream) InputStream(java.io.InputStream) SampleNode(org.spf4j.stackmonitor.SampleNode) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) StackSampleElement(org.spf4j.base.avro.StackSampleElement) BinaryDecoder(org.apache.avro.io.BinaryDecoder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with StackSampleElement

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

the class Converter method convert.

@Nullable
public static SampleNode convert(final Iterator<StackSampleElement> samples) {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    while (samples.hasNext()) {
        StackSampleElement asmp = samples.next();
        SampleNode sn = new SampleNode(asmp.getCount());
        SampleNode parent = index.get(asmp.getParentId());
        if (parent != null) {
            Method m = asmp.getMethod();
            parent.put(m, sn);
        }
        index.put(asmp.getId(), sn);
    }
    return index.get(0);
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) StackSampleElement(org.spf4j.base.avro.StackSampleElement) Nullable(javax.annotation.Nullable)

Example 9 with StackSampleElement

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

the class Converter method loadSamples.

// it's a private method, don't care about being generic
@SuppressFBWarnings("OCP_OVERLY_CONCRETE_PARAMETER")
private static TIntObjectMap<SampleNode> loadSamples(final Decoder decoder, final StackSampleElement pasmp, final SpecificDatumReader<StackSampleElement> reader) throws IOException {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    long nrArrayItems = decoder.readArrayStart();
    while (nrArrayItems > 0) {
        for (int j = 0; j < nrArrayItems; j++) {
            StackSampleElement asmp = reader.read(pasmp, decoder);
            SampleNode sn = new SampleNode(asmp.getCount());
            SampleNode parent = index.get(asmp.getParentId());
            if (parent != null) {
                Method readMethod = asmp.getMethod();
                Method m = new Method(readMethod.getDeclaringClass(), readMethod.getName());
                parent.put(m, sn);
            }
            index.put(asmp.getId(), sn);
        }
        nrArrayItems = decoder.arrayNext();
    }
    return index;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) StackSampleElement(org.spf4j.base.avro.StackSampleElement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 10 with StackSampleElement

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

the class TextEntryPanel method displayActionPerformed.

@SuppressFBWarnings({ "UP_UNUSED_PARAMETER", "URLCONNECTION_SSRF_FD" })
private void displayActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_displayActionPerformed
    try {
        String text = jTextPane1.getText().trim();
        if (text.startsWith("http")) {
            URL url = new URL(text);
            URLConnection conn = url.openConnection();
            conn.setRequestProperty("Accept", "application/avro");
            conn.connect();
            String contentType = conn.getContentType();
            if (!"application/avro".equals(contentType)) {
                throw new IOException("Unsupported content type " + contentType);
            }
            try (InputStream is = new BufferedInputStream(conn.getInputStream())) {
                List<LogRecord> recs = (List<LogRecord>) readAvroBin(is, Schema.createArray(LogRecord.SCHEMA$));
                for (LogRecord rec : recs) {
                    List<StackSampleElement> stackSamples = rec.getStackSamples();
                    if (!stackSamples.isEmpty()) {
                        nodeConsumer.accept(rec.getMsg() + "; with trId=" + rec.getTrId(), Converter.convert(stackSamples.iterator()));
                    }
                }
            }
        } else if (text.startsWith("[")) {
            Schema schema = Schema.createArray(StackSampleElement.getClassSchema());
            DatumReader reader = new SpecificDatumReader(schema);
            List<StackSampleElement> samples;
            try {
                Decoder decoder = DecoderFactory.get().jsonDecoder(schema, text);
                samples = (List<StackSampleElement>) reader.read(null, decoder);
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            nodeConsumer.accept("SampleNode Array", Converter.convert(samples.iterator()));
        } else {
            nodeConsumer.accept("SampleNode Tree", SampleNode.parse(new StringReader(text)).getSecond());
        }
    } catch (IOException | RuntimeException ex) {
        errorConsumer.accept(ex);
    }
}
Also used : SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) DatumReader(org.apache.avro.io.DatumReader) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Schema(org.apache.avro.Schema) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Decoder(org.apache.avro.io.Decoder) URL(java.net.URL) URLConnection(java.net.URLConnection) BufferedInputStream(java.io.BufferedInputStream) LogRecord(org.spf4j.base.avro.LogRecord) StringReader(java.io.StringReader) List(java.util.List) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) StackSampleElement(org.spf4j.base.avro.StackSampleElement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

StackSampleElement (org.spf4j.base.avro.StackSampleElement)11 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)7 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)6 BufferedInputStream (java.io.BufferedInputStream)5 InputStream (java.io.InputStream)5 PushbackInputStream (java.io.PushbackInputStream)5 BinaryDecoder (org.apache.avro.io.BinaryDecoder)5 MemorizingBufferedInputStream (org.spf4j.io.MemorizingBufferedInputStream)5 SampleNode (org.spf4j.stackmonitor.SampleNode)5 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)4 IOException (java.io.IOException)4 UncheckedIOException (java.io.UncheckedIOException)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 Nullable (javax.annotation.Nullable)4 BufferedOutputStream (java.io.BufferedOutputStream)2 OutputStream (java.io.OutputStream)2 HashMap (java.util.HashMap)2 NoSuchElementException (java.util.NoSuchElementException)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 BinaryEncoder (org.apache.avro.io.BinaryEncoder)2