Add incremental indexing support Bug 380952
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 15 May 2012 20:56:10 +0000 (16:56 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 29 May 2012 19:38:43 +0000 (15:38 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
18 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
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.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.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/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.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
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramDataModel.java

index ede840ab360d93cb800de45002046b445b107ee4..adb454a0eeff44612a89eb65b6a557cb02d19bf5 100644 (file)
@@ -20,7 +20,7 @@ public abstract class TestParams {
     private static final String testTracePath1 = "traces/kernel"; //$NON-NLS-1$
     private static CTFTrace testTrace1 = null;
     private static CTFTrace testTraceFromFile1 = null;
-    private static final File testTraceFile1 = new File(testTracePath1);
+    private static final File testTraceFile1 = new File(testTracePath1+"/channel0_0"); //$NON-NLS-1$
 
     private static final File emptyFile = new File(""); //$NON-NLS-1$
     private static CTFTrace emptyTrace = null;
index f090d273aec1cbd7340fb99644d5ec99002da1c3..b373fe6c885d319ac1305a0108e02f90621b613b 100644 (file)
@@ -15,12 +15,14 @@ package org.eclipse.linuxtools.ctf.core.tests.headless;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Map;
 import java.util.Vector;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 
 public class ReadTrace {
 
@@ -32,7 +34,7 @@ public class ReadTrace {
         final String TRACE_PATH = "traces/kernel";
 
         // Change this to enable text output
-        final boolean USE_TEXT = true;
+        final boolean USE_TEXT = false;
 
         final int LOOP_COUNT = 1;
 
@@ -61,22 +63,21 @@ public class ReadTrace {
                 while (traceReader.hasMoreEvents()) {
                     EventDefinition ed = traceReader.getCurrentEventDef();
                     nbEvent++;
-                    if (prev == traceReader.getIndex()) {
-                        System.out.println("Error on events " + prev);
-                    }
-                    prev = traceReader.getIndex();
                     if (USE_TEXT) {
                         String output = formatDate(ed.getTimestamp()
                                 + trace.getOffset());
-                        System.out.println(traceReader.getIndex() + ", "
+                        System.out.println(nbEvent + ", "
                                 + output + ", " + ed.getDeclaration().getName()
                                 + ", " + ed.getCPU() + ed.getFields().toString()) ;
                     }
-
+                    long endTime = traceReader.getEndTime();
+                    long timestamp = traceReader.getCurrentEventDef().getTimestamp();
                     traceReader.advance();
                 }
+                Map<Long, Stream> streams = traceReader.getTrace().getStreams();
             }
             stop = System.nanoTime();
+
             System.out.print('.');
             double time = (stop - start) / (double) nbEvent;
             benchs.add(time);
@@ -88,65 +89,11 @@ public class ReadTrace {
         }
         avg /= benchs.size();
         System.out.println("Time to read " + nbEvent + " events = " + avg
-                + " events/ns");
+                + " ns/event");
         for (Double val : benchs) {
             System.out.print(val);
             System.out.print(", ");
         }
-        testSeekIndex(trace);
-        testSeekIndex(trace);
-    }
-
-    /**
-     * @return
-     */
-    private static long getTimestamp(CTFTraceReader fixture) {
-        if (fixture.getCurrentEventDef() != null) {
-            return fixture.getCurrentEventDef().getTimestamp();
-        }
-        return Long.MIN_VALUE;
-    }
-
-    public static void testSeekIndex(CTFTrace trace) {
-        CTFTraceReader fixture = new CTFTraceReader(trace);
-        long rank = 300000L;
-        long timeRank = 4281275394331L;
-        long nearEnd = 4287422858132L;
-        long seekTime_0;
-        long seekIndex_0 = 0;
-        long seekNext_300000 = 0;
-        long seekIndex_300000 = 0;
-        long seekTime_300000 = 0;
-        String cr = "\n"; //$NON-NLS-1$
-        fixture.seek(0);
-        for (int i = 0; i < 100; i++) {
-            fixture.advance();
-        }
-
-        fixture.seek(nearEnd);
-        /*
-         * we need to read the trace before seeking
-         */
-        fixture.seek(0);
-        seekTime_0 = getTimestamp(fixture);
-        for (int i = 0; i < rank; i++) {
-            fixture.advance();
-        }
-        seekNext_300000 = getTimestamp(fixture);
-        fixture.seek(timeRank);
-        seekTime_300000 = getTimestamp(fixture);
-        fixture.seekIndex(0);
-        seekIndex_0 = getTimestamp(fixture);
-
-        fixture.seekIndex(rank);
-        seekIndex_300000 = getTimestamp(fixture);
-        System.out.print(cr);
-        System.out.println("seek(0) " + seekTime_0 + cr + //$NON-NLS-1$
-                "seekIndex(0) " + seekIndex_0 + cr + //$NON-NLS-1$
-                "Next(300000) " + seekNext_300000 + cr + //$NON-NLS-1$
-                "seek(time(300000)) " + seekTime_300000 + cr + //$NON-NLS-1$
-                "seekIndex(300000) " + seekIndex_300000 //$NON-NLS-1$
-        );
     }
 
     /**
index d28f89a91fea5473465c46fb78863659dcfba9d2..f628eedf8294f412e72485b09caf12572e7f9b9f 100644 (file)
@@ -37,6 +37,7 @@ public class CTFTraceReaderTest {
 
     /**
      * Perform pre-test initialization.
+     *
      * @throws CTFReaderException
      */
     @Before
@@ -55,6 +56,7 @@ public class CTFTraceReaderTest {
     /**
      * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
      * trace.
+     *
      * @throws CTFReaderException
      */
     @Test
@@ -105,17 +107,26 @@ public class CTFTraceReaderTest {
     /**
      * Run the boolean advance() method test. Test advancing when we're at the
      * end, so we expect that there is no more events.
-     *
-     * @throws CTFReaderException
      */
     @Test
-    public void testAdvance_end() throws CTFReaderException {
+    public void testAdvance_end() {
+        int i = 0;
+        boolean result = fixture.advance();
+        while (result) {
+            result = fixture.advance();
+            i++;
+        }
+        fixture.seek(0);
+        fixture.advance();
         fixture.goToLastEvent();
-        while (fixture.hasMoreEvents()) {
-            fixture.advance();
+        i = 1;
+        result = fixture.advance();
+        while (result) {
+            result = fixture.advance();
+            i++;
         }
-        boolean result = fixture.advance();
         assertFalse(result);
+        assertEquals(i, 1);
     }
 
     /**
@@ -142,12 +153,13 @@ public class CTFTraceReaderTest {
      *
      * Both trace reader are different objects, so they shouldn't "equals" each
      * other.
+     *
      * @throws CTFReaderException
      */
     @Test
     public void testEquals() throws CTFReaderException {
         CTFTraceReader fixture2 = new CTFTraceReader(TestParams.createTrace());
-        assertTrue(fixture.equals(fixture2));
+        assertEquals(fixture, fixture2);
     }
 
     /**
@@ -163,11 +175,9 @@ public class CTFTraceReaderTest {
     /**
      * Run the getCurrentEventDef() method test. Get the last event's
      * definition.
-     *
-     * @throws CTFReaderException
      */
     @Test
-    public void testGetCurrentEventDef_last() throws CTFReaderException {
+    public void testGetCurrentEventDef_last() {
         fixture.goToLastEvent();
         EventDefinition result = fixture.getCurrentEventDef();
         assertNotNull(result);
@@ -201,8 +211,7 @@ public class CTFTraceReaderTest {
         fixture.goToLastEvent();
         long ts1 = getTimestamp();
         long ts2 = fixture.getEndTime();
-        // the end time can be later than the last event.
-        assertTrue(ts1 <= ts2);
+        assertEquals(ts1, ts2);
     }
 
     /**
@@ -283,51 +292,14 @@ public class CTFTraceReaderTest {
     }
 
 
-    /**
-     * Run the boolean seek(long) method test.
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testSeekIndex() throws CTFReaderException {
-        long rank = 30000L;
-        long first, second = 0, third , fourth;
-        /*
-         * we need to read the trace before seeking
-         */
-        first = getTimestamp();
-        for( int i = 0 ; i < 60000; i++ )
-        {
-            if( i == rank) {
-                second = getTimestamp();
-            }
-            fixture.advance();
-        }
-        boolean result= fixture.seekIndex(0);
-
-        third = getTimestamp();
-        boolean result2 = fixture.seekIndex(rank);
-        fourth = getTimestamp();
-        /*
-         * in blocks to see where code coverage fails
-         */
-        {
-            assertTrue(result);
-        }
-        {
-            assertTrue(result2);
-        }
-        {
-            assertEquals( first , third);
-        }
-        {
-            assertEquals( second , fourth);
-        }
-    }
 
     /**
      * @return
      */
     private long getTimestamp() {
-        return fixture.getCurrentEventDef().getTimestamp();
+        if (fixture.getCurrentEventDef() != null) {
+            return fixture.getCurrentEventDef().getTimestamp()+ this.fixture.getTrace().getOffset();
+        }
+        return -1;
     }
 }
index 52493974c11f37e6983afb1fd099f3c129925860..3113c15e932fee04b988fcca9ba81b3510a41223 100644 (file)
@@ -51,8 +51,7 @@ public class StreamInputPacketIndexEntryTest {
     @Test
     public void testStreamInputPacketIndexEntry_1() {
         String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1, " + //$NON-NLS-1$
-                "timestampBegin=0, timestampEnd=0, " + //$NON-NLS-1$
-                "indexBegin=9223372036854775807, indexEnd=9223372036854775807]"; //$NON-NLS-1$
+                "timestampBegin=0, timestampEnd=0]"; //$NON-NLS-1$
 
         assertNotNull(fixture);
         assertEquals(expectedResult, fixture.toString());
@@ -64,8 +63,8 @@ public class StreamInputPacketIndexEntryTest {
     @Test
     public void testToString() {
         String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1,"+ //$NON-NLS-1$
-                " timestampBegin=1, timestampEnd=1, indexBegin=9223372036854775807,"+ //$NON-NLS-1$
-                " indexEnd=9223372036854775807]"; //$NON-NLS-1$
+                " timestampBegin=1, timestampEnd=1]"; //$NON-NLS-1$
+
 
         fixture.setContentSizeBits(1);
         fixture.setDataOffsetBits(1);
index 42130794264d44679e2cb542c76467007f3495c5..1fad892ec4e3adfab0f7506b1e43401028b6aeed 100644 (file)
@@ -6,7 +6,8 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.nio.channels.FileChannel;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
@@ -99,12 +100,13 @@ public class EventDeclarationTest {
      * Run the EventDefinition createDefinition(StreamInputReader) method test.
      *
      * @throws CTFReaderException
+     * @throws FileNotFoundException
      */
     @Test
-    public void testCreateDefinition() throws CTFReaderException {
+    public void testCreateDefinition() throws CTFReaderException, FileNotFoundException {
         StreamInputReader streamInputReader = new StreamInputReader(
                 new StreamInput(new Stream(TestParams.createTrace()),
-                        (FileChannel) null, TestParams.getTraceFile()));
+                       (new FileInputStream(TestParams.getTraceFile())).getChannel(), TestParams.getTraceFile()));
 
         EventDefinition result = fixture.createDefinition(streamInputReader);
         assertNotNull(result);
index f9d07403640366ceeca075c5df2a27699cd1e2b2..4f89a918c4cfc8310ade179094f06b6d3193d1b0 100644 (file)
@@ -223,7 +223,7 @@ public class CTFTrace implements IDefinitionScope {
                 /*
                  * index the trace
                  */
-                s.createIndex();
+                s.setupIndex();
             }
         }
     }
index adef79362571fe825949a507e218d1a1a3c6f719..42ae663ee006015699ef3598876775887ecb331e 100644 (file)
@@ -13,7 +13,6 @@
 package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.PriorityQueue;
 import java.util.Set;
 import java.util.Vector;
@@ -22,7 +21,6 @@ import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
 import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
 
 /**
@@ -53,7 +51,7 @@ public class CTFTraceReader {
     /**
      * Array to count the number of event per trace file.
      */
-    private int[] eventCountPerTraceFile;
+    private long[] eventCountPerTraceFile;
 
     /**
      * Timestamp of the first event in the trace
@@ -65,18 +63,11 @@ public class CTFTraceReader {
      */
     private long endTime;
 
-    
+
     protected void setEndTime(long endTime) {
         this.endTime = endTime;
     }
 
-    /**
-     * Current event index
-     */
-    private long fIndex;
-
-    private final HashMap<Integer, Long> startIndex;
-
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -90,6 +81,7 @@ public class CTFTraceReader {
      */
     public CTFTraceReader(CTFTrace trace) {
         this.trace = trace;
+        streamInputReaders.clear();
 
         /**
          * Create the trace file readers.
@@ -102,16 +94,14 @@ public class CTFTraceReader {
         populateStreamInputReaderHeap();
 
         /**
-         * Get the start Time of this trace
-         * bear in mind that the trace could be empty.
+         * Get the start Time of this trace bear in mind that the trace could be
+         * empty.
          */
         this.startTime = 0;// prio.peek().getPacketReader().getCurrentPacket().getTimestampBegin();
         if (hasMoreEvents()) {
             this.startTime = prio.peek().getCurrentEvent().getTimestamp();
             this.setEndTime(this.startTime);
-            this.fIndex = 0;
         }
-        startIndex = new HashMap<Integer, Long>();
     }
 
     /**
@@ -139,13 +129,6 @@ public class CTFTraceReader {
         return this.startTime;
     }
 
-    /**
-     * @return the index
-     */
-    public long getIndex() {
-        return fIndex;
-    }
-
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -166,6 +149,7 @@ public class CTFTraceReader {
              * For each trace file of the stream.
              */
             for (StreamInput streamInput : streamInputs) {
+                streamInput.getIndex().getEntries().clear();
                 /*
                  * Create a reader.
                  */
@@ -182,7 +166,7 @@ public class CTFTraceReader {
         /*
          * Create the array to count the number of event per trace file.
          */
-        this.eventCountPerTraceFile = new int[this.streamInputReaders.size()];
+        this.eventCountPerTraceFile = new long[this.streamInputReaders.size()];
     }
 
     /**
@@ -205,6 +189,7 @@ public class CTFTraceReader {
              * Add each trace file reader in the priority queue, if we are able
              * to read an event from it.
              */
+            reader.setParent(this);
             if (reader.readNextEvent()) {
                 this.prio.add(reader);
 
@@ -249,24 +234,6 @@ public class CTFTraceReader {
         if (top == null) {
             return false;
         }
-        /*
-         * index if needed
-         */
-        if (hasMoreEvents()) {
-            StreamInputPacketReader packetReader = top.getPacketReader();
-            boolean packetHasMoreEvents = packetReader.hasMoreEvents();
-            StreamInputPacketIndexEntry currentPacket = packetReader
-                    .getCurrentPacket();
-            if (!packetHasMoreEvents) {
-                int n = this.streamInputReaders.indexOf(top);
-                if (!startIndex.containsKey(n)) {
-                    startIndex.put(n, 0L);
-                }
-                currentPacket.setIndexBegin(startIndex.get(n));
-                currentPacket.setIndexEnd(fIndex);
-                startIndex.put(n, fIndex + 1);
-            }
-        }
         /*
          * Read the next event of this reader.
          */
@@ -281,15 +248,17 @@ public class CTFTraceReader {
             /*
              * increment the index
              */
-            fIndex++;
-        }
-        boolean hasMoreEvents = hasMoreEvents();
 
+            if (top.getCurrentEvent() != null) {
+                this.endTime = Math.max(top.getCurrentEvent().getTimestamp(),
+                        this.endTime);
+            }
+        }
         /*
          * If there is no reader in the queue, it means the trace reader reached
          * the end of the trace.
          */
-        return hasMoreEvents;
+        return hasMoreEvents();
     }
 
     /**
@@ -297,20 +266,10 @@ public class CTFTraceReader {
      *
      * @throws CTFReaderException
      */
-    public void goToLastEvent() throws CTFReaderException {
-
-        for (StreamInputReader streamInputReader : this.streamInputReaders) {
-            /*
-             * Seek the trace reader.
-             */
-            streamInputReader.goToLastEvent();
-        }
-        int count = prio.size();
-        for (int i = 0; i < (count - 1); i++) {
-            /*
-             * Cull all the streams aside from the last one
-             */
-            prio.poll();
+    public void goToLastEvent() {
+        seek(this.getEndTime());
+        while (this.prio.size() > 1) {
+            this.advance();
         }
     }
 
@@ -330,13 +289,11 @@ public class CTFTraceReader {
          * Remove all the trace readers from the priority queue
          */
         this.prio.clear();
-        fIndex = 0;
-        long offset = 0;
         for (StreamInputReader streamInputReader : this.streamInputReaders) {
             /*
              * Seek the trace reader.
              */
-            offset += streamInputReader.seek(timestamp);
+            streamInputReader.seek(timestamp);
 
             /*
              * Add it to the priority queue if there is a current event.
@@ -346,82 +303,9 @@ public class CTFTraceReader {
         for (StreamInputReader streamInputReader : this.streamInputReaders) {
             if (streamInputReader.getCurrentEvent() != null) {
                 this.prio.add(streamInputReader);
-                fIndex = Math.max(fIndex, streamInputReader.getPacketReader()
-                        .getCurrentPacket().getIndexBegin()
-                        + offset);
-            }
-        }
-        return hasMoreEvents();
-    }
-
-    public boolean seekIndex(long index) {
-        this.prio.clear();
-
-        long tempIndex = Long.MIN_VALUE;
-        long tempTimestamp = Long.MIN_VALUE;
-        try {
-            for (StreamInputReader streamInputReader : this.streamInputReaders) {
-                /*
-                 * Seek the trace reader.
-                 */
-                final long streamIndex = streamInputReader.seekIndex(index);
-                if (streamInputReader.getCurrentEvent() != null) {
-                    tempIndex = Math.max(tempIndex, streamIndex);
-                    EventDefinition currentEvent = streamInputReader
-                            .getCurrentEvent();
-                    /*
-                     * Maybe we're at the beginning of a trace.
-                     */
-                    if (currentEvent == null) {
-                        streamInputReader.readNextEvent();
-                        currentEvent = streamInputReader.getCurrentEvent();
-                    }
-                    if (currentEvent != null) {
-                        tempTimestamp = Math.max(tempTimestamp,
-                                currentEvent.getTimestamp());
-                    } else {
-                        /*
-                         * probably beyond the last event
-                         */
-                        tempIndex = goToZero();
-                    }
-                }
-
-            }
-        } catch (CTFReaderException e) {
-            /*
-             * Important, if it failed, it's because it's not yet indexed, so we
-             * have to manually advance to the right value.
-             */
-            tempIndex = goToZero();
-        }
-        for (StreamInputReader streamInputReader : this.streamInputReaders) {
-            /*
-             * Add it to the priority queue if there is a current event.
-             */
-
-            if (streamInputReader.getCurrentEvent() != null) {
-                this.prio.add(streamInputReader);
-            }
-        }
-        if (tempIndex == Long.MAX_VALUE) {
-            tempIndex = 0;
-        }
-        long pos = tempIndex;
-        if (index > tempIndex) {
-            /*
-             * advance for offset
-             */
-            while ((prio.peek().getCurrentEvent().getTimestamp() < tempTimestamp)
-                    && hasMoreEvents()) {
-                this.advance();
-            }
 
-            for (pos = tempIndex; (pos < index) && hasMoreEvents(); pos++) {
-                this.advance();
             }
         }
-        this.fIndex = pos;
         return hasMoreEvents();
     }
 
@@ -474,14 +358,14 @@ public class CTFTraceReader {
             return;
         }
 
-        for (int i : this.eventCountPerTraceFile) {
+        for (long i : this.eventCountPerTraceFile) {
             numEvents += i;
         }
 
         for (int j = 0; j < this.eventCountPerTraceFile.length; j++) {
             StreamInputReader se = this.streamInputReaders.get(j);
 
-            int len = (width * this.eventCountPerTraceFile[se.getName()])
+            long len = (width * this.eventCountPerTraceFile[se.getName()])
                     / numEvents;
 
             StringBuilder sb = new StringBuilder(se.getFilename() + "\t["); //$NON-NLS-1$
@@ -490,7 +374,7 @@ public class CTFTraceReader {
                 sb.append('+');
             }
 
-            for (int i = len; i < width; i++) {
+            for (long i = len; i < width; i++) {
                 sb.append(' ');
             }
 
@@ -507,7 +391,6 @@ public class CTFTraceReader {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = (prime * result) + (int) (endTime ^ (endTime >>> 32));
         result = (prime * result) + (int) (startTime ^ (startTime >>> 32));
         result = (prime * result)
                 + ((streamInputReaders == null) ? 0 : streamInputReaders
@@ -528,12 +411,6 @@ public class CTFTraceReader {
             return false;
         }
         CTFTraceReader other = (CTFTraceReader) obj;
-        if (endTime != other.endTime) {
-            return false;
-        }
-        if (startTime != other.startTime) {
-            return false;
-        }
         if (streamInputReaders == null) {
             if (other.streamInputReaders != null) {
                 return false;
index b38ef26b5f4c833e25581398077772dcff50b0ce..50193e553cec1b02f50044347781a152e77d3ba4 100644 (file)
@@ -35,7 +35,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr
  * <p>
  * Reads the events of a packet of a trace file.
  */
-class StreamInputPacketReader implements IDefinitionScope {
+public class StreamInputPacketReader implements IDefinitionScope {
 
     // ------------------------------------------------------------------------
     // Constants
index 492734a553f1a327f8cd744cbe5c6571cb3715b9..00842e8f7b7429a2fd064f713ffc61cd48487daf 100644 (file)
@@ -13,7 +13,6 @@
 package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.nio.ByteOrder;
-import java.util.ListIterator;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
@@ -44,7 +43,7 @@ public class StreamInputReader {
     /**
      * Iterator on the packet index
      */
-    private ListIterator<StreamInputPacketIndexEntry> packetIndexIt;
+    private int packetIndex;
 
     /**
      * Reference to the current event of this trace file (iow, the last on that
@@ -54,6 +53,12 @@ public class StreamInputReader {
 
     private int name;
 
+    private CTFTraceReader parent;
+
+    private final long prevIndex;
+
+    private final boolean isthisthefirsttimewerereadingthisgivenstream;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -67,12 +72,13 @@ public class StreamInputReader {
     public StreamInputReader(StreamInput streamInput) {
         this.streamInput = streamInput;
         this.packetReader = new StreamInputPacketReader(this);
-
+        this.isthisthefirsttimewerereadingthisgivenstream = true;
         /*
          * Get the iterator on the packet index.
          */
-        this.packetIndexIt = streamInput.getIndex().listIterator();
+        this.packetIndex = 0;
 
+        this.prevIndex = 0;
         /*
          * Make first packet the current one.
          */
@@ -127,11 +133,19 @@ public class StreamInputReader {
      * @return If an event has been successfully read.
      */
     public boolean readNextEvent() {
+
+
         /*
          * Change packet if needed
          */
         if (!this.packetReader.hasMoreEvents()) {
-            goToNextPacket();
+            final StreamInputPacketIndexEntry prevPacket = this.packetReader
+                    .getCurrentPacket();
+            if (prevPacket != null) {
+                goToNextPacket();
+                final StreamInputPacketIndexEntry currentPacket = this.packetReader
+                        .getCurrentPacket();
+            }
         }
 
         /*
@@ -141,11 +155,16 @@ public class StreamInputReader {
             try {
                 this.setCurrentEvent(this.packetReader.readNextEvent());
             } catch (CTFReaderException e) {
-                /* Some problem happened, we'll assume there is no more events */
+                /*
+                 * Some problem happened, we'll assume that there are no more
+                 * events
+                 */
                 return false;
             }
             return true;
         }
+        final StreamInputPacketIndexEntry currentPacket = this
+                .getPacketReader().getCurrentPacket();
         this.setCurrentEvent(null);
         return false;
     }
@@ -154,14 +173,32 @@ public class StreamInputReader {
      * Change the current packet of the packet reader to the next one.
      */
     private void goToNextPacket() {
-        if (getPacketIndexIt().hasNext()) {
-            StreamInputPacketIndexEntry nextPacket = getPacketIndexIt().next();
-            this.packetReader.setCurrentPacket(nextPacket);
+        packetIndex++;
+        if (getPacketSize() >= (packetIndex + 1)) {
+            this.packetReader.setCurrentPacket(getPacket());
         } else {
-            this.packetReader.setCurrentPacket(null);
+            try {
+                if (this.streamInput.addPacketHeaderIndex()) {
+                    packetIndex = getPacketSize() - 1;
+                    this.packetReader.setCurrentPacket(getPacket());
+
+                } else {
+                    this.packetReader.setCurrentPacket(null);
+                }
+
+            } catch (CTFReaderException e) {
+                this.packetReader.setCurrentPacket(null);
+            }
         }
     }
 
+    /**
+     * @return
+     */
+    private int getPacketSize() {
+        return streamInput.getIndex().getEntries().size();
+    }
+
     /**
      * Changes the location of the trace file reader so that the current event
      * is the first event with a timestamp greater than the given timestamp.
@@ -174,7 +211,8 @@ public class StreamInputReader {
         /*
          * Search in the index for the packet to search in.
          */
-        this.packetIndexIt = this.streamInput.getIndex().search(timestamp);
+        this.packetIndex = this.streamInput.getIndex().search(timestamp)
+                .previousIndex();
 
         /*
          * Switch to this packet.
@@ -196,40 +234,7 @@ public class StreamInputReader {
         return offset;
     }
 
-    public long seekIndex(long index) throws CTFReaderException {
-        /*
-         * we need to check if a trace is empty too.
-         */
-        StreamInputPacketIndexEntry sipie = null;
-        /*
-         * Search in the index for the packet to search in.
-         */
-        this.packetIndexIt = this.streamInput.getIndex().searchIndex(index);
-        /*
-         * Switch to this packet.
-         */
-        goToNextPacket();
-
-        sipie = this.packetReader.getCurrentPacket();
-        /*
-         * Read the first packet
-         */
-        readNextEvent();
-        /*
-         * get the current index
-         */
-        if (this.packetReader.getCurrentPacket() == null)  {
-            if( !((sipie.getIndexBegin() == 0) && (sipie.getIndexEnd() == Long.MAX_VALUE))) {
-                throw new CTFReaderException(
-                        "Current packet null in index seek, did you index your trace yet?"); //$NON-NLS-1$
-            }
-            return 0;
-        }
-        return this.packetReader.getCurrentPacket().getIndexBegin();
-
-    }
-
-    public void goToLastEvent() throws CTFReaderException {
+    public void goToLastEvent() {
         /*
          * Search in the index for the packet to search in.
          */
@@ -243,7 +248,7 @@ public class StreamInputReader {
         /*
          * if the trace is empty.
          */
-        if((len == 0) ||(this.packetReader.hasMoreEvents() == false)) {
+        if ((len == 0) || (this.packetReader.hasMoreEvents() == false)) {
             /*
              * This means the trace is empty. abort.
              */
@@ -252,10 +257,10 @@ public class StreamInputReader {
         /*
          * Go to the last packet that contains events.
          */
-        for( int pos = len -1 ; pos > 0 ; pos--){
-            entry = this.streamInput.getIndex().getEntries().get(pos);
-            this.packetReader.setCurrentPacket(entry);
-            if(this.packetReader.hasMoreEvents()) {
+        for (int pos = len - 1; pos > 0; pos--) {
+            packetIndex = pos;
+            this.packetReader.setCurrentPacket(getPacket());
+            if (this.packetReader.hasMoreEvents()) {
                 break;
             }
         }
@@ -274,6 +279,21 @@ public class StreamInputReader {
         this.setCurrentEvent(prevEvent);
     }
 
+    /**
+     * @return the parent
+     */
+    public CTFTraceReader getParent() {
+        return parent;
+    }
+
+    /**
+     * @param parent
+     *            the parent to set
+     */
+    public void setParent(CTFTraceReader parent) {
+        this.parent = parent;
+    }
+
     public void setCurrentEvent(EventDefinition currentEvent) {
         this.currentEvent = currentEvent;
     }
@@ -281,8 +301,12 @@ public class StreamInputReader {
     /**
      * @return the packetIndexIt
      */
-    private ListIterator<StreamInputPacketIndexEntry> getPacketIndexIt() {
-        return packetIndexIt;
+    private int getPacketIndex() {
+        return packetIndex;
+    }
+
+    private StreamInputPacketIndexEntry getPacket() {
+        return streamInput.getIndex().getEntries().get(getPacketIndex());
     }
 
     /**
@@ -292,7 +316,9 @@ public class StreamInputReader {
         return packetReader;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
@@ -305,7 +331,9 @@ public class StreamInputReader {
         return result;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
index 92b2945eb015e1cf149b780b87cec85cee6836e7..6c819a7206b6aebd738cbe6c584676b9d04e22d3 100644 (file)
@@ -57,10 +57,20 @@ public class StreamInput implements IDefinitionScope {
     /**
      * The packet index of this input
      */
-    private final StreamInputPacketIndex index = new StreamInputPacketIndex();
+    private final StreamInputPacketIndex index;
 
     private long timestampEnd;
 
+    /*
+     * Definition of trace packet header
+     */
+    StructDefinition tracePacketHeaderDef = null;
+
+    /*
+     * Definition of trace stream packet context
+     */
+    StructDefinition streamPacketContextDef = null;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -79,6 +89,7 @@ public class StreamInput implements IDefinitionScope {
         this.stream = stream;
         this.fileChannel = fileChannel;
         this.file = file;
+        index = new StreamInputPacketIndex();
     }
 
     // ------------------------------------------------------------------------
@@ -126,25 +137,138 @@ public class StreamInput implements IDefinitionScope {
 
     /**
      * Create the index for this trace file.
-     *
+     */
+    public void setupIndex() {
+
+
+        /*
+         * The BitBuffer to extract data from the StreamInput
+         */
+        BitBuffer bitBuffer = new BitBuffer();
+        bitBuffer.order(this.getStream().getTrace().getByteOrder());
+
+        /*
+         * Create the definitions we need to read the packet headers + contexts
+         */
+        if (getStream().getTrace().getPacketHeader() != null) {
+            tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
+                    .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
+        }
+
+        if (getStream().getPacketContextDecl() != null) {
+            streamPacketContextDef = getStream().getPacketContextDecl()
+                    .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
+        }
+
+    }
+
+    public boolean addPacketHeaderIndex() throws CTFReaderException {
+        long currentPos = 0L;
+        if (!index.getEntries().isEmpty()) {
+            StreamInputPacketIndexEntry pos = index.getEntries().lastElement();
+            currentPos = computeNextOffset(pos);
+        }
+        long fileSize = getStreamSize();
+        if (currentPos < fileSize) {
+            BitBuffer bitBuffer = new BitBuffer();
+            bitBuffer.order(this.getStream().getTrace().getByteOrder());
+            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
+                    currentPos);
+            createPacketIndexEntry(fileSize, currentPos, packetIndex,
+                    tracePacketHeaderDef, streamPacketContextDef, bitBuffer);
+            index.addEntry(packetIndex);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @param fileSizeBytes
+     * @return
+     */
+    private long getStreamSize() {
+        return file.length();
+    }
+
+    /**
+     * @param fileSizeBytes
+     * @param packetOffsetBytes
+     * @param packetIndex
+     * @param tracePacketHeaderDef
+     * @param streamPacketContextDef
+     * @param bitBuffer
+     * @return
      * @throws CTFReaderException
      */
-    public void createIndex() throws CTFReaderException {
+    private long createPacketIndexEntry(long fileSizeBytes,
+            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
+            StructDefinition tracePacketHeaderDef,
+            StructDefinition streamPacketContextDef, BitBuffer bitBuffer)
+            throws CTFReaderException {
+        MappedByteBuffer bb = createPacketBitBuffer(fileSizeBytes,
+                packetOffsetBytes, packetIndex, bitBuffer);
+
         /*
-         * The size of the file in bytes
+         * Read the trace packet header if it exists.
          */
-        long fileSizeBytes = 0;
-        try {
-            fileSizeBytes = fileChannel.size();
-        } catch (IOException e) {
-            throw new CTFReaderException(e);
+        if (tracePacketHeaderDef != null) {
+            parseTracePacketHeader(tracePacketHeaderDef, bitBuffer);
         }
 
         /*
-         * Offset of the current packet in bytes
+         * Read the stream packet context if it exists.
          */
-        long packetOffsetBytes = 0;
+        if (streamPacketContextDef != null) {
+            parsePacketContext(fileSizeBytes, streamPacketContextDef,
+                    bitBuffer, packetIndex);
+        } else {
+            setPacketContextNull(fileSizeBytes, packetIndex);
+        }
+
+        /* Basic validation */
+        if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
+            throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
+        }
 
+        if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex
+                .getOffsetBytes()) * 8)) {
+            throw new CTFReaderException(
+                    "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+        }
+
+        /*
+         * Offset in the file, in bits
+         */
+        packetIndex.setDataOffsetBits(bitBuffer.position());
+
+        /*
+         * Update the counting packet offset
+         */
+        packetOffsetBytes = computeNextOffset(packetIndex);
+        return packetOffsetBytes;
+    }
+
+    /**
+     * @param packetIndex
+     * @return
+     */
+    private static long computeNextOffset(
+            StreamInputPacketIndexEntry packetIndex) {
+        return packetIndex.getOffsetBytes()
+                + ((packetIndex.getPacketSizeBits() + 7) / 8);
+    }
+
+    /**
+     * @param fileSizeBytes
+     * @param packetOffsetBytes
+     * @param packetIndex
+     * @param bitBuffer
+     * @return
+     * @throws CTFReaderException
+     */
+    private MappedByteBuffer createPacketBitBuffer(long fileSizeBytes,
+            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
+            BitBuffer bitBuffer) throws CTFReaderException {
         /*
          * Initial size, it should map at least the packet header + context
          * size.
@@ -152,217 +276,161 @@ public class StreamInput implements IDefinitionScope {
          * TODO: use a less arbitrary size.
          */
         long mapSize = 4096;
-
         /*
-         * Definition of trace packet header
+         * If there is less data remaining than what we want to map, reduce the
+         * map size.
          */
-        StructDefinition tracePacketHeaderDef = null;
+        if ((fileSizeBytes - packetIndex.getOffsetBytes()) < mapSize) {
+            mapSize = fileSizeBytes - packetIndex.getOffsetBytes();
+        }
 
         /*
-         * Definition of trace stream packet context
+         * Map the packet.
          */
-        StructDefinition streamPacketContextDef = null;
+        MappedByteBuffer bb;
 
-        /*
-         * The BitBuffer to extract data from the StreamInput
-         */
-        BitBuffer bitBuffer = new BitBuffer();
-        bitBuffer.order(this.getStream().getTrace().getByteOrder());
+        try {
+            bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes, mapSize);
+        } catch (IOException e) {
+            throw new CTFReaderException(e);
+        }
+        bitBuffer.setByteBuffer(bb);
+        return bb;
+    }
+
+    /**
+     * @param tracePacketHeaderDef
+     * @param bitBuffer
+     * @throws CTFReaderException
+     */
+    private void parseTracePacketHeader(StructDefinition tracePacketHeaderDef,
+            BitBuffer bitBuffer) throws CTFReaderException {
+        tracePacketHeaderDef.read(bitBuffer);
 
         /*
-         * Create the definitions we need to read the packet headers + contexts
+         * Check the CTF magic number
          */
-        if (getStream().getTrace().getPacketHeader() != null) {
-            tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
-                    .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
-        }
+        IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
+                .lookupDefinition("magic"); //$NON-NLS-1$
+        if (magicDef != null) {
+            int magic = (int) magicDef.getValue();
+            if (magic != Utils.CTF_MAGIC) {
+                throw new CTFReaderException(
+                        "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
+            }
 
-        if (getStream().getPacketContextDecl() != null) {
-            streamPacketContextDef = getStream().getPacketContextDecl()
-                    .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
         }
 
         /*
-         * Scan through the packets of the file.
+         * Check the trace UUID
          */
-        while (packetOffsetBytes < fileSizeBytes) {
-            /*
-             * If there is less data remaining than what we want to map, reduce
-             * the map size.
-             */
-            if ((fileSizeBytes - packetOffsetBytes) < mapSize) {
-                mapSize = fileSizeBytes - packetOffsetBytes;
-            }
-
-            /*
-             * Map the packet.
-             */
-            MappedByteBuffer bb;
-            try {
-                bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes,
-                        mapSize);
-            } catch (IOException e) {
-                throw new CTFReaderException(e);
+        ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef
+                .lookupDefinition("uuid"); //$NON-NLS-1$
+        if (uuidDef != null) {
+            byte[] uuidArray = new byte[16];
+
+            for (int i = 0; i < 16; i++) {
+                IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
+                        .getElem(i);
+                uuidArray[i] = (byte) uuidByteDef.getValue();
             }
-            bitBuffer.setByteBuffer(bb);
 
-            /*
-             * Create the index entry
-             */
-            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
-                    packetOffsetBytes);
-
-            /*
-             * Read the trace packet header if it exists.
-             */
-            if (tracePacketHeaderDef != null) {
-                tracePacketHeaderDef.read(bitBuffer);
-
-                /*
-                 * Check the CTF magic number
-                 */
-                IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
-                        .lookupDefinition("magic"); //$NON-NLS-1$
-                if (magicDef != null) {
-                    int magic = (int) magicDef.getValue();
-                    if (magic != Utils.CTF_MAGIC) {
-                        throw new CTFReaderException(
-                                "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
-                    }
-
-                }
-
-                /*
-                 * Check the trace UUID
-                 */
-                ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef
-                        .lookupDefinition("uuid"); //$NON-NLS-1$
-                if (uuidDef != null) {
-                    byte[] uuidArray = new byte[16];
-
-                    for (int i = 0; i < 16; i++) {
-                        IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
-                                .getElem(i);
-                        uuidArray[i] = (byte) uuidByteDef.getValue();
-                    }
-
-                    UUID uuid = Utils.makeUUID(uuidArray);
-
-                    if (!getStream().getTrace().getUUID().equals(uuid)) {
-                        throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
-                    }
-                }
-
-                /*
-                 * Check that the stream id did not change
-                 */
-                IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
-                        .lookupDefinition("stream_id"); //$NON-NLS-1$
-                if (streamIDDef != null) {
-                    long streamID = streamIDDef.getValue();
-
-                    if (streamID != getStream().getId()) {
-                        throw new CTFReaderException(
-                                "Stream ID changing within a StreamInput"); //$NON-NLS-1$
-                    }
-                }
-            }
+            UUID uuid = Utils.makeUUID(uuidArray);
 
-            /*
-             * Read the stream packet context if it exists.
-             */
-            if (streamPacketContextDef != null) {
-                streamPacketContextDef.read(bitBuffer);
-
-                /*
-                 * Read the content size in bits
-                 */
-                IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("content_size"); //$NON-NLS-1$
-                if (contentSizeDef != null) {
-                    packetIndex.setContentSizeBits((int) contentSizeDef
-                            .getValue());
-                } else {
-                    packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
-                }
-
-                /*
-                 * Read the packet size in bits
-                 */
-                IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("packet_size"); //$NON-NLS-1$
-                if (packetSizeDef != null) {
-                    packetIndex.setPacketSizeBits((int) packetSizeDef
-                            .getValue());
-                } else {
-                    if (packetIndex.getContentSizeBits() != 0) {
-                        packetIndex.setPacketSizeBits(packetIndex
-                                .getContentSizeBits());
-                    } else {
-                        packetIndex
-                                .setPacketSizeBits((int) (fileSizeBytes * 8));
-                    }
-                }
-
-                /*
-                 * Read the begin timestamp
-                 */
-                IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
-                if (timestampBeginDef != null) {
-                    packetIndex.setTimestampBegin( timestampBeginDef.getValue());
-                }
-
-                /*
-                 * Read the end timestamp
-                 */
-                IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("timestamp_end"); //$NON-NLS-1$
-                if (timestampEndDef != null) {
-                    packetIndex.setTimestampEnd(timestampEndDef
-                            .getValue());
-                    setTimestampEnd(packetIndex.getTimestampEnd());
-                }
-            } else {
-                /*
-                 * If there is no packet context, infer the content and packet
-                 * size from the file size (assume that there is only one packet
-                 * and no padding)
-                 */
-                packetIndex.setContentSizeBits( (int) (fileSizeBytes * 8));
-                packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
+            if (!getStream().getTrace().getUUID().equals(uuid)) {
+                throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
             }
+        }
 
-            /* Basic validation */
-            if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
-                throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
-            }
+        /*
+         * Check that the stream id did not change
+         */
+        IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
+                .lookupDefinition("stream_id"); //$NON-NLS-1$
+        if (streamIDDef != null) {
+            long streamID = streamIDDef.getValue();
 
-            if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex.getOffsetBytes()) * 8)) {
+            if (streamID != getStream().getId()) {
                 throw new CTFReaderException(
-                        "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+                        "Stream ID changing within a StreamInput"); //$NON-NLS-1$
             }
+        }
+    }
 
-            /*
-             * Offset in the file, in bits
-             */
-            packetIndex.setDataOffsetBits( bitBuffer.position());
+    /**
+     * @param fileSizeBytes
+     * @param packetIndex
+     */
+    private static void setPacketContextNull(long fileSizeBytes,
+            StreamInputPacketIndexEntry packetIndex) {
+        /*
+         * If there is no packet context, infer the content and packet size from
+         * the file size (assume that there is only one packet and no padding)
+         */
+        packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
+        packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
+    }
 
-            /*
-             * Add the packet index entry to the index
-             */
-            index.addEntry(packetIndex);
+    /**
+     * @param fileSizeBytes
+     * @param streamPacketContextDef
+     * @param bitBuffer
+     * @param packetIndex
+     */
+    private void parsePacketContext(long fileSizeBytes,
+            StructDefinition streamPacketContextDef, BitBuffer bitBuffer,
+            StreamInputPacketIndexEntry packetIndex) {
+        streamPacketContextDef.read(bitBuffer);
 
-            /*
-             * Update the counting packet offset
-             */
-            packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
+        /*
+         * Read the content size in bits
+         */
+        IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
+                .lookupDefinition("content_size"); //$NON-NLS-1$
+        if (contentSizeDef != null) {
+            packetIndex.setContentSizeBits((int) contentSizeDef.getValue());
+        } else {
+            packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
+        }
 
+        /*
+         * Read the packet size in bits
+         */
+        IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
+                .lookupDefinition("packet_size"); //$NON-NLS-1$
+        if (packetSizeDef != null) {
+            packetIndex.setPacketSizeBits((int) packetSizeDef.getValue());
+        } else {
+            if (packetIndex.getContentSizeBits() != 0) {
+                packetIndex.setPacketSizeBits(packetIndex.getContentSizeBits());
+            } else {
+                packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
+            }
+        }
+
+        /*
+         * Read the begin timestamp
+         */
+        IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
+                .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
+        if (timestampBeginDef != null) {
+            packetIndex.setTimestampBegin(timestampBeginDef.getValue());
+        }
+
+        /*
+         * Read the end timestamp
+         */
+        IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
+                .lookupDefinition("timestamp_end"); //$NON-NLS-1$
+        if (timestampEndDef != null) {
+            packetIndex.setTimestampEnd(timestampEndDef.getValue());
+            setTimestampEnd(packetIndex.getTimestampEnd());
         }
-        index.getEntries().get(0).setIndexBegin(0L);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
@@ -373,7 +441,9 @@ public class StreamInput implements IDefinitionScope {
         return result;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
index 80723ea1beaa9e65db5155b9c073b7206b905a45..234b887ced71b50e1b8824da93766ca130993bc5 100644 (file)
@@ -72,7 +72,8 @@ public class StreamInputPacketIndex {
         }
 
         if (!this.entries.isEmpty()) {
-            if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
+            if (entry.getTimestampBegin() < this.entries.lastElement()
+                    .getTimestampBegin()) {
                 throw new CTFReaderException(
                         "Packets begin timestamp decreasing"); //$NON-NLS-1$
             }
@@ -138,65 +139,6 @@ public class StreamInputPacketIndex {
             }
         }
 
-        return this.entries.listIterator(guessI);
-    }
-    /**
-     * Given a rank, this methods returns the first PacketIndexEntry that
-     * could include the rank, that is the last packet with a begin
-     * rank smaller than the given rank.
-     *
-     * @param index
-     *            The rank to look for.
-     * @return The StreamInputPacketEntry that corresponds to the packet that
-     *         includes the given timestamp.
-     */
-    public ListIterator<StreamInputPacketIndexEntry> searchIndex(final long index) {
-        /*
-         * Start with min and max covering all the elements.
-         */
-        int max = this.entries.size() - 1;
-        int min = 0;
-
-        int guessI;
-        StreamInputPacketIndexEntry guessEntry = null;
-
-        if (index < 0) {
-            throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$
-        }
-
-        for (;;) {
-            /*
-             * Guess in the middle of min and max. The +1 is so that in case
-             * (min + 1 == max), we choose the packet at the subscript "max"
-             * instead of the one at "min". Otherwise, it would give an infinite
-             * loop.
-             */
-            guessI = (max + min + 1) / 2;
-            guessEntry = this.entries.get(guessI);
-
-            /*
-             * If we reached the point where we focus on a single packet, our
-             * search is done.
-             */
-            if (min == max) {
-                break;
-            }
-
-            if (index < guessEntry.getIndexBegin()) {
-                /*
-                 * If the timestamp if before the begin timestamp, we know that
-                 * the packet to return is before the guess.
-                 */
-                max = guessI - 1;
-            } else if (index >= guessEntry.getIndexBegin()) {
-                /*
-                 * If the timestamp is after the begin timestamp, we know that
-                 * the packet to return is after the guess or is the guess.
-                 */
-                min = guessI;
-            }
-        }
-
         return this.entries.listIterator(guessI);
     }
 }
index f9968451ae8337c809b44b9dcc0deefd5e4c7b92..ee44da2136fea194674c36494e71f21bb2ae3a7e 100644 (file)
@@ -23,7 +23,7 @@ public class StreamInputPacketIndexEntry {
     // Attributes
     // ------------------------------------------------------------------------
 
-
+    public static final long INVALID_INDEX = Long.MAX_VALUE;
 
     /**
      * Offset of the packet in the file, in bytes
@@ -55,11 +55,6 @@ public class StreamInputPacketIndexEntry {
      */
     private long timestampEnd = 0;
 
-
-    private long indexBegin = Long.MAX_VALUE;
-
-    private long indexEnd = Long.MAX_VALUE;
-
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -91,18 +86,16 @@ public class StreamInputPacketIndexEntry {
         return (ts >= timestampBegin) && (ts <= timestampEnd);
     }
 
-    boolean includesIndex(long index){
-        return (index >= indexBegin) && (index <= indexEnd);
-    }
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     *
      * @see java.lang.Object#toString()
      */
     @Override
     public String toString() {
         return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes //$NON-NLS-1$
                 + ", timestampBegin=" + timestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
-                + timestampEnd + ", indexBegin=" + indexBegin + ", indexEnd=" //$NON-NLS-1$ //$NON-NLS-2$
-                + indexEnd + "]"; //$NON-NLS-1$
+                + timestampEnd + "]"; //$NON-NLS-1$
     }
 
     // ------------------------------------------------------------------------
@@ -124,7 +117,8 @@ public class StreamInputPacketIndexEntry {
     }
 
     /**
-     * @param dataOffsetBits the dataOffsetBits to set
+     * @param dataOffsetBits
+     *            the dataOffsetBits to set
      */
     public void setDataOffsetBits(int dataOffsetBits) {
         this.dataOffsetBits = dataOffsetBits;
@@ -138,7 +132,8 @@ public class StreamInputPacketIndexEntry {
     }
 
     /**
-     * @param packetSizeBits the packetSizeBits to set
+     * @param packetSizeBits
+     *            the packetSizeBits to set
      */
     public void setPacketSizeBits(int packetSizeBits) {
         this.packetSizeBits = packetSizeBits;
@@ -152,7 +147,8 @@ public class StreamInputPacketIndexEntry {
     }
 
     /**
-     * @param contentSizeBits the contentSizeBits to set
+     * @param contentSizeBits
+     *            the contentSizeBits to set
      */
     public void setContentSizeBits(int contentSizeBits) {
         this.contentSizeBits = contentSizeBits;
@@ -166,7 +162,8 @@ public class StreamInputPacketIndexEntry {
     }
 
     /**
-     * @param timestampBegin the timestampBegin to set
+     * @param timestampBegin
+     *            the timestampBegin to set
      */
     public void setTimestampBegin(long timestampBegin) {
         this.timestampBegin = timestampBegin;
@@ -180,37 +177,11 @@ public class StreamInputPacketIndexEntry {
     }
 
     /**
-     * @param timestampEnd the timestampEnd to set
+     * @param timestampEnd
+     *            the timestampEnd to set
      */
     public void setTimestampEnd(long timestampEnd) {
         this.timestampEnd = timestampEnd;
     }
 
-    /**
-     * @return the indexBegin
-     */
-    public long getIndexBegin() {
-        return indexBegin;
-    }
-
-    /**
-     * @param indexBegin the indexBegin to set
-     */
-    public void setIndexBegin(long indexBegin) {
-        this.indexBegin = indexBegin;
-    }
-
-    /**
-     * @return the indexEnd
-     */
-    public long getIndexEnd() {
-        return indexEnd;
-    }
-
-    /**
-     * @param indexEnd the indexEnd to set
-     */
-    public void setIndexEnd(long indexEnd) {
-        this.indexEnd = indexEnd;
-    }
 }
index b327c9c2650e7964052e0e8f91890da08d59a4d2..af4e75a557ce4dea3cbdfa5aef60bbd712a84dac 100644 (file)
@@ -592,61 +592,6 @@ public class CtfIteratorTest {
         assertTrue(result);
     }
 
-    /**
-     * Run the boolean seekRank(long) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testSeekRank_1()
-        throws Exception {
-        CtfIterator fixture = new CtfIterator(createTrace());
-        CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
-        ctfLocation.setLocation(Long.valueOf(1));
-        fixture.setLocation(ctfLocation);
-        fixture.increaseRank();
-        long rank = 1L;
-
-        boolean result = fixture.seekRank(rank);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertTrue(result);
-    }
-
-    /**
-     * Run the boolean seekRank(long) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testSeekRank_2()
-        throws Exception {
-        CtfIterator fixture = new CtfIterator(createTrace());
-        CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
-        ctfLocation.setLocation(Long.valueOf(1));
-        fixture.setLocation(ctfLocation);
-        fixture.increaseRank();
-        long rank = 1L;
-
-        boolean result = fixture.seekRank(rank);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-        assertTrue(result);
-    }
 
     /**
      * Run the void setLocation(ITmfLocation<?>) method test.
@@ -676,59 +621,6 @@ public class CtfIteratorTest {
         //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
     }
 
-    /**
-     * Run the void setRank(long) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testSetRank_1()
-        throws Exception {
-        CtfIterator fixture = new CtfIterator(createTrace());
-        CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
-        ctfLocation.setLocation(Long.valueOf(1));
-        fixture.setLocation(ctfLocation);
-        fixture.increaseRank();
-        long rank = 1L;
-
-        fixture.setRank(rank);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-    }
-
-    /**
-     * Run the void setRank(long) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testSetRank_2()
-        throws Exception {
-        CtfIterator fixture = new CtfIterator(createTrace());
-        CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
-        ctfLocation.setLocation(Long.valueOf(1));
-        fixture.setLocation(ctfLocation);
-        fixture.increaseRank();
-        long rank = 1L;
-
-        fixture.setRank(rank);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    java.lang.NullPointerException
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.createStreamInputReaders(CTFTraceReader.java:152)
-        //       at org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader.<init>(CTFTraceReader.java:92)
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator.<init>(CtfIterator.java:40)
-    }
 
     /**
      * Perform pre-test initialization.
index 423b7bbc377b2d622186fbc3d96f83d47308fb6a..2b90e67895ef5a25d7f1292ed856906be456b112 100644 (file)
@@ -7,17 +7,14 @@ import static org.junit.Assert.assertTrue;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedEventRequest;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
@@ -53,7 +50,7 @@ public class CtfTmfTraceTest {
         // add additional test code here
         assertNotNull(result);
         assertEquals(null, result.getEventType());
-        assertEquals(50000, result.getCacheSize());
+        assertEquals(1000, result.getCacheSize());
         assertEquals(0L, result.getNbEvents());
         assertEquals(0L, result.getStreamingInterval());
         assertEquals(null, result.getStateSystem());
@@ -62,30 +59,6 @@ public class CtfTmfTraceTest {
         assertEquals(null, result.getType());
     }
 
-    /**
-     * Run the ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent>) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testArmRequest_1()
-        throws Exception {
-        CtfTmfTrace fixture = initTrace();
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        ITmfDataRequest<CtfTmfEvent> request = new TmfCoalescedEventRequest(ITmfEvent.class);
-
-        ITmfContext result = fixture.armRequest(request);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNotNull(result);
-    }
-
-
     /**
      * @return
      * @throws TmfTraceException
@@ -95,77 +68,6 @@ public class CtfTmfTraceTest {
         fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
         return fixture;
     }
-
-    /**
-     * Run the ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent>) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testArmRequest_2()
-        throws Exception {
-        CtfTmfTrace fixture = initTrace();
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        ITmfDataRequest<CtfTmfEvent> request = new TmfCoalescedEventRequest(ITmfEvent.class);
-
-        ITmfContext result = fixture.armRequest(request);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent>) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testArmRequest_3()
-        throws Exception {
-        CtfTmfTrace fixture = initTrace();
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        ITmfDataRequest<CtfTmfEvent> request = new TmfCoalescedEventRequest(ITmfEvent.class);
-
-        ITmfContext result = fixture.armRequest(request);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent>) method test.
-     *
-     * @throws Exception
-     *
-     * @generatedBy CodePro at 03/05/12 2:29 PM
-     */
-    @Test
-    public void testArmRequest_4()
-        throws Exception {
-        CtfTmfTrace fixture = initTrace();
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        ITmfDataRequest<CtfTmfEvent> request = new TmfCoalescedEventRequest(ITmfEvent.class);
-
-        ITmfContext result = fixture.armRequest(request);
-
-        // add additional test code here
-        // An unexpected exception was thrown in user code while executing this test:
-        //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
-        //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNotNull(result);
-    }
-
-
     /**
      * Run the void broadcast(TmfSignal) method test.
      *
@@ -222,7 +124,7 @@ public class CtfTmfTraceTest {
         // An unexpected exception was thrown in user code while executing this test:
         //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
         //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertEquals(50000, result);
+        assertEquals(1000, result);
     }
 
     /**
@@ -339,7 +241,7 @@ public class CtfTmfTraceTest {
         // An unexpected exception was thrown in user code while executing this test:
         //    org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException: Path must be a valid directory
         //       at org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace.initTrace(CtfTmfTrace.java:98)
-        assertNull(result);
+        assertNotNull(result);
     }
 
     /**
index d139b4b4a049b1d14c53400abb4f373e0fdb66af..a15b4200d8bab29524b4489109c73c0f8f64a4a3 100644 (file)
@@ -109,7 +109,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparab
     public boolean seek(final long timestamp) {
         boolean ret = false;
         final long offsetTimestamp = timestamp
-                - this.getCtfTmfTrace().getCTFTrace().getOffset();
+                - this.getTrace().getOffset();
         if (offsetTimestamp < 0) {
             ret = super.seek(timestamp);
         } else {
@@ -124,23 +124,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparab
         return ret;
     }
 
-    /**
-     * Method seekRank. seeks to a given rank
-     * @param rank long the rank to seek to
-     * @return boolean
-     */
-    public boolean seekRank(final long rank) {
-        boolean ret = false;
-        ret = super.seekIndex(rank);
-
-        if (ret) {
-            curLocation.setLocation(getCurrentEvent().getTimestampValue());
-        } else {
-            curLocation = NULL_LOCATION;
-        }
-        return ret;
-    }
-
     /**
      * Method getRank.
      * @return long
index a0cdd85243807d8619f39573ac5abb67cf9c14f0..4976ea570a3a633064315918e3edbfacdebc24e9 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp.TimestampType;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
@@ -31,7 +30,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 
-public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParser{
+public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParser<CtfTmfEvent>{
 
     //-------------------------------------------
     //        Fields
@@ -279,12 +278,23 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
         return this.fTrace.getEnvironment().get(key);
     }
 
+    //-------------------------------------------
+    //        Clocks
+    //-------------------------------------------
+
+    public long getOffset(){
+        if( fTrace != null ) {
+            return fTrace.getOffset();
+        }
+        return 0;
+    }
+
     //-------------------------------------------
     //        Parser
     //-------------------------------------------
 
     @Override
-    public ITmfEvent parseEvent(ITmfContext context) {
+    public CtfTmfEvent parseEvent(ITmfContext context) {
         CtfTmfEvent event = null;
         if( context instanceof CtfIterator ){
             CtfIterator itt = (CtfIterator) context;
index c8f915aee213a12adf01fa918effd0e6c1882f51..034d465403b81e0db2f98bb197bd1e7e202f5dab 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2011, 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Bernd Hufmann - Changed to updated histogram data model
@@ -97,7 +97,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         // Check if we are outside the time range; if so, just set the current
         // event
         long timestamp = getTimestamp(event.x);
-        if (timestamp < fZoom.getStartTime() || timestamp > fZoom.getEndTime()) {
+        if ((timestamp < fZoom.getStartTime()) || (timestamp > fZoom.getEndTime())) {
             super.mouseDown(event);
             return;
         }
@@ -125,8 +125,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
             int nbBuckets = event.x - fStartPosition;
             long delta = nbBuckets * fScaledData.fBucketDuration;
             long newStart = fZoom.getStartTime() + delta;
-            if (newStart < getStartTime())
+            if (newStart < getStartTime()) {
                 newStart = getStartTime();
+            }
             long newEnd = newStart + fZoom.getDuration();
             if (newEnd > getEndTime()) {
                 newEnd = getEndTime();
@@ -151,7 +152,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
         GC rangeWindowGC = new GC(rangeRectangleImage);
 
-        if (fScaledData != null && fRangeStartTime != 0) {
+        if ((fScaledData != null) && (fRangeStartTime != 0)) {
             drawTimeRangeWindow(rangeWindowGC, rangeRectangleImage);
         }
 
@@ -165,7 +166,7 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
     private void drawTimeRangeWindow(GC imageGC, Image image) {
 
         // Map times to histogram coordinates
-        long bucketSpan = fScaledData.fBucketDuration;
+        long bucketSpan = Math.max(fScaledData.fBucketDuration,1);
         int rangeWidth = (int) (fRangeDuration / bucketSpan);
 
         int left = (int) ((fRangeStartTime - fDataModel.getFirstBucketTime()) / bucketSpan);
@@ -190,9 +191,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         imageGC.setLineWidth(1);
         imageGC.setLineStyle(SWT.LINE_SOLID);
 
-        int chHalfWidth = ((rangeWidth < 60) ? rangeWidth * 2 / 3 : 40) / 2;
+        int chHalfWidth = ((rangeWidth < 60) ? (rangeWidth * 2) / 3 : 40) / 2;
         imageGC.drawLine(center - chHalfWidth, height / 2, center + chHalfWidth, height / 2);
-        imageGC.drawLine(center, height / 2 - chHalfWidth, center, height / 2 + chHalfWidth);
+        imageGC.drawLine(center, (height / 2) - chHalfWidth, center, (height / 2) + chHalfWidth);
     }
 
 }
index a2394a04781c73fc3007b17e0995303799d85df2..c9db53399ae54de9b8711f0b0a2bef9eba81840a 100644 (file)
@@ -1,14 +1,14 @@
 /*******************************************************************************
  * Copyright (c) 2011, 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
- *   Bernd Hufmann - Implementation of new interfaces/listeners and support for 
+ *   Bernd Hufmann - Implementation of new interfaces/listeners and support for
  *                   time stamp in any order
  *   Francois Chouinard - Moved from LTTng to TMF
  *******************************************************************************/
@@ -44,12 +44,12 @@ import org.eclipse.core.runtime.ListenerList;
  * 2<i>d</i>). This compaction happens as needed as the trace is read.
  * <p>
  * The model allows for timestamps in not increasing order. The timestamps can
- * be fed to the model in any order. If an event has a timestamp less than the 
+ * be fed to the model in any order. If an event has a timestamp less than the
  * <i>basetime</i>, the buckets will be moved to the right to account for the
- * new smaller timestamp. The new <i>basetime</i> is a multiple of the bucket 
+ * new smaller timestamp. The new <i>basetime</i> is a multiple of the bucket
  * duration smaller then the previous <i>basetime</i>. Note that the <i>basetime</i>
  * might not be anymore a timestamp of an event. If necessary, the buckets will
- * be compacted before moving to the right. This might be necessary to not 
+ * be compacted before moving to the right. This might be necessary to not
  * loose any event counts at the end of the buckets array.
  * <p>
  * The mapping from the model to the UI is performed by the <i>scaleTo()</i>
@@ -72,7 +72,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     public static final int DEFAULT_NUMBER_OF_BUCKETS = 16 * 1000;
 
     public static final int REFRESH_FREQUENCY = DEFAULT_NUMBER_OF_BUCKETS;
-    
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -90,10 +90,10 @@ public class HistogramDataModel implements IHistogramDataModel {
     private long fLastEventTime;
     private long fCurrentEventTime;
     private long fTimeLimit;
-    
+
     // Private listener lists
     private final ListenerList fModelListeners;
-    
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -112,7 +112,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     public HistogramDataModel(HistogramDataModel other) {
         fNbBuckets = other.fNbBuckets;
         fBuckets = Arrays.copyOf(other.fBuckets, fNbBuckets);
-        fBucketDuration = other.fBucketDuration;
+        fBucketDuration = Math.max(other.fBucketDuration,1);
         fNbEvents = other.fNbEvents;
         fLastBucket = other.fLastBucket;
         fFirstBucketTime = other.fFirstBucketTime;
@@ -142,7 +142,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     public long getBucketDuration() {
         return fBucketDuration;
     }
-    
+
     public long getFirstBucketTime() {
         return fFirstBucketTime;
     }
@@ -150,7 +150,7 @@ public class HistogramDataModel implements IHistogramDataModel {
     public long getStartTime() {
         return fFirstEventTime;
     }
-    
+
     public long getEndTime() {
         return fLastEventTime;
     }
@@ -162,15 +162,15 @@ public class HistogramDataModel implements IHistogramDataModel {
     public long getTimeLimit() {
         return fTimeLimit;
     }
-    
+
     // ------------------------------------------------------------------------
     // Listener handling
     // ------------------------------------------------------------------------
-    
+
     public void addHistogramListener(IHistogramModelListener listener) {
-        fModelListeners.add(listener);        
+        fModelListeners.add(listener);
     }
-    
+
     public void removeHistogramListener(IHistogramModelListener listener) {
         fModelListeners.remove(listener);
     }
@@ -178,17 +178,17 @@ public class HistogramDataModel implements IHistogramDataModel {
     private void fireModelUpdateNotification() {
         fireModelUpdateNotification(0);
     }
-    
+
     private void fireModelUpdateNotification(long count) {
-        if (count % REFRESH_FREQUENCY == 0) {
+        if ((count % REFRESH_FREQUENCY) == 0) {
             Object[] listeners = fModelListeners.getListeners();
-            for (int i = 0; i < listeners.length; i++) {
-                IHistogramModelListener listener = (IHistogramModelListener) listeners[i];
+            for (Object listener2 : listeners) {
+                IHistogramModelListener listener = (IHistogramModelListener) listener2;
                 listener.modelUpdated();
             }
         }
     }
-    
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -216,7 +216,7 @@ public class HistogramDataModel implements IHistogramDataModel {
 
     /**
      * Sets the current event time
-     * 
+     *
      * @param timestamp
      */
     public void setCurrentEvent(long timestamp) {
@@ -225,42 +225,42 @@ public class HistogramDataModel implements IHistogramDataModel {
 
     /**
      * Sets the current event time
-     * 
+     *
      * @param timestamp
      */
     public void setCurrentEventNotifyListeners(long timestamp) {
         fCurrentEventTime = timestamp;
         fireModelUpdateNotification();
     }
-    
+
     /**
      * Add event to the correct bucket, compacting the if needed.
-     * 
+     *
      * @param timestamp the timestamp of the event to count
      */
     @Override
     public void countEvent(long eventCount, long timestamp) {
-        
+
         // Validate
         if (timestamp < 0) {
             return;
         }
-        
+
         // Set the start/end time if not already done
-        if (fLastBucket == 0 && fBuckets[0] == 0 && timestamp > 0) {
+        if ((fLastBucket == 0) && (fBuckets[0] == 0) && (timestamp > 0)) {
             fFirstBucketTime = timestamp;
             fFirstEventTime = timestamp;
             updateEndTime();
         }
-        
+
         if (timestamp < fFirstEventTime) {
             fFirstEventTime = timestamp;
         }
-        
+
         if (fLastEventTime < timestamp) {
             fLastEventTime = timestamp;
         }
-        
+
         if (timestamp >= fFirstBucketTime) {
 
             // Compact as needed
@@ -269,37 +269,38 @@ public class HistogramDataModel implements IHistogramDataModel {
             }
 
         } else {
-            
+
             // get offset for adjustment
             int offset = getOffset(timestamp);
 
             // Compact as needed
-            while(fLastBucket + offset >= fNbBuckets) {
+            while((fLastBucket + offset) >= fNbBuckets) {
                 mergeBuckets();
                 offset = getOffset(timestamp);
             }
-            
+
             moveBuckets(offset);
 
             fLastBucket = fLastBucket + offset;
 
-            fFirstBucketTime = fFirstBucketTime - offset*fBucketDuration;
+            fFirstBucketTime = fFirstBucketTime - (offset*fBucketDuration);
             updateEndTime();
         }
-        
+
         // Increment the right bucket
         int index = (int) ((timestamp - fFirstBucketTime) / fBucketDuration);
         fBuckets[index]++;
         fNbEvents++;
-        if (fLastBucket < index)
+        if (fLastBucket < index) {
             fLastBucket = index;
-        
+        }
+
         fireModelUpdateNotification(eventCount);
     }
 
     /**
      * Scale the model data to the width, height and bar width requested.
-     * 
+     *
      * @param width
      * @param height
      * @param barWidth
@@ -309,29 +310,33 @@ public class HistogramDataModel implements IHistogramDataModel {
     @Override
     public HistogramScaledData scaleTo(int width, int height, int barWidth) {
         // Basic validation
-        if (width <= 0 ||  height <= 0 || barWidth <= 0)
+        if ((width <= 0) ||  (height <= 0) || (barWidth <= 0))
+         {
             throw new AssertionError("Invalid histogram dimensions (" + width + "x" + height + ", barWidth=" + barWidth + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        }
 
         // The result structure
         HistogramScaledData result = new HistogramScaledData(width, height, barWidth);
 
         // Scale horizontally
         result.fMaxValue = 0;
-        
+
         int nbBars = width / barWidth;
-        int bucketsPerBar = fLastBucket / nbBars + 1;
-        result.fBucketDuration = bucketsPerBar * fBucketDuration;
+        int bucketsPerBar = (fLastBucket / nbBars) + 1;
+        result.fBucketDuration = Math.max(bucketsPerBar * fBucketDuration,1);
         for (int i = 0; i < nbBars; i++) {
             int count = 0;
-            for (int j = i * bucketsPerBar; j < (i + 1) * bucketsPerBar; j++) {
-                if (fNbBuckets <= j)
+            for (int j = i * bucketsPerBar; j < ((i + 1) * bucketsPerBar); j++) {
+                if (fNbBuckets <= j) {
                     break;
+                }
                 count += fBuckets[j];
             }
             result.fData[i] = count;
             result.fLastBucket = i;
-            if (result.fMaxValue < count)
+            if (result.fMaxValue < count) {
                 result.fMaxValue = count;
+            }
         }
 
         // Scale vertically
@@ -339,11 +344,13 @@ public class HistogramDataModel implements IHistogramDataModel {
             result.fScalingFactor = (double) height / result.fMaxValue;
         }
 
+        fBucketDuration = Math.max(fBucketDuration, 1);
         // Set the current event index in the scaled histogram
-        if (fCurrentEventTime >= fFirstBucketTime && fCurrentEventTime <= fLastEventTime)
+        if ((fCurrentEventTime >= fFirstBucketTime) && (fCurrentEventTime <= fLastEventTime)) {
             result.fCurrentBucket = (int) ((fCurrentEventTime - fFirstBucketTime) / fBucketDuration) / bucketsPerBar;
-        else
+        } else {
             result.fCurrentBucket = HistogramScaledData.OUT_OF_RANGE_BUCKET;
+        }
 
         result.fFirstBucketTime = fFirstBucketTime;
         result.fFirstEventTime = fFirstEventTime;
@@ -355,22 +362,22 @@ public class HistogramDataModel implements IHistogramDataModel {
     // ------------------------------------------------------------------------
 
     private void updateEndTime() {
-        fTimeLimit = fFirstBucketTime + fNbBuckets * fBucketDuration;
+        fTimeLimit = fFirstBucketTime + (fNbBuckets * fBucketDuration);
     }
 
     private void mergeBuckets() {
-        for (int i = 0; i < fNbBuckets / 2; i++) {
-            fBuckets[i] = fBuckets[2 * i] + fBuckets[2 * i + 1];
+        for (int i = 0; i < (fNbBuckets / 2); i++) {
+            fBuckets[i] = fBuckets[2 * i] + fBuckets[(2 * i) + 1];
         }
         Arrays.fill(fBuckets, fNbBuckets / 2, fNbBuckets, 0);
         fBucketDuration *= 2;
         updateEndTime();
-        fLastBucket = fNbBuckets / 2 - 1;
+        fLastBucket = (fNbBuckets / 2) - 1;
     }
-    
+
     private void moveBuckets(int offset) {
         for(int i = fNbBuckets - 1; i >= offset; i--) {
-            fBuckets[i] = fBuckets[i-offset]; 
+            fBuckets[i] = fBuckets[i-offset];
         }
 
         for (int i = 0; i < offset; i++) {
@@ -380,7 +387,7 @@ public class HistogramDataModel implements IHistogramDataModel {
 
     private int getOffset(long timestamp) {
         int offset = (int) ((fFirstBucketTime - timestamp) / fBucketDuration);
-        if ((fFirstBucketTime - timestamp) % fBucketDuration != 0) {
+        if (((fFirstBucketTime - timestamp) % fBucketDuration) != 0) {
             offset++;
         }
         return offset;
This page took 0.061279 seconds and 5 git commands to generate.