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()));
}
}
}
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);
}
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;
}
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;
}
}
}
Aggregations