Search in sources :

Example 1 with ApplicationStackSamples

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

the class AvroProfilePersisterTest method testPersister.

@Test
public void testPersister() throws IOException {
    Path file;
    SampleNode sn;
    try (AvroProfilePersister persister = new AvroProfilePersister(org.spf4j.base.Runtime.TMP_FOLDER_PATH, "testProfile", true, 60000L)) {
        SampleNodeTest snt = new SampleNodeTest();
        sn = SampleNode.createSampleNode(snt.newSt1());
        SampleNode.addToSampleNode(sn, snt.newSt2());
        SampleNode.addToSampleNode(sn, snt.newSt3());
        SampleNode.addToSampleNode(sn, snt.newSt4());
        for (int i = 0; i < 10; i++) {
            persister.persist(ImmutableMap.of("test", sn), "tag", Instant.now(), Instant.now());
        }
        file = persister.getTargetFile();
        LOG.debug("persisted profile to {}", file);
    }
    SpecificDatumReader<ApplicationStackSamples> reader = new SpecificDatumReader<>(ApplicationStackSamples.class);
    try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
        for (int i = 0; i < 10; i++) {
            ApplicationStackSamples samples = stream.next();
            Assert.assertEquals("test", samples.getContext());
            Assert.assertEquals(sn, Converter.convert(samples.getStackSamples().iterator()));
        }
    }
}
Also used : Path(java.nio.file.Path) ApplicationStackSamples(org.spf4j.base.avro.ApplicationStackSamples) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) DataFileStream(org.apache.avro.file.DataFileStream) Test(org.junit.Test)

Example 2 with ApplicationStackSamples

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

the class AvroStackSampleSupplier method getMetaData.

@Override
public ProfileMetaData getMetaData(final Instant pfrom, final Instant pto) throws IOException {
    Set<String> contexts = new HashSet<>();
    Set<String> tags = new HashSet<>();
    try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
        while (stream.hasNext()) {
            ApplicationStackSamples samples = stream.next();
            Instant sampleFrom = samples.getCollectedFrom();
            Instant sampleTo = samples.getCollectedTo();
            if ((sampleFrom.compareTo(sampleTo) == 0 && sampleFrom.compareTo(pfrom) >= 0 && sampleFrom.compareTo(pfrom) <= 0) || (sampleFrom.isBefore(pto) && sampleTo.isAfter(pfrom))) {
                contexts.add(samples.getContext());
                tags.add(samples.getTag());
            }
        }
    }
    return new ProfileMetaData(contexts, tags);
}
Also used : ApplicationStackSamples(org.spf4j.base.avro.ApplicationStackSamples) Instant(java.time.Instant) DataFileStream(org.apache.avro.file.DataFileStream) HashSet(java.util.HashSet)

Example 3 with ApplicationStackSamples

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

the class AvroStackSampleSupplier method getSamples.

@Override
public SampleNode getSamples(final String context, final String tag, final Instant pfrom, final Instant pto) throws IOException {
    SampleNode result = null;
    try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
        while (stream.hasNext()) {
            ApplicationStackSamples samples = stream.next();
            Instant sampleFrom = samples.getCollectedFrom();
            Instant sampleTo = samples.getCollectedTo();
            if (((sampleFrom.compareTo(sampleTo) == 0 && sampleFrom.compareTo(pfrom) >= 0 && sampleFrom.compareTo(pfrom) <= 0) || (sampleFrom.isBefore(pto) && sampleTo.isAfter(pfrom))) && (tag == null || samples.getTag().equals(tag)) && (context == null || samples.getContext().equals(context))) {
                SampleNode currentSamples = Converter.convert(samples.getStackSamples().iterator());
                if (result == null) {
                    result = currentSamples;
                } else if (currentSamples != null) {
                    result.add(currentSamples);
                }
            }
        }
    }
    return result;
}
Also used : ApplicationStackSamples(org.spf4j.base.avro.ApplicationStackSamples) Instant(java.time.Instant) DataFileStream(org.apache.avro.file.DataFileStream)

Example 4 with ApplicationStackSamples

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

the class AvroStackSampleSupplier method scanLimits.

private synchronized void scanLimits() throws IOException {
    if (this.from == null) {
        Instant lfrom = Instant.MIN;
        Instant lto = Instant.MAX;
        try (DataFileStream<ApplicationStackSamples> stream = new DataFileStream<>(Files.newInputStream(file), reader)) {
            if (stream.hasNext()) {
                ApplicationStackSamples samples = stream.next();
                lfrom = samples.getCollectedFrom();
                lto = samples.getCollectedTo();
            }
            while (stream.hasNext()) {
                ApplicationStackSamples samples = stream.next();
                lto = samples.getCollectedTo();
            }
            this.from = lfrom;
            this.to = lto;
        }
    }
}
Also used : ApplicationStackSamples(org.spf4j.base.avro.ApplicationStackSamples) Instant(java.time.Instant) DataFileStream(org.apache.avro.file.DataFileStream)

Aggregations

DataFileStream (org.apache.avro.file.DataFileStream)4 ApplicationStackSamples (org.spf4j.base.avro.ApplicationStackSamples)4 Instant (java.time.Instant)3 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)1 Test (org.junit.Test)1