Search in sources :

Example 1 with CycleResultsRLEBufferReadable

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable in project engineblock by engineblock.

the class CycleResultsRLEBufferReadableTest method testRLESingle3.

@Test
public void testRLESingle3() {
    ByteBuffer bb = ByteBuffer.allocate(3 * (Long.BYTES + Long.BYTES + Byte.BYTES));
    bb.putLong(31L).putLong(32L).put((byte) 127);
    bb.putLong(41L).putLong(43L).put((byte) 53);
    bb.putLong(132L).putLong(135L).put((byte) 27);
    bb.flip();
    CycleResultsRLEBufferReadable crb = new CycleResultsRLEBufferReadable(bb);
    ArrayList<CycleResult> cycles = new ArrayList<>();
    crb.iterator().forEachRemaining(s -> s.forEach(cycles::add));
    long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
    int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
    assertThat(cycleValues).containsExactly(31L, 41L, 42L, 132L, 133L, 134L);
    assertThat(resultValues).containsExactly(127, 53, 53, 27, 27, 27);
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) ArrayList(java.util.ArrayList) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 2 with CycleResultsRLEBufferReadable

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable in project engineblock by engineblock.

the class CycleResultsRLEBufferReadableTest method testGetCycleResultsSegment.

@Test
public void testGetCycleResultsSegment() {
    CycleResultsRLEBufferTarget t = new CycleResultsRLEBufferTarget(1000);
    t.onCycleResult(1L, 1);
    t.onCycleResult(2L, 1);
    t.onCycleResult(10L, 2);
    t.onCycleResult(11L, 2);
    t.onCycleResult(13L, 2);
    t.onCycleResult(7L, 7);
    CycleResultsRLEBufferReadable readable = t.toSegmentsReadable();
    CycleResultsSegment s1 = readable.iterator().next();
}
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)

Example 3 with CycleResultsRLEBufferReadable

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable in project engineblock by engineblock.

the class CycleResultsRLEBufferTargetTest method testBasicRLEncoding.

@Test
public void testBasicRLEncoding() {
    CycleResultsRLEBufferTarget tb = new CycleResultsRLEBufferTarget(1024);
    assertThat(tb.getRawBufferCapacity()).isEqualTo(17408);
    tb.onCycleResult(0L, 0);
    tb.onCycleResult(1L, 1);
    CycleResultsRLEBufferReadable r = tb.toSegmentsReadable();
    ArrayList<CycleResult> cycles = new ArrayList<>();
    Iterable<CycleResult> ci = r.getCycleResultIterable();
    Iterator<CycleResult> cit = ci.iterator();
    while (cit.hasNext()) {
        cycles.add(cit.next());
    }
    long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
    assertThat(cycleValues).containsExactly(0L, 1L);
    int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
    assertThat(resultValues).containsExactly(0, 1);
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) ArrayList(java.util.ArrayList) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult) Test(org.testng.annotations.Test)

Example 4 with CycleResultsRLEBufferReadable

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable in project engineblock by engineblock.

the class CycleResultsRLEBufferTargetTest method testGappedIntervalRLEEncoding.

public void testGappedIntervalRLEEncoding() {
    CycleResultsRLEBufferTarget tb = new CycleResultsRLEBufferTarget(100000);
    assertThat(tb.getRawBufferCapacity()).isEqualTo(1700000);
    tb.onCycleResult(0L, 0);
    tb.onCycleResult(13L, 1);
    tb.onCycleResult(14L, 1);
    tb.onCycleResult(15L, 1);
    tb.onCycleResult(28L, 2);
    tb.onCycleResult(29L, 2);
    tb.onCycleResult(100L, 5);
    tb.onCycleResult(101L, 6);
    tb.onCycleResult(102L, 7);
    CycleResultsRLEBufferReadable r = tb.toSegmentsReadable();
    ArrayList<CycleResult> cycles = new ArrayList<>();
    r.getCycleResultIterable().iterator().forEachRemaining(cycles::add);
    long[] cycleValues = cycles.stream().mapToLong(CycleResult::getCycle).toArray();
    assertThat(cycleValues).containsExactly(0L, 13L, 14L, 15L, 28L, 29L, 100L, 101L, 102L);
    int[] resultValues = cycles.stream().mapToInt(CycleResult::getResult).toArray();
    assertThat(resultValues).containsExactly(0, 1, 1, 1, 2, 2, 5, 6, 7);
}
Also used : CycleResultsRLEBufferReadable(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable) CycleResultsRLEBufferTarget(io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget) ArrayList(java.util.ArrayList) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)

Example 5 with CycleResultsRLEBufferReadable

use of io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable 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)

Aggregations

CycleResultsRLEBufferReadable (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferReadable)6 CycleResult (io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)4 CycleResultsRLEBufferTarget (io.engineblock.activityapi.cyclelog.buffers.results_rle.CycleResultsRLEBufferTarget)4 Test (org.testng.annotations.Test)4 CycleResultsSegment (io.engineblock.activityapi.cyclelog.buffers.results.CycleResultsSegment)3 ArrayList (java.util.ArrayList)3 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 ByteBuffer (java.nio.ByteBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1