Search in sources :

Example 6 with CycleResultsSegment

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();
}
Also used : CycleResultsSegment(io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment)

Example 7 with CycleResultsSegment

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;
                }
            }
        }
    }
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) MappedByteBuffer(java.nio.MappedByteBuffer) RandomAccessFile(java.io.RandomAccessFile) CycleResultsSegment(io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 8 with CycleResultsSegment

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);
// 
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) CycleResultsSegment(io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment) Test(org.testng.annotations.Test)

Aggregations

CycleResultsSegment (io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment)8 Test (org.testng.annotations.Test)4 CycleResultsRLEBufferReadable (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable)3 CycleResult (io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)2 CycleResultSegmentBuffer (io.engineblock.activityapi.cyclelog.buffers.results.CycleResultSegmentBuffer)2 CycleResultsRLEBufferTarget (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget)2 Timer (com.codahale.metrics.Timer)1 CycleSegment (io.engineblock.activityapi.cyclelog.buffers.cycles.CycleSegment)1 CycleResultArray (io.engineblock.activityapi.cyclelog.buffers.results.CycleResultArray)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 ArrayList (java.util.ArrayList)1