ctf.core: add populate indexes and fix seek last event
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 11 Apr 2015 03:31:51 +0000 (23:31 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 23 Apr 2015 17:31:05 +0000 (13:31 -0400)
Add much needed documentation to goToLastEvent. It is
not as trivial as one would think.

Change-Id: Ia2834df70f583430afc1a7046993809c9262a690
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/45689
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputReader.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTraceReader.java

index 8a8dc2d61711ec4306fb7dd7b42724a110e0bcda..9c62495f5442617cf02b6260639dc95e2fbdd440 100644 (file)
@@ -362,17 +362,14 @@ public class CTFStreamInputReader implements AutoCloseable {
      *             if an error occurs
      */
     public void goToLastEvent() throws CTFException {
-        /*
-         * Search in the index for the packet to search in.
-         */
-        final int len = fStreamInput.getIndex().size();
 
         /*
-         * Go to beginning of trace.
+         * Go to the beginning of the trace
          */
         seek(0);
+
         /*
-         * if the trace is empty.
+         * Check that there is at least one event
          */
         if ((fStreamInput.getIndex().isEmpty()) || (!fPacketReader.hasMoreEvents())) {
             /*
@@ -380,12 +377,28 @@ public class CTFStreamInputReader implements AutoCloseable {
              */
             return;
         }
+
+        fPacketIndex = fStreamInput.getIndex().size() - 1;
+        /*
+         * Go to last indexed packet
+         */
+        fPacketReader.setCurrentPacket(getPacket());
+
+        /*
+         * Keep going until you cannot
+         */
+        while (fPacketReader.getCurrentPacket() != null) {
+            goToNextPacket();
+        }
+
+        final int lastPacketIndex = fStreamInput.getIndex().size() - 1;
         /*
          * Go to the last packet that contains events.
          */
-        for (int pos = len - 1; pos > 0; pos--) {
+        for (int pos = lastPacketIndex; pos > 0; pos--) {
             fPacketIndex = pos;
             fPacketReader.setCurrentPacket(getPacket());
+
             if (fPacketReader.hasMoreEvents()) {
                 break;
             }
index 6286da118b69e625abf3b2495d9c783d2c77eff7..c9fc265407f5d81bfcd60870d9d4d1dfc68cb524 100644 (file)
@@ -567,4 +567,22 @@ public class CTFTraceReader implements AutoCloseable {
     public CTFTrace getTrace() {
         return fTrace;
     }
+
+    /**
+     * This will read the entire trace and populate all the indexes. The reader
+     * will then be reset to the first event in the trace.
+     *
+     * Do not call in the fast path.
+     *
+     * @throws CTFException
+     *             A trace reading error occurred
+     * @since 1.0
+     */
+    public void populateIndex() throws CTFException {
+        for (CTFStreamInputReader sir : fPrio) {
+            sir.goToLastEvent();
+        }
+        seek(0);
+
+    }
 }
This page took 0.02673 seconds and 5 git commands to generate.