Search in sources :

Example 11 with SampleNode

use of org.spf4j.stackmonitor.SampleNode 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 12 with SampleNode

use of org.spf4j.stackmonitor.SampleNode 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 13 with SampleNode

use of org.spf4j.stackmonitor.SampleNode 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 14 with SampleNode

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

the class ConverterTest method testSaveLoad.

@Test
public void testSaveLoad() throws IOException {
    File test = File.createTempFile("test", ".ssdumnp3");
    SampleNode testSample = testSample();
    Map<String, SampleNode> dumps = new HashMap<>(4);
    dumps.put("zero", null);
    dumps.put("something", testSample);
    Converter.saveLabeledDumps(test, dumps);
    Map<String, SampleNode> loadLabeledDumps = Converter.loadLabeledDumps(test);
    Assert.assertEquals(testSample, loadLabeledDumps.get("something"));
}
Also used : HashMap(java.util.HashMap) SampleNode(org.spf4j.stackmonitor.SampleNode) File(java.io.File) Test(org.junit.Test)

Example 15 with SampleNode

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

the class Explorer method toSupplier.

// GEN-LAST:event_compareMenuItemActionPerformed
private StackSampleSupplier toSupplier(final File file) throws IOException {
    if (Spf4jFileFilter.SSDUMP.accept(file)) {
        SampleNode samples = loadLegacyFormat(file);
        Instant now = Instant.now();
        return new OneStackSampleSupplier(now, now, samples);
    } else if (Spf4jFileFilter.SSDUMP2.accept(file) || Spf4jFileFilter.SSDUMP2_GZ.accept(file)) {
        SampleNode samples = org.spf4j.ssdump2.Converter.load(file);
        Instant now = Instant.now();
        return new OneStackSampleSupplier(now, now, samples);
    } else if (Spf4jFileFilter.SSDUMP3.accept(file) || Spf4jFileFilter.SSDUMP3_GZ.accept(file)) {
        Map<String, SampleNode> loadLabeledDumps = org.spf4j.ssdump2.Converter.loadLabeledDumps(file);
        Instant now = Instant.now();
        return new MultiStackSampleSupplier(now, now, loadLabeledDumps);
    } else if (Spf4jFileFilter.D3_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parseD3Json(br);
            Instant now = Instant.now();
            return new OneStackSampleSupplier(now, now, parse.getSecond());
        }
    } else if (Spf4jFileFilter.SPF4J_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parse(br);
            Instant now = Instant.now();
            return new OneStackSampleSupplier(now, now, parse.getSecond());
        }
    } else if (Spf4jFileFilter.PROFILE_AVRO.accept(file)) {
        return new AvroStackSampleSupplier(file.toPath());
    } else {
        throw new IOException("Unsupported file format " + file);
    }
}
Also used : AvroStackSampleSupplier(org.spf4j.stackmonitor.AvroStackSampleSupplier) Instant(java.time.Instant) BufferedReader(java.io.BufferedReader) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Pair(org.spf4j.base.Pair)

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