Fix ranks in CtfTmfTrace as part of bug #389051
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 31 May 2012 19:18:54 +0000 (15:18 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 31 May 2012 19:18:54 +0000 (15:18 -0400)
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java

index 42ae663ee006015699ef3598876775887ecb331e..08f9d181abd47ae95454cb1f7923544de96d338f 100644 (file)
@@ -245,9 +245,6 @@ public class CTFTraceReader {
             final long topEnd = top.getCurrentEvent().getTimestamp() + this.getTrace().getOffset();
             this.setEndTime( Math.max(topEnd, this.getEndTime()));
             this.eventCountPerTraceFile[top.getName()]++;
-            /*
-             * increment the index
-             */
 
             if (top.getCurrentEvent() != null) {
                 this.endTime = Math.max(top.getCurrentEvent().getTimestamp(),
index 234b887ced71b50e1b8824da93766ca130993bc5..b295342b7fb81f9ff04f9948761d820c475faff3 100644 (file)
@@ -102,6 +102,13 @@ public class StreamInputPacketIndex {
         int guessI;
         StreamInputPacketIndexEntry guessEntry = null;
 
+        /*
+         * If the index is empty, return the iterator at the very beginning.
+         */
+        if( this.getEntries().isEmpty()) {
+            return this.getEntries().listIterator();
+        }
+
         if (timestamp < 0) {
             throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$
         }
index a15b4200d8bab29524b4489109c73c0f8f64a4a3..2c2efbc1ea52fc37b5f23ff5ccb049b44e9ec885 100644 (file)
@@ -195,7 +195,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparab
      */
     @Override
     public void increaseRank() {
-        curRank++;
+        /* Only increase the rank if it's valid */
+        if(hasValidRank()) {
+            curRank++;
+        }
     }
 
     /**
index c21ecbc5a13022487de6db6911b4c79784ed74a5..be3f94d45792899f06e4a2e407a6d41bccbd3b9c 100644 (file)
@@ -63,13 +63,15 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
     @Override
     public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
             throws TmfTraceException {
+        /*
+         * Set the cache size. This has to be done before the call to super()
+         * because the super needs to know the cache size.
+         */
+        setCacheSize();
         super.initTrace(resource, path, eventType);
         EventDeclaration ed;
         ITmfEventField eventField;
 
-        // Set the cache size
-        setCacheSize();
-
         @SuppressWarnings("unused")
         CtfTmfEventType type;
 
@@ -92,12 +94,6 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
                 this.setStartTime(TmfTimestamp.BIG_BANG);
             } else {
                 this.setStartTime(iterator.getCurrentEvent().getTimestamp());
-                /*
-                 * is the trace empty
-                 */
-                if( iterator.hasMoreEvents()){
-                    iterator.goToLastEvent();
-                }
                 this.setEndTime(iterator.getCurrentEvent().getTimestamp());
             }
 
@@ -172,16 +168,22 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
     @Override
     public ITmfContext seekEvent(final ITmfLocation<?> location) {
         CtfLocation currentLocation = (CtfLocation) location;
+        CtfIterator context = new CtfIterator(this);
+        /*
+         * The rank is set to 0 if the iterator seeks the beginning. If not, it
+         * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
+         * by rank for now.
+         */
         if (currentLocation == null) {
             currentLocation = new CtfLocation(0L);
+            context.setRank(0);
         }
-        CtfIterator context = new CtfIterator(this);
-
         if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) {
             ((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS);
             currentLocation.setLocation(getEndTime().getValue() + 1);
         }
         context.setLocation(currentLocation);
+        if(context.getRank() != 0)
         context.setRank(ITmfContext.UNKNOWN_RANK);
         return context;
     }
@@ -207,11 +209,14 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
         if (context instanceof CtfIterator) {
             CtfIterator ctfIterator = (CtfIterator) context;
             event = ctfIterator.getCurrentEvent();
-            ctfIterator.advance();
+
             if (event != null) {
                 updateAttributes(context, event.getTimestamp());
+                ctfIterator.advance();
+                ctfIterator.increaseRank();
             }
         }
+
         return event;
     }
 
This page took 0.028457 seconds and 5 git commands to generate.