Search in sources :

Example 1 with ITmfCheckpoint

use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.

the class BTreeTest method testAccept.

/**
 * Tests that accepts find the correct checkpoint and ends with a perfect
 * match
 */
@Test
public void testAccept() {
    for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), 0);
        fBTree.insert(checkpoint);
    }
    final TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(123), new TmfLongLocation(123L), 0);
    class TestVisitor implements IBTreeVisitor {

        public int fLastCompare = 0;

        ITmfCheckpoint fFoundCheckpoint;

        @Override
        public int compare(ITmfCheckpoint checkRec) {
            fLastCompare = checkRec.compareTo(checkpoint);
            if (fLastCompare == 0) {
                fFoundCheckpoint = checkRec;
            }
            return fLastCompare;
        }
    }
    final TestVisitor t = new TestVisitor();
    fBTree.accept(t);
    assertEquals(checkpoint, t.fFoundCheckpoint);
    assertEquals(0, t.fLastCompare);
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) IBTreeVisitor(org.eclipse.tracecompass.internal.tmf.core.trace.indexer.IBTreeVisitor) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) Test(org.junit.Test)

Example 2 with ITmfCheckpoint

use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.

the class FlatArrayTest method testBinarySearch.

/**
 * Tests that binarySearch find the correct checkpoint and ends with a
 * perfect match
 */
@Test
public void testBinarySearch() {
    for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
        TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), 0);
        fFlatArray.insert(checkpoint);
    }
    TmfCheckpoint expectedCheckpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(122), new TmfLongLocation(122L), 0);
    int expectedRank = 122;
    long rank = fFlatArray.binarySearch(expectedCheckpoint);
    ITmfCheckpoint found = fFlatArray.get(rank);
    assertEquals(expectedRank, rank);
    assertEquals(found, expectedCheckpoint);
}
Also used : TmfLongLocation(org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) Test(org.junit.Test)

Example 3 with ITmfCheckpoint

use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.

the class BTreeCheckpointVisitor method compare.

@Override
public int compare(ITmfCheckpoint currentCheckpoint) {
    int compareTo = currentCheckpoint.compareTo(search);
    if (compareTo <= 0 && !exactFound) {
        rank = currentCheckpoint.getCheckpointRank();
        found = currentCheckpoint;
        if (compareTo == 0) {
            exactFound = true;
        }
    }
    return compareTo;
}
Also used : ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint)

Example 4 with ITmfCheckpoint

use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.

the class BTreeNode method serializeOut.

/**
 * Write the node data to disk
 */
void serializeOut() {
    try {
        fTree.getRandomAccessFile().seek(fFileOffset);
        ByteBuffer bb = fTree.getNodeByteBuffer();
        bb.clear();
        for (int i = 0; i < fTree.getMaxNumChildren(); ++i) {
            bb.putLong(fChildrenFileOffsets[i]);
        }
        bb.putInt(fNumEntries);
        for (int i = 0; i < fNumEntries; ++i) {
            ITmfCheckpoint key = fEntries[i];
            key.serialize(bb);
        }
        fTree.getRandomAccessFile().write(bb.array());
        fIsDirty = false;
    } catch (IOException e) {
        Activator.logError(MessageFormat.format(Messages.BTreeNode_IOErrorWriting, fFileOffset, fTree.getRandomAccessFile()), e);
    }
}
Also used : ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint)

Example 5 with ITmfCheckpoint

use of org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint in project tracecompass by tracecompass.

the class FlatArray method get.

/**
 * Get a checkpoint from a rank
 *
 * @param rank
 *            the rank to search
 * @return the checkpoint that has been found or null if not found
 */
public ITmfCheckpoint get(long rank) {
    ITmfCheckpoint checkpoint = null;
    try {
        long pos = getHeader().getSize() + fCheckpointSize * rank;
        if (getRandomAccessFile() == null) {
            return null;
        }
        getRandomAccessFile().seek(pos);
        fByteBuffer.clear();
        getRandomAccessFile().read(fByteBuffer.array());
        ITmfLocation location = getTrace().restoreLocation(fByteBuffer);
        ITmfTimestamp timeStamp = TmfTimestamp.create(fByteBuffer);
        checkpoint = new TmfCheckpoint(timeStamp, location, fByteBuffer);
    } catch (IOException e) {
        Activator.logError(MessageFormat.format(Messages.FlatArray_IOErrorReading, getFile()), e);
    }
    return checkpoint;
}
Also used : ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) IOException(java.io.IOException) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation) TmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint) ITmfCheckpoint(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint)

Aggregations

ITmfCheckpoint (org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint)16 TmfCheckpoint (org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint)8 Test (org.junit.Test)7 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)5 ITmfCheckpointIndex (org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpointIndex)5 TmfLongLocation (org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation)5 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)3 TmfContext (org.eclipse.tracecompass.tmf.core.trace.TmfContext)3 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)1 IBTreeVisitor (org.eclipse.tracecompass.internal.tmf.core.trace.indexer.IBTreeVisitor)1 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)1 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)1 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1 ITmfEventParser (org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1 TmfExperimentStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub)1 TmfTraceStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub)1