if (USE_TEXT) {
System.out.println("Event, " + " Time, " + " type, " + " CPU ");
}
- if (trace != null) {
- CTFTraceReader traceReader = new CTFTraceReader(trace);
+ try {
+ if (trace != null) {
+ CTFTraceReader traceReader = new CTFTraceReader(trace);
- start = System.nanoTime();
+ start = System.nanoTime();
- while (traceReader.hasMoreEvents()) {
- EventDefinition ed = traceReader.getCurrentEventDef();
- nbEvent++;
- if (USE_TEXT) {
- String output = formatDate(ed.getTimestamp()
- + trace.getOffset());
- System.out.println(nbEvent + ", "
- + output + ", " + ed.getDeclaration().getName()
- + ", " + ed.getCPU() + ed.getFields().toString()) ;
+ while (traceReader.hasMoreEvents()) {
+ EventDefinition ed = traceReader.getCurrentEventDef();
+ nbEvent++;
+ if (USE_TEXT) {
+ String output = formatDate(ed.getTimestamp()
+ + trace.getOffset());
+ System.out.println(nbEvent + ", "
+ + output + ", " + ed.getDeclaration().getName()
+ + ", " + ed.getCPU() + ed.getFields().toString());
+ }
+ // long endTime = traceReader.getEndTime();
+ // long timestamp =
+ // traceReader.getCurrentEventDef().getTimestamp();
+ traceReader.advance();
}
- // long endTime = traceReader.getEndTime();
- // long timestamp = traceReader.getCurrentEventDef().getTimestamp();
- traceReader.advance();
+ // Map<Long, Stream> streams =
+ // traceReader.getTrace().getStreams();
}
- // Map<Long, Stream> streams = traceReader.getTrace().getStreams();
- }
- stop = System.nanoTime();
+ stop = System.nanoTime();
- System.out.print('.');
- double time = (stop - start) / (double) nbEvent;
- benchs.add(time);
+ System.out.print('.');
+ double time = (stop - start) / (double) nbEvent;
+ benchs.add(time);
+ } catch (CTFReaderException e) {
+ System.out.println("error");
+ }
}
System.out.println("");
double avg = 0;
import java.nio.ByteOrder;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
*/
@Before
public void setUp() {
- fixture = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+ fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
createBuffer(fixture);
}
/**
* Run the int getInt() method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_base() {
+ public void testGetInt_base() throws CTFReaderException {
int result = fixture.getInt();
assertEquals(0x020406, result);
}
/**
* Run the int getInt(int) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_pos0() {
+ public void testGetInt_pos0() throws CTFReaderException {
fixture.position(0);
int result = fixture.getInt();
assertEquals(0x010203, result);
/**
* Run the int getInt(int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_pos1() {
+ public void testGetInt_pos1() throws CTFReaderException {
fixture.position(1);
int length = 1;
boolean signed = true;
/**
* Run the int getInt(int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_pos2() {
+ public void testGetInt_pos2() throws CTFReaderException {
fixture.position(2);
int length = 0;
boolean signed = true;
/**
* Run the int getInt(int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_signed() {
+ public void testGetInt_signed() throws CTFReaderException {
fixture.position(1);
int length = 0;
boolean signed = true;
/**
* Run the int getInt(int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_signed_length1() {
+ public void testGetInt_signed_length1() throws CTFReaderException {
fixture.position(1);
int length = 1;
boolean signed = true;
/**
* Run the int getInt(int,int,boolean) method test with a little-endian
* BitBuffer.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_le1() {
- BitBuffer le_fixture = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(128));
+ public void testGetInt_le1() throws CTFReaderException {
+ BitBuffer le_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
createBuffer(le_fixture);
le_fixture.position(1);
/**
* Run the int getInt(int,int,boolean) method test with a little-endian
* BitBuffer.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testGetInt_le2() {
- BitBuffer le_fixture = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(128));
+ public void testGetInt_le2() throws CTFReaderException {
+ BitBuffer le_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
createBuffer(le_fixture);
le_fixture.position(0);
/**
* Run the int getInt(int,boolean) method test and expect an overflow.
+ *
+ * @throws CTFReaderException
+ * Expected
*/
- @Test(expected = java.nio.BufferOverflowException.class)
- public void testGetInt_invalid() {
- BitBuffer small_fixture = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(128));
+ @Test(expected = CTFReaderException.class)
+ public void testGetInt_invalid() throws CTFReaderException {
+ BitBuffer small_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
createBuffer(small_fixture, 2);
small_fixture.position(10);
/**
* Run the int getInt(int,int,boolean) method test and expect an overflow.
+ *
+ * @throws CTFReaderException
+ * Expected
*/
- @Test(expected = java.nio.BufferOverflowException.class)
- public void testGetInt_invalid2() {
- BitBuffer small_fixture = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(128));
+ @Test(expected = CTFReaderException.class)
+ public void testGetInt_invalid2() throws CTFReaderException {
+ BitBuffer small_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
createBuffer(small_fixture, 2);
small_fixture.position(1);
/**
* Run the void putInt(int) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testPutInt() {
+ public void testPutInt() throws CTFReaderException {
int value = 1;
fixture.position(1);
fixture.putInt(value);
/**
* Run the void putInt(int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testPutInt_signed() {
+ public void testPutInt_signed() throws CTFReaderException {
int length = 1;
int value = 1;
/**
* Run the void putInt(int,int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testPutInt_length0() {
+ public void testPutInt_length0() throws CTFReaderException {
int length = 0;
int value = 1;
/**
* Run the void putInt(int,int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testPutInt_length1() {
+ public void testPutInt_length1() throws CTFReaderException {
int length = 1;
int value = 1;
/**
* Run the void putInt(int) method test.
+ *
+ * @throws CTFReaderException
+ * Not expected
*/
@Test
- public void testPutInt_hex() {
+ public void testPutInt_hex() throws CTFReaderException {
final int value = 0x010203;
int read;
/**
* Run the void putInt(int,int,int,boolean) method test.
+ *
+ * @throws CTFReaderException
+ * Expected
*/
- @Test(expected = java.nio.BufferOverflowException.class)
- public void testPutInt_invalid() {
+ @Test(expected = CTFReaderException.class)
+ public void testPutInt_invalid() throws CTFReaderException {
BitBuffer fixture2;
- fixture2 = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+ fixture2 = new BitBuffer(ByteBuffer.allocateDirect(128));
fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
createBuffer(fixture2, 4);
fixture2.position(1);
/**
* Run the boolean advance() method test. Test advancing normally.
+ * @throws CTFReaderException error
*/
@Test
- public void testAdvance_normal() {
+ public void testAdvance_normal() throws CTFReaderException {
boolean result = fixture.advance();
assertTrue(result);
}
/**
* 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 error
*/
@Test
- public void testAdvance_end() {
+ public void testAdvance_end() throws CTFReaderException {
int i = 0;
boolean result = fixture.advance();
while (result) {
/**
* Run the CTFTraceReader copy constructor test.
+ * @throws CTFReaderException error
*/
@Test
- public void testCopyFrom() {
+ public void testCopyFrom() throws CTFReaderException {
CTFTraceReader result = fixture.copyFrom();
assertNotNull(result);
}
/**
* Run the getCurrentEventDef() method test. Get the last event's
* definition.
+ * @throws CTFReaderException error
*/
@Test
- public void testGetCurrentEventDef_last() {
+ public void testGetCurrentEventDef_last() throws CTFReaderException {
fixture.goToLastEvent();
EventDefinition result = fixture.getCurrentEventDef();
assertNotNull(result);
/**
* Run the void goToLastEvent() method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testGoToLastEvent() {
+ public void testGoToLastEvent() throws CTFReaderException {
fixture.goToLastEvent();
long ts1 = getTimestamp();
long ts2 = fixture.getEndTime();
/**
* Run the void printStats() method test with no 'width' parameter.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_noparam() {
+ public void testPrintStats_noparam() throws CTFReaderException {
fixture.advance();
fixture.printStats();
}
/**
* Run the void printStats(int) method test with width = 0.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_width0() {
+ public void testPrintStats_width0() throws CTFReaderException {
fixture.advance();
fixture.printStats(0);
}
/**
* Run the void printStats(int) method test with width = 1.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_width1() {
+ public void testPrintStats_width1() throws CTFReaderException {
fixture.advance();
fixture.printStats(1);
}
/**
* Run the void printStats(int) method test with width = 2.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_width2() {
+ public void testPrintStats_width2() throws CTFReaderException {
fixture.advance();
fixture.printStats(2);
}
/**
* Run the void printStats(int) method test with width = 10.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_width10() {
+ public void testPrintStats_width10() throws CTFReaderException {
fixture.advance();
fixture.printStats(10);
}
/**
* Run the void printStats(int) method test with width = 100.
+ * @throws CTFReaderException error
*/
@Test
- public void testPrintStats_100() {
+ public void testPrintStats_100() throws CTFReaderException {
for (int i = 0; i < 1000; i++) {
fixture.advance();
}
/**
* Run the boolean seek(long) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testSeek() {
+ public void testSeek() throws CTFReaderException {
long timestamp = 1L;
boolean result = fixture.seek(timestamp);
assertTrue(result);
/**
* Run the void goToLastEvent() method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testGoToLastEvent1() {
+ public void testGoToLastEvent1() throws CTFReaderException {
final long endTimestamp = goToEnd();
final long endTime = 4287422460315L;
assertEquals(endTime , endTimestamp );
/**
* Run the void goToLastEvent() method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testGoToLastEvent2() {
+ public void testGoToLastEvent2() throws CTFReaderException {
long timestamp = -1;
while(fixture.readNextEvent()) {
timestamp = fixture.getCurrentEvent().getTimestamp();
assertEquals(0 , timestamp- endTimestamp );
}
- private long goToEnd() {
+ private long goToEnd() throws CTFReaderException {
fixture.goToLastEvent();
return fixture.getCurrentEvent().getTimestamp();
}
/**
* Run the boolean readNextEvent() method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testReadNextEvent() {
+ public void testReadNextEvent() throws CTFReaderException {
boolean result = fixture.readNextEvent();
assertTrue(result);
}
/**
* Run the void seek(long) method test. Seek by direct timestamp
+ * @throws CTFReaderException error
*/
@Test
- public void testSeek_timestamp() {
+ public void testSeek_timestamp() throws CTFReaderException {
long timestamp = 1L;
fixture.seek(timestamp);
}
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.junit.Before;
import org.junit.Test;
}
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead_noDefs() {
+ public void testRead_noDefs() throws CTFReaderException {
BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
charArrayFixture.read(input);
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead_withDefs() {
+ public void testRead_withDefs() throws CTFReaderException {
charArrayFixture.setDefinitions(new Definition[] {});
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead() {
+ public void testRead() throws CTFReaderException {
fixture.setIntegerValue(1L);
BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
}
@Test
- public void testFloat64Bit(){
+ public void testFloat64Bit() throws CTFReaderException{
for(int i = 1; i < 63 ; i++) {
parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), 0);
fixture = parent.createDefinition(null, fieldName);
}
@Test
- public void testFloat48Bit(){
+ public void testFloat48Bit() throws CTFReaderException{
parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), 0);
fixture = parent.createDefinition(null, fieldName);
assertNotNull(fixture);
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead() {
+ public void testRead() throws CTFReaderException {
singleFixture.setValue(2.0);
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
singleFixture.read(input);
import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead() {
+ public void testRead() throws CTFReaderException {
fixture.setValue(1L);
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
* Contributors:
* Geneviève Bastien - Initial API and implementation
* Alexandre Montplaisir - Split out in separate class
+ * Matthew Khouzam - update api (exceptions)
*******************************************************************************/
package org.eclipse.linuxtools.ctf.core.tests.types;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
input = new BitBuffer(bb);
}
- /** Read 32-bits BE */
+ /**
+ * Read 32-bits BE
+ *
+ * @throws CTFReaderException
+ * error
+ */
@Test
- public void test32BE() {
+ public void test32BE() throws CTFReaderException {
IntegerDeclaration be = new IntegerDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
IntegerDefinition fixture_be = be.createDefinition(null, name);
fixture_be.read(input);
assertEquals(0xabcdef12, fixture_be.getValue());
}
- /** Read 64-bits BE */
+ /**
+ * Read 64-bits BE
+ *
+ * @throws CTFReaderException
+ * error
+ */
@Test
- public void test64BE() {
+ public void test64BE() throws CTFReaderException {
IntegerDeclaration be = new IntegerDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
IntegerDefinition fixture_be = be.createDefinition(null, name);
fixture_be.read(input);
assertEquals(0xabcdef123456789aL, fixture_be.getValue());
}
- /** Read 32-bits LE */
+ /**
+ * Read 32-bits LE
+ *
+ * @throws CTFReaderException
+ * error
+ */
@Test
- public void test32LE() {
+ public void test32LE() throws CTFReaderException {
IntegerDeclaration le = new IntegerDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
IntegerDefinition fixture_le = le.createDefinition(null, name);
fixture_le.read(input);
assertEquals(0x12efcdab, fixture_le.getValue());
}
- /** Read 64-bits LE */
+ /**
+ * Read 64-bits LE
+ *
+ * @throws CTFReaderException
+ * error
+ */
@Test
- public void test64LE() {
+ public void test64LE() throws CTFReaderException {
IntegerDeclaration le = new IntegerDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
IntegerDefinition fixture_le = le.createDefinition(null, name);
fixture_le.read(input);
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead() {
+ public void testRead() throws CTFReaderException {
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
fixture.read(input);
}
import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead() {
+ public void testRead() throws CTFReaderException {
fixture.setString(new StringBuilder());
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
fixture.read(input);
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the void read(BitBuffer) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testRead_() {
+ public void testRead_() throws CTFReaderException {
ByteBuffer bb = ByteBuffer.allocateDirect(128);
bb.put((byte) 20);
BitBuffer input = new BitBuffer(bb);
package org.eclipse.linuxtools.ctf.core.event.io;
-import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* <b><u>BitBuffer</u></b>
* <p>
* byte order.
*
* @return The int value read from the buffer
+ * @throws CTFReaderException
+ * An error occurred reading the data. When the buffer is read
+ * beyond its end, this exception will be raised.
*/
- public int getInt() {
+ public int getInt() throws CTFReaderException {
return getInt(BIT_INT, true);
}
* @param signed
* The sign extended flag
* @return The int value read from the buffer
+ * @throws CTFReaderException
+ * An error occurred reading the data. When the buffer is read
+ * beyond its end, this exception will be raised.
*/
- public int getInt(int length, boolean signed) {
+ public int getInt(int length, boolean signed) throws CTFReaderException {
/* Nothing to read. */
if (length == 0) {
/* Validate that the buffer has enough bits. */
if (!canRead(length)) {
- throw new BufferOverflowException();
+ throw new CTFReaderException("Cannot read the integer, " + //$NON-NLS-1$
+ "the buffer does not have enough remaining space. " + //$NON-NLS-1$
+ "Requested:" + length); //$NON-NLS-1$
}
/* Get the value from the byte buffer. */
*
* @param value
* The int value to write
+ * @throws CTFReaderException
+ * An error occurred writing the data. If the buffer is written
+ * beyond its end, this exception will be raised.
*/
- public void putInt(int value) {
+ public void putInt(int value) throws CTFReaderException {
putInt(BIT_INT, value);
}
* The number of bits to write
* @param value
* The value to write
+ * @throws CTFReaderException
+ * An error occurred writing the data. If the buffer is written
+ * beyond its end, this exception will be raised.
*/
- public void putInt(int length, int value) {
+ public void putInt(int length, int value) throws CTFReaderException {
final long curPos = this.pos;
if (!canRead(length)) {
- throw new BufferOverflowException();
+ throw new CTFReaderException("Cannot write to bitbuffer, " //$NON-NLS-1$
+ + "insufficient space. Requested: " + length); //$NON-NLS-1$
}
if (length == 0) {
return;
import java.util.Arrays;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF array definition
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
for (Definition definition : definitions) {
definition.read(input);
}
package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF definition
*
* @param input
* the bitbuffer containing the data to read.
+ * @throws CTFReaderException
+ * An error occurred reading the data. If the buffer is reading
+ * beyond its end, this exception will be raised.
* @since 2.0
*/
- public abstract void read(BitBuffer input);
+ public abstract void read(BitBuffer input) throws CTFReaderException;
/**
* Offset the buffer position wrt the current alignment.
return;
}
pos = (pos + mask) & ~mask;
-
input.position(pos);
}
package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF enum definition.
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
alignRead(input, this.declaration);
integerValue.read(input);
long val = integerValue.getValue();
package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF float definition.
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
/* Offset the buffer position wrt the current alignment */
alignRead(input, this.declaration);
final int exp = declaration.getExponent();
}
private static double readRawFloat64(BitBuffer input, final int manBits,
- final int expBits) {
+ final int expBits) throws CTFReaderException {
long low = input.getInt(32, false);
low = low & 0x00000000FFFFFFFFL;
long high = input.getInt(32, false);
}
private static double readRawFloat32(BitBuffer input, final int manBits,
- final int expBits) {
+ final int expBits) throws CTFReaderException {
long temp = input.getInt(32, false);
return createFloat(temp, manBits - 1, expBits);
}
import java.nio.ByteOrder;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF integer definition.
}
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
final long longNegBit = 0x0000000080000000L;
/* Offset the buffer position wrt the current alignment */
alignRead(input, this.declaration);
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
currentLength = (int) lengthDefinition.getValue();
if ((definitions == null) || (definitions.length < currentLength)) {
package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF string definition (similar to a C null-terminated byte array).
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
/* Offset the buffer position wrt the current alignment */
alignRead(input, this.declaration);
string.setLength(0);
import java.util.Map;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF structure definition (similar to a C structure).
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
alignRead(input, this.declaration);
final List<String> fieldList = declaration.getFieldsList();
for (String fName : fieldList) {
import java.util.Map;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF variant definition (similar to a C union).
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
currentField = tagDefinition.getValue();
Definition field = definitions.get(currentField);
*
* @param trace
* The trace to read from.
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public CTFTraceReader(CTFTrace trace) {
+ public CTFTraceReader(CTFTrace trace) throws CTFReaderException {
this.trace = trace;
streamInputReaders.clear();
* Copy constructor
*
* @return The new CTFTraceReader
+ * @throws CTFReaderException if an error occurs
*/
- public CTFTraceReader copyFrom() {
+ public CTFTraceReader copyFrom() throws CTFReaderException {
CTFTraceReader newReader = null;
newReader = new CTFTraceReader(this.trace);
/**
* Dispose the CTFTraceReader
+ *
* @since 2.0
*/
public void dispose() {
return prio;
}
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/**
* Creates one trace file reader per trace file contained in the trace.
+ *
+ * @throws CTFReaderException
+ * if an error occurs
*/
- private void createStreamInputReaders() {
+ private void createStreamInputReaders() throws CTFReaderException {
Collection<Stream> streams = this.trace.getStreams().values();
/*
/**
* Initializes the priority queue used to choose the trace file with the
* lower next event timestamp.
+ *
+ * @throws CTFReaderException
+ * if an error occurs
*/
- private void populateStreamInputReaderHeap() {
+ private void populateStreamInputReaderHeap() throws CTFReaderException {
if (this.streamInputReaders.isEmpty()) {
this.prio = new PriorityQueue<StreamInputReader>();
return;
* Go to the next event.
*
* @return True if an event was read.
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public boolean advance() {
+ public boolean advance() throws CTFReaderException {
/*
* Remove the reader from the top of the priority queue.
*/
/**
* Go to the last event in the trace.
+ *
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public void goToLastEvent() {
+ public void goToLastEvent() throws CTFReaderException {
seek(this.getEndTime());
while (this.prio.size() > 1) {
this.advance();
* the timestamp to seek to
* @return true if there are events above or equal the seek timestamp,
* false if seek at the end of the trace (no valid event).
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public boolean seek(long timestamp) {
+ public boolean seek(long timestamp) throws CTFReaderException {
/*
* Remove all the trace readers from the priority queue
*/
private void parsePacketContext(long fileSizeBytes,
StructDefinition streamPacketContextDef, BitBuffer bitBuffer,
- StreamInputPacketIndexEntry packetIndex) {
+ StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
streamPacketContextDef.read(bitBuffer);
for (String field : streamPacketContextDef.getDeclaration()
*
* @param currentPacket
* The index entry of the packet to switch to.
+ * @throws CTFReaderException
+ * If we get an error reading the packet
*/
- void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) {
+ void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) throws CTFReaderException {
StreamInputPacketIndexEntry prevPacket = null;
this.currentPacket = currentPacket;
private CTFTraceReader parent;
/** Map of all the event types */
- private final Map<Long, EventDefinition> eventDefs = new HashMap<Long,EventDefinition>();
+ private final Map<Long, EventDefinition> eventDefs = new HashMap<Long, EventDefinition>();
// ------------------------------------------------------------------------
// Constructors
*
* @param streamInput
* The StreamInput to read.
+ * @throws CTFReaderException
+ * if an error occurs
* @since 2.0
*/
- public StreamInputReader(StreamInput streamInput) {
+ public StreamInputReader(StreamInput streamInput) throws CTFReaderException {
this.streamInput = streamInput;
this.packetReader = new StreamInputPacketReader(this);
/*
/**
* Dispose the StreamInputReader
+ *
* @since 2.0
*/
public void dispose() {
/**
* Gets the filename of the stream being read
+ *
* @return The filename of the stream being read
*/
public String getFilename() {
* Reads the next event in the current event variable.
*
* @return If an event has been successfully read.
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public boolean readNextEvent() {
+ public boolean readNextEvent() throws CTFReaderException {
/*
* Change packet if needed
/**
* Change the current packet of the packet reader to the next one.
+ *
+ * @throws CTFReaderException
+ * if an error occurs
*/
- private void goToNextPacket() {
+ private void goToNextPacket() throws CTFReaderException {
packetIndex++;
if (getPacketSize() >= (packetIndex + 1)) {
this.packetReader.setCurrentPacket(getPacket());
* @param timestamp
* The timestamp to seek to.
* @return The offset compared to the current position
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public long seek(long timestamp) {
+ public long seek(long timestamp) throws CTFReaderException {
long offset = 0;
gotoPacket(timestamp);
/**
* @param timestamp
+ * @throws CTFReaderException
+ * if an error occurs
*/
- private void gotoPacket(long timestamp) {
+ private void gotoPacket(long timestamp) throws CTFReaderException {
this.packetIndex = this.streamInput.getIndex().search(timestamp)
.previousIndex();
/*
/**
* Seeks the last event of a stream and returns it.
+ *
+ * @throws CTFReaderException
+ * if an error occurs
*/
- public void goToLastEvent() {
+ public void goToLastEvent() throws CTFReaderException {
/*
* Search in the index for the packet to search in.
*/
/**
* Sets the current event in a stream input reader
- * @param currentEvent the event to set
+ *
+ * @param currentEvent
+ * the event to set
*/
public void setCurrentEvent(EventDefinition currentEvent) {
this.currentEvent = currentEvent;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
/**
* Perform pre-test initialization.
+ * @throws CTFReaderException error
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
assumeTrue(testTrace.exists());
trace = testTrace.getTrace();
iterator = new CtfIterator(trace);
/**
* Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
+ * @throws CTFReaderException error
*/
@Test
- public void testCtfIterator_noinit() {
+ public void testCtfIterator_noinit() throws CTFReaderException {
CtfIterator result = new CtfIterator(trace);
assertNotNull(result);
}
/**
* Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
+ * @throws CTFReaderException error
*/
@Test
- public void testCtfIterator_init() {
+ public void testCtfIterator_init() throws CTFReaderException {
trace.init("test");
CtfIterator result = new CtfIterator(trace);
/**
* Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
* specifies an initial position for the iterator.
+ * @throws CTFReaderException error
*/
@Test
- public void testCtfIterator_position() {
+ public void testCtfIterator_position() throws CTFReaderException {
long timestampValue = 1L;
long rank = 1L;
CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);
/**
* Run the int compareTo(CtfIterator) method test.
+ * @throws CTFReaderException error
*/
@Test
- public void testCompareTo() {
+ public void testCompareTo() throws CTFReaderException {
CtfIterator o = new CtfIterator(trace);
int result = iterator.compareTo(o);
/**
* Run the boolean equals(Object) method test. Compare with another iterator
* on the same trace.
+ * @throws CTFReaderException error
*/
@Test
- public void testEquals_other() {
+ public void testEquals_other() throws CTFReaderException {
CtfIterator obj = new CtfIterator(trace);
CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
obj.setLocation(ctfLocation1);
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField;
import org.junit.Before;
import org.junit.Test;
/**
* Perform pre-test initialization.
+ * @throws CTFReaderException error
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
StructDeclaration sDec = new StructDeclaration(1l);
StringDeclaration strDec = new StringDeclaration();
IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8,
import java.util.Set;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
/**
* Perform pre-test initialization.
+ * @throws CTFReaderException error
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
assumeTrue(testTrace.exists());
CtfTmfTrace trace = testTrace.getTrace();
CtfIterator tr = new CtfIterator(trace);
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
/**
* The CTF trace reader iterator.
*
- * It doesn't reserve a file handle, so many iterators can be used without worries
- * of I/O errors or resource exhaustion.
+ * It doesn't reserve a file handle, so many iterators can be used without
+ * worries of I/O errors or resource exhaustion.
*
* @version 1.0
* @author Matthew Khouzam
/**
* An invalid location
*/
- final public static CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
+ public static final CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
private CtfLocation curLocation;
private long curRank;
*
* @param trace
* the trace to iterate over
+ * @throws CTFReaderException
+ * error
*/
- public CtfIterator(final CtfTmfTrace trace) {
+ public CtfIterator(final CtfTmfTrace trace) throws CTFReaderException {
super(trace.getCTFTrace());
this.ctfTmfTrace = trace;
if (this.hasMoreEvents()) {
* long the timestamp in ns of the trace for positioning
* @param rank
* long the index of the trace for positioning
+ * @throws CTFReaderException
+ * error
* @since 2.0
*/
public CtfIterator(final CtfTmfTrace trace,
- final CtfLocationInfo ctfLocationData, final long rank) {
+ final CtfLocationInfo ctfLocationData, final long rank) throws CTFReaderException {
super(trace.getCTFTrace());
this.ctfTmfTrace = trace;
/**
* Method getCtfTmfTrace. gets a CtfTmfTrace
+ *
* @return CtfTmfTrace
*/
public CtfTmfTrace getCtfTmfTrace() {
/**
* Method getCurrentEvent. gets the current event
+ *
* @return CtfTmfEvent
*/
public CtfTmfEvent getCurrentEvent() {
*
* @param ctfLocationData
* The LocationData representing the position to seek to
- * @return boolean
+ * @return boolean True if the seek was successful, false if there was an
+ * error seeking.
* @since 2.0
*/
public synchronized boolean seek(final CtfLocationInfo ctfLocationData) {
/* Adjust the timestamp depending on the trace's offset */
long currTimestamp = ctfLocationData.getTimestamp();
final long offsetTimestamp = this.getCtfTmfTrace().getCTFTrace().timestampNanoToCycles(currTimestamp);
- if (offsetTimestamp < 0) {
- ret = super.seek(0L);
- } else {
- ret = super.seek(offsetTimestamp);
+ try {
+ if (offsetTimestamp < 0) {
+ ret = super.seek(0L);
+ } else {
+ ret = super.seek(offsetTimestamp);
+ }
+ } catch (CTFReaderException e) {
+ Activator.logError(e.getMessage(), e);
+ return false;
}
-
/*
* Check if there is already one or more events for that timestamp, and
* assign the location index correctly
/**
* Method getRank.
+ *
* @return long
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
*/
/**
* Method setRank.
- * @param rank long
+ *
+ * @param rank
+ * long
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
*/
@Override
@Override
public CtfIterator clone() {
CtfIterator clone = null;
- clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank);
+ try {
+ clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank);
+ } catch (CTFReaderException e) {
+ Activator.logError(e.getMessage(), e);
+ }
return clone;
}
/**
* Method dispose.
+ *
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
*/
@Override
/**
* Method setLocation.
- * @param location ITmfLocation<?>
+ *
+ * @param location
+ * ITmfLocation<?>
* @since 3.0
*/
@Override
/**
* Method getLocation.
+ *
* @return CtfLocation
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
*/
/**
* Method increaseRank.
+ *
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
*/
@Override
/**
* Method hasValidRank, if the iterator is valid
+ *
* @return boolean
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
*/
/**
* Method advance go to the next event
+ *
* @return boolean successful or not
*/
@Override
public synchronized boolean advance() {
long index = curLocation.getLocationInfo().getIndex();
long timestamp = curLocation.getLocationInfo().getTimestamp();
- boolean ret = super.advance();
+ boolean ret = false;
+ try {
+ ret = super.advance();
+ } catch (CTFReaderException e) {
+ Activator.logError(e.getMessage(), e);
+ }
if (ret) {
final long timestampValue = getCurrentEvent().getTimestamp().getValue();
/**
* Method compareTo.
- * @param o CtfIterator
+ *
+ * @param o
+ * CtfIterator
* @return int -1, 0, 1
*/
@Override
* @since 2.0
*/
public CtfIterator createIterator() {
- return new CtfIterator(this);
+ try {
+ return new CtfIterator(this);
+ } catch (CTFReaderException e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ return null;
}
// ------------------------------------------------------------------------