add fallback for seeking by unindexed traces
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 29 Mar 2012 14:38:52 +0000 (10:38 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Mon, 16 Apr 2012 18:20:12 +0000 (14:20 -0400)
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
org.eclipse.linuxtools.tmf.core.tests/.classpath
org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF
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 9d28f3007dede1e056624788fb992f3a8bb7d50f..d5424ab304c3914e3a52b2e4018e917a2a23eaaa 100644 (file)
@@ -93,7 +93,12 @@ public class ReadTrace {
             System.out.print(val);
             System.out.print(", ");
         }
-        testSeekIndex(trace);
+        try {
+            testSeekIndex(trace);
+        } catch (CTFReaderException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
 
         try {
             testSeekIndex(trace);
@@ -166,7 +171,7 @@ public class ReadTrace {
         return Long.MIN_VALUE;
     }
 
-    public static void testSeekIndex(CTFTrace trace) {
+    public static void testSeekIndex(CTFTrace trace) throws CTFReaderException {
         CTFTraceReader fixture = new CTFTraceReader(trace);
         long rank = 300000L;
         long timeRank = 4281275394331L;
index 67ff4421272cdff7901d834311293542185349c4..3177f5489ff4445b05d6b8d65bc113233b9a529d 100644 (file)
@@ -284,9 +284,10 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the boolean seek(long) method test.
+     * @throws CTFReaderException
      */
     @Test
-    public void testSeekIndex() {
+    public void testSeekIndex() throws CTFReaderException {
         long rank = 30000L;
         long first, second = 0, third , fourth;
         /*
index 2632eeaf6468ae9625ffcd27863418d7581e89ce..5ebf5cc76f2053f90360d375e0f704e62eb91cc2 100644 (file)
@@ -19,7 +19,7 @@ import java.util.Vector;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
+
 /**
  * Reads the events of a trace.
  */
@@ -339,14 +339,29 @@ public class CTFTraceReader {
 
         long tempIndex = Long.MIN_VALUE;
         long tempTimestamp = Long.MIN_VALUE;
-        for (StreamInputReader streamInputReader : this.streamInputReaders) {
+        try {
+            for (StreamInputReader streamInputReader : this.streamInputReaders) {
+                /*
+                 * Seek the trace reader.
+                 */
+                final long streamIndex = streamInputReader.seekIndex(index);
+                tempIndex = Math.max(tempIndex, streamIndex);
+                tempTimestamp = Math.max(tempTimestamp,
+                        streamInputReader.getCurrentEvent().timestamp);
+
+            }
+        } catch (CTFReaderException e) {
             /*
-             * Seek the trace reader.
+             * Important, if it failed, it's because it's not yet indexed,
+             * so we have to manually advance to the right value.
              */
-            final long streamIndex = streamInputReader.seekIndex(index);
-            tempIndex = Math.max(tempIndex, streamIndex);
-            tempTimestamp = Math.max(tempTimestamp, streamInputReader.getCurrentEvent().timestamp);
-
+            for (StreamInputReader streamInputReader : this.streamInputReaders) {
+                /*
+                 * Seek the trace reader.
+                 */
+                streamInputReader.seek(0);
+            }
+            tempIndex = 0;
         }
         for (StreamInputReader streamInputReader : this.streamInputReaders) {
             /*
@@ -360,8 +375,8 @@ public class CTFTraceReader {
         /*
          * advance for offset
          */
-        while( (prio.peek().getCurrentEvent().timestamp < tempTimestamp) && hasMoreEvents() )
-        {
+        while ((prio.peek().getCurrentEvent().timestamp < tempTimestamp)
+                && hasMoreEvents()) {
             this.advance();
         }
         long pos = tempIndex;
index 46e2fd190c0b4d83d0aa1ab85a26b0e7c9eab9cd..4150c8475f76e2b7df14f826fb37f6135cd5024c 100644 (file)
@@ -184,7 +184,7 @@ public class StreamInputReader {
     }
 
 
-    public long seekIndex(long index)
+    public long seekIndex(long index) throws CTFReaderException
     {
         /*
          * Search in the index for the packet to search in.
@@ -201,6 +201,9 @@ public class StreamInputReader {
         /*
          * get the current index
          */
+        if(this.packetReader.getCurrentPacket() == null){
+            throw new CTFReaderException("Current packet null in index seek, did you index your trace yet?");
+        }
         return this.packetReader.getCurrentPacket().getIndexBegin();
 
     }
index 2a987e28541dabf30f380fa3890ff1f723abecf8..a2dcfc3c8089e7194a07cd4f298b4716fa1cc5c6 100644 (file)
@@ -4,5 +4,6 @@
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="stubs"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.linuxtools.tmf.core"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 31c3c816367513249aa9c0b743b2d5961c178c64..f09ae57717211479a23e12ef4a7401c18f655b01 100644 (file)
@@ -11,5 +11,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.junit;bundle-version="3.8.2",
  org.eclipse.core.runtime;bundle-version="3.7.0",
  org.eclipse.core.resources;bundle-version="3.7.100",
- org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0"
+ org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0",
+ org.eclipse.linuxtools.ctf.core;bundle-version="0.1.0"
 Export-Package: org.eclipse.linuxtools.tmf.tests.stubs.trace;x-friends:="org.eclipse.linuxtools.tmf.ui.tests"
index d37a3efda1f34d93cdd33b0bdda0b4e4a113afc4..64a51252c127129d48258c928aab740c2eae4f92 100644 (file)
@@ -31,8 +31,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     public CtfIterator(CtfTmfTrace trace, long timestampValue, long rank) {
         super(trace.getCTFTrace());
         this.ctfTmfTrace = trace;
-        this.curLocation = (new CtfLocation(
-                this.getCurrentEvent().getTimestampValue()));
+        this.curLocation = (new CtfLocation(this.getCurrentEvent()
+                .getTimestampValue()));
         if (this.getCurrentEvent().getTimestampValue() != timestampValue) {
             this.seek(timestampValue);
         }
@@ -85,7 +85,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     @Override
     public void setRank(long rank) {
-        seekRank( rank );
+        seekRank(rank);
     }
 
     /*
@@ -96,8 +96,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     @Override
     public CtfIterator clone() {
         CtfIterator clone = null;
-        clone = new CtfIterator(ctfTmfTrace,
-                this.getCurrentEvent().getTimestampValue(), curRank);
+        clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent()
+                .getTimestampValue(), curRank);
         return clone;
     }
 
index 71838854c72f63ff1de3f70b24df5de03781f30f..418cc38f0175c93053dcb7fd814b7a17ca34c838 100644 (file)
@@ -83,6 +83,8 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements
         // this.fEndTime.clone()));
     }
 
+
+
     @Override
     public void indexTrace(boolean waitForCompletion) {
     }
@@ -242,8 +244,8 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements
     @Override
     public double getLocationRatio(ITmfLocation<?> location) {
         CtfIterator curLocation = (CtfIterator) location;
-        return ((double) curLocation.getCurrentEvent().getTimestampValue() -
-                curLocation.getStartTime())
+        return ((double) curLocation.getCurrentEvent().getTimestampValue() - curLocation
+                .getStartTime())
                 / (curLocation.getEndTime() - curLocation.getStartTime());
     }
 
This page took 0.067291 seconds and 5 git commands to generate.