package org.eclipse.tracecompass.tmf.core.tests.parsers.custom;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
fTestData.validateEventCount(eventCount);
}
+ /**
+ * Test that the fast bound reading method returns the correct time stamps.
+ */
+ @Test
+ public void testReadingBounds() {
+ /* First, read the bounds without indexing. */
+ ITmfTimestamp start = fTrace.readStart();
+ ITmfTimestamp end = fTrace.readEnd();
+
+ /*
+ * Index the trace so that getStartTime and getEndTime return the
+ * correct time stamps.
+ */
+ fTrace.indexTrace(true);
+
+ /* Compare the TmfTrace bounds to the fast read bounds. */
+ assertEquals(fTrace.getStartTime(), start);
+ assertEquals(fTrace.getEndTime(), end);
+ }
+
}
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
}
super.traceRangeUpdated(signal);
}
+
+ /**
+ * @since 2.3
+ */
+ @Override
+ public synchronized ITmfTimestamp readEnd() {
+ try {
+ Long pos = fFile.length() - 1;
+ /* Outer loop to find the first line of a matcher group. */
+ while (pos > 0) {
+ /* Inner loop to find line beginning */
+ while (pos > 0) {
+ fFile.seek(pos - 1);
+ if (fFile.read() == '\n') {
+ break;
+ }
+ pos--;
+ }
+ ITmfLocation location = new TmfLongLocation(pos);
+ ITmfContext context = seekEvent(location);
+ ITmfEvent event = parseEvent(context);
+ context.dispose();
+ if (event != null) {
+ /* The last event in the trace was successfully parsed. */
+ return event.getTimestamp();
+ }
+ /* pos was after the beginning of the lines of the last event. */
+ pos--;
+ }
+ } catch (IOException e) {
+ Activator.logError("Error seeking last event. File: " + getPath(), e); //$NON-NLS-1$
+ }
+
+ /* Empty trace */
+ return null;
+ }
}