tmf.core: implement readEnd for CustomTxtTrace
authorLoïc Prieur-Drevon <loic.prieur.drevon@ericsson.com>
Wed, 22 Mar 2017 14:49:33 +0000 (10:49 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 29 Mar 2017 13:16:15 +0000 (09:16 -0400)
Change-Id: Ieaf32d6dc66e0ae9ad0e293687a1e2882c0506ce
Signed-off-by: Loïc Prieur-Drevon <loic.prieur.drevon@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/93622
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/parsers/custom/AbstractCustomTraceDataTest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java

index 95f62685fffbf5ac99776d8d5601e8513a4488c5..009c3daf22344a4ee64706f1ef09a27c73725028 100644 (file)
@@ -9,12 +9,15 @@
 
 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;
@@ -158,4 +161,24 @@ public abstract class AbstractCustomTraceDataTest {
         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);
+    }
+
 }
index 4327bdfc454ada032f43ae338bc77819321eb245..53ed59197611126ed52bc212bd00de24765d5e69 100644 (file)
@@ -40,6 +40,7 @@ import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
 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;
@@ -583,4 +584,40 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
         }
         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;
+    }
 }
This page took 0.031317 seconds and 5 git commands to generate.