summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMatthew Khouzam2012-03-28 18:16:51 (EDT)
committer Francois Chouinard2012-04-16 14:20:10 (EDT)
commitd2ada18550e299323a68a43746f6b5d23406dcf5 (patch)
tree7882616df7a9d5229fc8074c32cb9852b6fca2df
parent099df0107b394ad0abd9f40e88919052b6f7766d (diff)
downloadorg.eclipse.linuxtools-d2ada18550e299323a68a43746f6b5d23406dcf5.zip
org.eclipse.linuxtools-d2ada18550e299323a68a43746f6b5d23406dcf5.tar.gz
org.eclipse.linuxtools-d2ada18550e299323a68a43746f6b5d23406dcf5.tar.bz2
Add support for seeks by index.
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java16
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java56
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java45
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java14
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java26
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java24
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java43
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java66
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java16
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java140
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java8
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java13
12 files changed, 349 insertions, 118 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
index cf3dbc6..9252497 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
@@ -7,24 +7,24 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
/**
* Here are the definitions common to all the CTF parser tests.
- *
+ *
* @author alexmont
*
*/
public abstract class TestParams {
-
+
/* Path to test traces */
- private static final String testTracePath1 = "Tests/traces/trace20m"; //$NON-NLS-1$
+ private static final String testTracePath1 = "Tests/traces/trace20m1"; //$NON-NLS-1$
private static CTFTrace testTrace1 = null;
private static CTFTrace testTraceFromFile1 = null;
-
+
private static final File emptyFile = new File(""); //$NON-NLS-1$
private static CTFTrace emptyTrace = null;
-
+
public static File getEmptyFile() {
return emptyFile;
}
-
+
public static CTFTrace getEmptyTrace() {
if (emptyTrace == null) {
try {
@@ -32,11 +32,11 @@ public abstract class TestParams {
} catch (CTFReaderException e) {
/* We know this trace should exist */
throw new RuntimeException(e);
- }
+ }
}
return emptyTrace;
}
-
+
public static CTFTrace createTrace() throws CTFReaderException {
if (testTrace1 == null) {
testTrace1 = new CTFTrace(testTracePath1);
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
index bd13a1f..9d28f30 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
@@ -87,11 +87,13 @@ public class ReadTrace {
avg += val;
}
avg /= benchs.size();
- System.out.println("Time to read = " + avg + " events/ns");
+ System.out.println("Time to read " + nbEvent + " events = " + avg
+ + " events/ns");
for (Double val : benchs) {
System.out.print(val);
System.out.print(", ");
}
+ testSeekIndex(trace);
try {
testSeekIndex(trace);
@@ -155,6 +157,58 @@ public class ReadTrace {
}
/**
+ * @return
+ */
+ private static long getTimestamp(CTFTraceReader fixture) {
+ if (fixture.getCurrentEventDef() != null) {
+ return fixture.getCurrentEventDef().timestamp;
+ }
+ 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$
+ );
+ }
+
+ /**
* @param timestamp
* the timestamp in UTC to convert to nanoseconds.
* @return formatted string.
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
index 5c8b928..67ff442 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
@@ -1,5 +1,6 @@
package org.eclipse.linuxtools.ctf.core.tests.trace;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -36,7 +37,7 @@ public class CTFTraceReaderTest {
/**
* Perform pre-test initialization.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
@@ -54,7 +55,7 @@ public class CTFTraceReaderTest {
/**
* Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
* trace.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testOpen_existing() throws CTFReaderException {
@@ -141,7 +142,7 @@ public class CTFTraceReaderTest {
*
* Both trace reader are different objects, so they shouldn't "equals" each
* other.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testEquals() throws CTFReaderException {
@@ -198,7 +199,7 @@ public class CTFTraceReaderTest {
@Test
public void testGoToLastEvent() throws CTFReaderException {
fixture.goToLastEvent();
- long ts1 = fixture.getCurrentEventDef().timestamp;
+ long ts1 = getTimestamp();
long ts2 = fixture.getEndTime();
assertTrue(ts1 == ts2);
}
@@ -279,4 +280,40 @@ public class CTFTraceReaderTest {
boolean result = fixture.seek(timestamp);
assertTrue(result);
}
+
+
+ /**
+ * Run the boolean seek(long) method test.
+ */
+ @Test
+ public void testSeekIndex() {
+ 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();
+ assertTrue(result);
+ assertTrue(result2);
+ assertEquals( first , third);
+ assertEquals( second , fourth);
+ }
+
+ /**
+ * @return
+ */
+ private long getTimestamp() {
+ return fixture.getCurrentEventDef().timestamp;
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
index c661d26..e76e7f1 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
@@ -11,7 +11,7 @@ import org.junit.Test;
/**
* The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
* class <code>{@link StreamInputPacketIndexEntry}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
@@ -21,7 +21,7 @@ public class StreamInputPacketIndexEntryTest {
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@@ -67,11 +67,11 @@ public class StreamInputPacketIndexEntryTest {
"timestampBegin=1, timestampEnd=1, " + //$NON-NLS-1$
"dataOffset=1, packetSize=1, contentSize=1]"; //$NON-NLS-1$
- fixture.contentSizeBits = 1;
- fixture.dataOffsetBits = 1;
- fixture.timestampEnd = 1L;
- fixture.packetSizeBits = 1;
- fixture.timestampBegin = 1L;
+ fixture.setContentSizeBits(1);
+ fixture.setDataOffsetBits(1);
+ fixture.setTimestampEnd(1L);
+ fixture.setPacketSizeBits(1);
+ fixture.setTimestampBegin(1L);
assertEquals(expectedResult, fixture.toString());
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java
index e0e3ad1..c83ae86 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java
@@ -16,7 +16,7 @@ import org.junit.Test;
/**
* The class <code>StreamInputPacketIndexTest</code> contains tests for the
* class <code>{@link StreamInputPacketIndex}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
@@ -27,7 +27,7 @@ public class StreamInputPacketIndexTest {
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@@ -37,7 +37,7 @@ public class StreamInputPacketIndexTest {
/**
* Perform pre-test initialization.
- *
+ *
* @throws CTFReaderException
*/
@Before
@@ -66,40 +66,40 @@ public class StreamInputPacketIndexTest {
/**
* Run the void addEntry(StreamInputPacketIndexEntry) method test, by
* specifying only 1 parameter to the entry.
- *
+ *
* @throws CTFReaderException
*/
@Test
public void testAddEntry_1param() throws CTFReaderException {
- entry.packetSizeBits = 0;
+ entry.setPacketSizeBits(0);
fixture.addEntry(entry);
}
/**
* Run the void addEntry(StreamInputPacketIndexEntry) method test by
* specifying 2 parameters to the entry.
- *
+ *
* @throws CTFReaderException
*/
@Test
public void testAddEntry_2params() throws CTFReaderException {
- entry.packetSizeBits = 1;
- entry.contentSizeBits = 0;
+ entry.setPacketSizeBits(1);
+ entry.setContentSizeBits(0);
fixture.addEntry(entry);
}
/**
* Run the void addEntry(StreamInputPacketIndexEntry) method test, by
* specifying all 4 parameters to the entry.
- *
+ *
* @throws CTFReaderException
*/
@Test
public void testAddEntry_4params() throws CTFReaderException {
- entry.timestampBegin = 1L;
- entry.packetSizeBits = 1;
- entry.contentSizeBits = 1;
- entry.timestampEnd = 1L;
+ entry.setTimestampBegin(1L);
+ entry.setPacketSizeBits(1);
+ entry.setContentSizeBits(1);
+ entry.setTimestampEnd(1L);
fixture.addEntry(entry);
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java
index b113ffe..c075684 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java
@@ -16,12 +16,14 @@ import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* The class <code>StreamInputPacketReaderTest</code> contains tests for the
* class <code>{@link StreamInputPacketReader}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
@@ -31,7 +33,7 @@ public class StreamInputPacketReaderTest {
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@@ -41,8 +43,8 @@ public class StreamInputPacketReaderTest {
/**
* Perform pre-test initialization.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
@@ -64,8 +66,8 @@ public class StreamInputPacketReaderTest {
/**
* Run the StreamInputPacketReader(StreamInputReader) constructor test.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Test
public void testStreamInputPacketReader() throws CTFReaderException {
@@ -143,7 +145,7 @@ public class StreamInputPacketReaderTest {
/**
* Run the EventDefinition readNextEvent() method test.
- *
+ *
* @throws CTFReaderException
*/
@Test
@@ -161,7 +163,7 @@ public class StreamInputPacketReaderTest {
fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
1L);
- currentPacket.packetSizeBits = 1;
+ currentPacket.setPacketSizeBits(1);
fixture.setCurrentPacket(currentPacket);
}
@@ -184,8 +186,8 @@ public class StreamInputPacketReaderTest {
fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
1L);
- currentPacket.timestampBegin = 1L;
- currentPacket.packetSizeBits = 1;
+ currentPacket.setTimestampBegin(1L);
+ currentPacket.setPacketSizeBits(1);
fixture.setCurrentPacket(currentPacket);
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
index 83d289c..2632eea 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
@@ -98,8 +98,7 @@ public class CTFTraceReader {
this.endTime = this.startTime;
this.index = 0;
startIndex = new long[prio.size()];
- for( int i = 0; i < prio.size(); i++ )
- {
+ for (int i = 0; i < prio.size(); i++) {
startIndex[i] = 0;
}
}
@@ -252,8 +251,7 @@ public class CTFTraceReader {
this.endTime = Math.max(topEnd, this.endTime);
this.eventCountPerTraceFile[top.getName()]++;
}
- if(hasMoreEvents())
- {
+ if (hasMoreEvents()) {
/*
* increment the index
*/
@@ -261,11 +259,11 @@ public class CTFTraceReader {
StreamInputPacketReader packetReader = top.getPacketReader();
if (packetReader.hasMoreEvents() == false) {
- int n = this.streamInputReaders.indexOf(packetReader);
+ int n = this.streamInputReaders.indexOf(top);
StreamInputPacketIndexEntry currentPacket = packetReader
.getCurrentPacket();
- currentPacket.indexBegin = startIndex[n];
- currentPacket.indexEnd = index;
+ currentPacket.setIndexBegin(startIndex[n]);
+ currentPacket.setIndexEnd(index);
startIndex[n] = index + 1;
}
}
@@ -325,41 +323,52 @@ public class CTFTraceReader {
*/
}
- for (StreamInputReader streamInputReader : this.streamInputReaders ) {
+ for (StreamInputReader streamInputReader : this.streamInputReaders) {
if (streamInputReader.getCurrentEvent() != null) {
this.prio.add(streamInputReader);
index = Math.max(index, streamInputReader.getPacketReader()
- .getCurrentPacket().indexBegin + offset);
+ .getCurrentPacket().getIndexBegin()
+ + offset);
}
}
return hasMoreEvents();
}
- public boolean seekIndex( long index )
- {
+ public boolean seekIndex(long index) {
this.prio.clear();
- this.index = index;
- long tempIndex = Long.MAX_VALUE;
+
+ long tempIndex = Long.MIN_VALUE;
+ long tempTimestamp = Long.MIN_VALUE;
for (StreamInputReader streamInputReader : this.streamInputReaders) {
/*
* Seek the trace reader.
*/
- tempIndex = Math.min(tempIndex, streamInputReader.seekBeforeIndex(index));
+ final long streamIndex = streamInputReader.seekIndex(index);
+ tempIndex = Math.max(tempIndex, streamIndex);
+ tempTimestamp = Math.max(tempTimestamp, streamInputReader.getCurrentEvent().timestamp);
+ }
+ 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);
}
}
/*
- * advance for offset
+ * advance for offset
*/
- for( long pos = tempIndex; (pos < index) && hasMoreEvents(); pos++){
+ while( (prio.peek().getCurrentEvent().timestamp < tempTimestamp) && hasMoreEvents() )
+ {
this.advance();
}
-
+ long pos = tempIndex;
+ for (pos = tempIndex; (pos < index) && hasMoreEvents(); pos++) {
+ this.advance();
+ }
+ this.index = pos;
return hasMoreEvents();
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
index 236b6ad..878e8ec 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
@@ -171,13 +171,13 @@ public class StreamInput implements IDefinitionScope {
* 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$
+ 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$
+ streamPacketContextDef = getStream().getPacketContextDecl()
+ .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
}
/*
@@ -219,7 +219,8 @@ public class StreamInput implements IDefinitionScope {
/*
* Check the CTF magic number
*/
- IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("magic"); //$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) {
@@ -232,12 +233,14 @@ public class StreamInput implements IDefinitionScope {
/*
* Check the trace UUID
*/
- ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
+ 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);
+ IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
+ .getElem(i);
uuidArray[i] = (byte) uuidByteDef.getValue();
}
@@ -251,7 +254,8 @@ public class StreamInput implements IDefinitionScope {
/*
* Check that the stream id did not change
*/
- IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
+ IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
+ .lookupDefinition("stream_id"); //$NON-NLS-1$
if (streamIDDef != null) {
long streamID = streamIDDef.getValue();
@@ -271,41 +275,51 @@ public class StreamInput implements IDefinitionScope {
/*
* Read the content size in bits
*/
- IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("content_size"); //$NON-NLS-1$
+ IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("content_size"); //$NON-NLS-1$
if (contentSizeDef != null) {
- packetIndex.contentSizeBits = (int) contentSizeDef.getValue();
+ packetIndex.setContentSizeBits((int) contentSizeDef
+ .getValue());
} else {
- packetIndex.contentSizeBits = (int) (fileSizeBytes * 8);
+ packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
}
/*
* Read the packet size in bits
*/
- IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("packet_size"); //$NON-NLS-1$
+ IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("packet_size"); //$NON-NLS-1$
if (packetSizeDef != null) {
- packetIndex.packetSizeBits = (int) packetSizeDef.getValue();
+ packetIndex.setPacketSizeBits((int) packetSizeDef
+ .getValue());
} else {
- if (packetIndex.contentSizeBits != 0) {
- packetIndex.packetSizeBits = packetIndex.contentSizeBits;
+ if (packetIndex.getContentSizeBits() != 0) {
+ packetIndex.setPacketSizeBits(packetIndex
+ .getContentSizeBits());
} else {
- packetIndex.packetSizeBits = (int) (fileSizeBytes * 8);
+ packetIndex
+ .setPacketSizeBits((int) (fileSizeBytes * 8));
}
}
/*
* Read the begin timestamp
*/
- IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_begin"); //$NON-NLS-1$
+ IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
if (timestampBeginDef != null) {
- packetIndex.timestampBegin = timestampBeginDef.getValue();
+ packetIndex.setTimestampBegin( timestampBeginDef.getValue());
}
/*
* Read the end timestamp
*/
- IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef.lookupDefinition("timestamp_end"); //$NON-NLS-1$
+ IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("timestamp_end"); //$NON-NLS-1$
if (timestampEndDef != null) {
- setTimestampEnd(packetIndex.timestampEnd = timestampEndDef.getValue());
+ packetIndex.setTimestampEnd(timestampEndDef
+ .getValue());
+ setTimestampEnd(packetIndex.getTimestampEnd());
}
} else {
/*
@@ -313,16 +327,16 @@ public class StreamInput implements IDefinitionScope {
* size from the file size (assume that there is only one packet
* and no padding)
*/
- packetIndex.contentSizeBits = (int) (fileSizeBytes * 8);
- packetIndex.packetSizeBits = (int) (fileSizeBytes * 8);
+ packetIndex.setContentSizeBits( (int) (fileSizeBytes * 8));
+ packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
}
/* Basic validation */
- if (packetIndex.contentSizeBits > packetIndex.packetSizeBits) {
+ if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
}
- if (packetIndex.packetSizeBits > ((fileSizeBytes - packetIndex.offsetBytes) * 8)) {
+ 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$
}
@@ -330,7 +344,7 @@ public class StreamInput implements IDefinitionScope {
/*
* Offset in the file, in bits
*/
- packetIndex.dataOffsetBits = bitBuffer.position();
+ packetIndex.setDataOffsetBits( bitBuffer.position());
/*
* Add the packet index entry to the index
@@ -340,7 +354,7 @@ public class StreamInput implements IDefinitionScope {
/*
* Update the counting packet offset
*/
- packetOffsetBytes += (packetIndex.packetSizeBits + 7) / 8;
+ packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
}
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java
index ed044ea..84c4bcc 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java
@@ -61,16 +61,16 @@ public class StreamInputPacketIndex {
*/
public void addEntry(StreamInputPacketIndexEntry entry)
throws CTFReaderException {
- assert (entry.packetSizeBits != 0);
- assert (entry.contentSizeBits != 0);
+ assert (entry.getContentSizeBits() != 0);
+ assert (entry.getContentSizeBits() != 0);
- if (entry.timestampBegin > entry.timestampEnd) {
+ if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
throw new CTFReaderException(
"Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
}
if (!this.entries.isEmpty()) {
- if (entry.timestampBegin < this.entries.lastElement().timestampBegin) {
+ if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
throw new CTFReaderException(
"Packets begin timestamp decreasing"); //$NON-NLS-1$
}
@@ -121,13 +121,13 @@ public class StreamInputPacketIndex {
break;
}
- if (timestamp < guessEntry.timestampBegin) {
+ if (timestamp < guessEntry.getTimestampBegin()) {
/*
* If the timestamp if before the begin timestamp, we know that
* the packet to return is before the guess.
*/
max = guessI - 1;
- } else if (timestamp >= guessEntry.timestampBegin) {
+ } else if (timestamp >= guessEntry.getTimestampBegin()) {
/*
* If the timestamp is after the begin timestamp, we know that
* the packet to return is after the guess or is the guess.
@@ -180,13 +180,13 @@ public class StreamInputPacketIndex {
break;
}
- if (index < guessEntry.indexBegin) {
+ 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.indexBegin) {
+ } 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.
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java
index e94b212..12672a7 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndexEntry.java
@@ -23,40 +23,42 @@ public class StreamInputPacketIndexEntry {
// Attributes
// ------------------------------------------------------------------------
+
+
/**
* Offset of the packet in the file, in bytes
*/
- public long offsetBytes;
+ final private long offsetBytes;
/**
* Offset of the data in the packet, in bits
*/
- public int dataOffsetBits = 0;
+ private int dataOffsetBits = 0;
/**
* Packet size, in bits
*/
- public int packetSizeBits = 0;
+ private int packetSizeBits = 0;
/**
* Content size, in bits
*/
- public int contentSizeBits = 0;
+ private int contentSizeBits = 0;
/**
* Begin timestamp
*/
- public long timestampBegin = 0;
+ private long timestampBegin = 0;
/**
* End timestamp
*/
- public long timestampEnd = 0;
+ private long timestampEnd = 0;
- public long indexBegin = 0;
+ private long indexBegin = -1;
- public long indexEnd = 0;
+ private long indexEnd = -1;
// ------------------------------------------------------------------------
// Constructors
@@ -92,15 +94,123 @@ public class StreamInputPacketIndexEntry {
boolean includesIndex(long index){
return (index >= indexBegin) && (index <= indexEnd);
}
-
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
- /* Only for debugging, shouldn't be externalized */
- return "PacketIndexEntry [offset=" + offsetBytes + ", timestampBegin=" //$NON-NLS-1$ //$NON-NLS-2$
- + Long.toHexString(timestampBegin) + ',' + " timestampEnd=" //$NON-NLS-1$
- + Long.toHexString(timestampEnd) + ", dataOffset=" //$NON-NLS-1$
- + dataOffsetBits + ", packetSize=" + packetSizeBits //$NON-NLS-1$
- + ", contentSize=" + contentSizeBits + ']'; //$NON-NLS-1$
+ 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$
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters and Setters
+ // ------------------------------------------------------------------------
+
+ /**
+ * @return the offsetBytes
+ */
+ public long getOffsetBytes() {
+ return offsetBytes;
+ }
+
+ /**
+ * @return the dataOffsetBits
+ */
+ public int getDataOffsetBits() {
+ return dataOffsetBits;
+ }
+
+ /**
+ * @param dataOffsetBits the dataOffsetBits to set
+ */
+ public void setDataOffsetBits(int dataOffsetBits) {
+ this.dataOffsetBits = dataOffsetBits;
+ }
+
+ /**
+ * @return the packetSizeBits
+ */
+ public int getPacketSizeBits() {
+ return packetSizeBits;
+ }
+
+ /**
+ * @param packetSizeBits the packetSizeBits to set
+ */
+ public void setPacketSizeBits(int packetSizeBits) {
+ this.packetSizeBits = packetSizeBits;
+ }
+
+ /**
+ * @return the contentSizeBits
+ */
+ public int getContentSizeBits() {
+ return contentSizeBits;
+ }
+
+ /**
+ * @param contentSizeBits the contentSizeBits to set
+ */
+ public void setContentSizeBits(int contentSizeBits) {
+ this.contentSizeBits = contentSizeBits;
}
+ /**
+ * @return the timestampBegin
+ */
+ public long getTimestampBegin() {
+ return timestampBegin;
+ }
+
+ /**
+ * @param timestampBegin the timestampBegin to set
+ */
+ public void setTimestampBegin(long timestampBegin) {
+ this.timestampBegin = timestampBegin;
+ }
+
+ /**
+ * @return the timestampEnd
+ */
+ public long getTimestampEnd() {
+ return timestampEnd;
+ }
+
+ /**
+ * @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;
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
index 210b482..cc9f556 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
@@ -224,8 +224,8 @@ public class StreamInputPacketReader implements IDefinitionScope {
MappedByteBuffer bb = null;
try {
bb = getStreamInputReader().getStreamInput().getFileChannel().map(
- MapMode.READ_ONLY, this.currentPacket.offsetBytes,
- (this.currentPacket.packetSizeBits + 7) / 8);
+ MapMode.READ_ONLY, this.currentPacket.getOffsetBytes(),
+ (this.currentPacket.getPacketSizeBits() + 7) / 8);
} catch (IOException e) {
/*
* The streamInputReader object is already allocated, so this
@@ -258,7 +258,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
* Use the timestamp begin of the packet as the reference for the
* timestamp reconstitution.
*/
- lastTimestamp = currentPacket.timestampBegin;
+ lastTimestamp = currentPacket.getTimestampBegin();
} else {
getBitBuffer().setByteBuffer(null);
@@ -273,7 +273,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
*/
public boolean hasMoreEvents() {
if (currentPacket != null) {
- return getBitBuffer().position() < currentPacket.contentSizeBits;
+ return getBitBuffer().position() < currentPacket.getContentSizeBits();
}
return false;
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
index a2592d3..46e2fd1 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
@@ -142,7 +142,8 @@ public class StreamInputReader {
*/
private void goToNextPacket() {
if (getPacketIndexIt().hasNext()) {
- this.packetReader.setCurrentPacket(getPacketIndexIt().next());
+ StreamInputPacketIndexEntry nextPacket = getPacketIndexIt().next();
+ this.packetReader.setCurrentPacket(nextPacket);
} else {
this.packetReader.setCurrentPacket(null);
}
@@ -183,7 +184,7 @@ public class StreamInputReader {
}
- public long seekBeforeIndex(long index)
+ public long seekIndex(long index)
{
/*
* Search in the index for the packet to search in.
@@ -194,9 +195,13 @@ public class StreamInputReader {
*/
goToNextPacket();
/*
+ * Read the first packet
+ */
+ readNextEvent();
+ /*
* get the current index
*/
- return this.packetReader.getCurrentPacket().indexBegin;
+ return this.packetReader.getCurrentPacket().getIndexBegin();
}
@@ -206,7 +211,7 @@ public class StreamInputReader {
*/
int len = this.streamInput.getIndex().getEntries().size();
StreamInputPacketIndexEntry entry = this.streamInput.getIndex().getEntries().get(len-1);
- seek(entry.timestampEnd - 1 );
+ seek(entry.getTimestampEnd() - 1 );
/*
* Go until the end of that packet
*/