use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment in project engineblock by engineblock.
the class ReorderingConcurrentResultBuffer method close.
@Override
public synchronized void close() throws Exception {
logger.trace("closing and flushing " + segments.size() + " segments");
Collections.sort(segments);
for (CycleResultsSegment segment : segments) {
downstream.onCycleResultSegment(segment);
segmentCount--;
currentCount -= segment.getCount();
}
downstream.close();
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment in project engineblock by engineblock.
the class CycleLogDumperUtility method dumpData.
private void dumpData(String filename, DisplayType displayType) {
File filepath = new File(filename);
MappedByteBuffer mbb = null;
if (!filepath.exists()) {
if (!filepath.getPath().endsWith(".cyclelog")) {
filepath = new File(filename + ".cyclelog");
if (!filepath.exists()) {
throw new RuntimeException("neither '" + filename + "' nor '" + filename + ".cyclelog' exists!");
}
}
}
try {
RandomAccessFile raf = new RandomAccessFile(filepath, "rw");
mbb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length());
} catch (Exception e) {
throw new RuntimeException(e);
}
int readsize = 100;
if (mbb.remaining() > 0) {
CycleResultsRLEBufferReadable readable = null;
while (mbb.remaining() > 0) {
readable = new CycleResultsRLEBufferReadable(readsize, mbb);
for (CycleResultsSegment segment : readable) {
switch(displayType) {
case cycles:
for (CycleResult cycleResult : segment) {
System.out.println(cycleResult);
}
break;
case spans:
System.out.println(segment.toString());
break;
}
}
}
}
}
use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment in project engineblock by engineblock.
the class CycleResultsRLEBufferReadableTest method testIteratorExhausted.
@Test
public void testIteratorExhausted() {
CycleResultsRLEBufferTarget t = new CycleResultsRLEBufferTarget(1000);
t.onCycleResult(1L, 5);
t.onCycleResult(2L, 6);
t.onCycleResult(4L, 8);
CycleResultsRLEBufferReadable cr = t.toSegmentsReadable();
Iterator<CycleResultsSegment> iterator = cr.iterator();
CycleResultsSegment s1 = iterator.next();
assertThat(s1.getCount()).isEqualTo(1);
CycleResultsSegment s2 = iterator.next();
assertThat(s2.getCount()).isEqualTo(1);
CycleResultsSegment s3 = iterator.next();
assertThat(s3.getCount()).isEqualTo(1);
assertThat(iterator.hasNext()).isFalse();
// long[] cycleValues = StreamSupport.stream(cr.spliterator(), false)
// .mapToLong(CycleResult::getCycle).toArray();
// int[] resultValues = StreamSupport.stream(cr.spliterator(), false)
// .mapToInt(CycleResult::getResult).toArray();
//
// assertThat(cycleValues).containsExactly(1L, 2L, 4L);
// assertThat(resultValues).containsExactly(5, 6, 8);
//
}
Aggregations