/**
* Run the CTFEventField parseField(Definition,String) method test.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testParseField_complex() throws CTFReaderException {
int len = 32;
IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null);
+ ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null, 32);
String lengthName = "LengthName"; //$NON-NLS-1$
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
/**
* Run the CTFEventField parseField(Definition,String) method test.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testParseField_simple() throws CTFReaderException {
public void testParseField_simple2() {
IntegerDefinition fieldDef = new IntegerDefinition(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null), null, fieldName);
+ Encoding.ASCII, null, 8), null, fieldName);
fieldDef.setValue(1L);
assertNotNull(fieldDef);
@Test
public void testParseField_manual() {
Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(20,
- new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null)),
+ new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null, 8)),
null, fieldName);
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
@Test
public void testParseField_manual2() {
Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(12,
- new IntegerDeclaration(32, false, 32, null, null, null)), null,
+ new IntegerDeclaration(32, false, 32, null, null, null, 8)), null,
fieldName);
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
*/
@SuppressWarnings("nls")
public static void main(String[] args) {
- final String TRACE_PATH = "Tests/traces/trace20m1";
+ final String TRACE_PATH = "/home/ematkho/lttng-traces/lt-hello-4175-20120405-092230";
// Change this to enable text output
- final boolean USE_TEXT = false;
+ final boolean USE_TEXT = true;
final int LOOP_COUNT = 1;
+ trace.getOffset());
System.out.println(traceReader.getIndex() + ", "
+ output + ", " + ed.getDeclaration().getName()
- + ", " + ed.getCPU());
+ + ", " + ed.getCPU() + ed.getFields().toString()) ;
}
traceReader.advance();
}
private ArrayDefinition createLongArray() {
- IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none"); //$NON-NLS-1$
+ IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none",8); //$NON-NLS-1$
IntegerDefinition[] defs = createIntDefs(10, 32);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
}
private ArrayDefinition createCharArray() {
- IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none"); //$NON-NLS-1$
+ IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none",8); //$NON-NLS-1$
IntegerDefinition[] defs = createIntDefs(4,8);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
String content = "test" + i; //$NON-NLS-1$
defs[i] = new IntegerDefinition(new IntegerDeclaration(bits, false,
- 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content);
+ 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content);
defs[i].setValue(i);
}
return defs;
@Test
public void testIsString_complex() {
final IntegerDeclaration id = new IntegerDeclaration(8, false, 16,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
ArrayDeclaration ad = new ArrayDeclaration(0, id);
ArrayDefinition ownFixture = new ArrayDefinition(ad, this.trace,
"Testx"); //$NON-NLS-1$
@Before
public void setUp() {
fixture = new EnumDeclaration(new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null));
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8));
}
/**
@Test
public void testEnumDeclaration() {
IntegerDeclaration containerType = new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
EnumDeclaration result = new EnumDeclaration(containerType);
public void setUp() {
EnumDeclaration declaration = new EnumDeclaration(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null));
+ Encoding.ASCII, null, 8));
String fieldName = ""; //$NON-NLS-1$
fixture = new EnumDefinition(declaration, null, fieldName);
@Before
public void setUp() {
fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null);
+ Encoding.ASCII, null, 32);
}
/**
Encoding encoding = Encoding.ASCII;
IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
- byteOrder, encoding, null);
+ byteOrder, encoding, null, 16);
assertNotNull(result);
assertEquals(1, result.getBase());
@Test
public void testIsCharacter_8bytes() {
IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
boolean result = fixture8.isCharacter();
assertEquals(true, result);
@Test
public void testIsSigned_unsigned() {
IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false,
- 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+ 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
boolean result = fixture_unsigned.isSigned();
assertEquals(false, result);
}
- /**
- * Run the void setBase(int) method test.
- */
- @Test
- public void testSetBase() {
- int base = 1;
- fixture.setBase(base);
- }
-
- /**
- * Run the void setByteOrder(ByteOrder) method test.
- */
- @Test
- public void testSetByteOrder() {
- ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
- fixture.setByteOrder(byteOrder);
- }
-
- /**
- * Run the void setEncoding(Encoding) method test.
- */
- @Test
- public void testSetEncoding() {
- Encoding encoding = Encoding.ASCII;
- fixture.setEncoding(encoding);
- }
-
- /**
- * Run the void setLength(int) method test.
- */
- @Test
- public void testSetLength() {
- int length = 1;
- fixture.setLength(length);
- }
-
- /**
- * Run the void setSigned(boolean) method test.
- */
- @Test
- public void testSetSigned() {
- boolean signed = true;
- fixture.setSigned(signed);
- }
/**
* Run the String toString() method test.
/**
* Perform pre-test initialization. We know the structDef won't be null (or
* else the tests will fail), so we can safely suppress the warning.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
@Test
public void testIntegerDefinition() {
IntegerDeclaration declaration = new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
IDefinitionScope definitionScope = null;
String fieldName = ""; //$NON-NLS-1$
@Test
public void testCreateDefinition() {
IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(fieldName, id);
/**
* Perform pre-test initialization.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
StructDefinition structDef;
IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
String lengthName = "LengthName"; //$NON-NLS-1$
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
int len = 32;
IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
String lengthName = "LengthName"; //$NON-NLS-1$
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
* Perform pre-test initialization.
*
* Not sure it needs to be that complicated, oh well...
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
sDef2 = new StructDefinition(new StructDeclaration(1L), vDef2, fName);
eDef = new EnumDefinition(new EnumDeclaration(new IntegerDeclaration(1,
- true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName)), sDef2, fName);
+ true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName, 8)), sDef2, fName);
fixture = new VariantDefinition(vDecl1, sDef1, fName);
fixture.setTagDefinition(eDef);
/**
* Run the VariantDefinition(VariantDeclaration,DefinitionScope,String)
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Test
public void testVariantDefinition() throws CTFReaderException {
/**
* Run the void setTagDefinition(EnumDefinition) method test.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Test
public void testSetTagDefinition() throws CTFReaderException {
structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
tagDefinition = new EnumDefinition(new EnumDeclaration(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, fName)), structDef, fName);
+ Encoding.ASCII, fName, 8)), structDef, fName);
fixture.setTagDefinition(tagDefinition);
}
return length;
}
+ @Override
+ public long getAlignment() {
+ long retVal = this.getElementType().getAlignment();
+ return retVal;
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return containerType;
}
+ @Override
+ public long getAlignment() {
+ return this.getContainerType().getAlignment();
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return "[declaration] enum[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
}
+
}
*
* Contributors: Matthew Khouzam - Initial API and implementation
*******************************************************************************/
+
package org.eclipse.linuxtools.ctf.core.event.types;
import java.nio.ByteOrder;
private final int exp;
private final ByteOrder byteOrder;
private final Encoding encoding;
+ private final long alignment;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder,
- Encoding encoding) {
+ Encoding encoding, long alignment) {
mant = mantissa;
exp = exponent;
this.byteOrder = byteOrder;
this.encoding = encoding;
+ this.alignment = alignment;
}
// Gettters/Setters/Predicates
// ------------------------------------------------------------------------
-
-
/**
* @return the mant
*/
return encoding;
}
+ public long getAlignment() {
+ return alignment;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
int exp = declaration.getExponent();
int mant = declaration.getMantissa();
if( (exp + mant) == 32 ){
- readRawFloat32(input, mant , exp);
+ value = readRawFloat32(input, mant , exp);
}
else if((exp + mant) == 64)
{
- readRawFloat64(input, mant,exp);
+ value = readRawFloat64(input, mant,exp);
}
else
{
- private void readRawFloat64(BitBuffer input, final int manBits, final int expBits) {
+ private static double readRawFloat64(BitBuffer input, final int manBits, final int expBits) {
long low = input.getInt(32, false);
low = low & 0x00000000FFFFFFFFL;
long high = input.getInt(32, false);
high = high & 0x00000000FFFFFFFFL;
long temp = (high << 32) | low;
-
-
- value = createFloat(temp, manBits, expBits);
+ return createFloat(temp, manBits-1, expBits);
}
/**
* @param expBits
*/
private static double createFloat(long rawValue, final int manBits, final int expBits) {
- long manShift = 1L << manBits;
- long manMask = manShift -1;
- long expMask = (1L << expBits) -1;
-
- int exp =(int)( rawValue >> manBits);
- long man = (rawValue & manMask);
- double expPow = Math.pow(2.0, exp-(1 << (expBits-1)));
- double ret = man * 1.0f;
- ret /= manShift;
- ret += 1.0;
- ret *= expPow;
- return ret;
+ long manShift = 1L << (manBits);
+ long manMask = manShift - 1;
+ long expMask = (1L << expBits) - 1;
+
+ int exp = (int) ((rawValue >> (manBits))&expMask)+1;
+ long man = (rawValue & manMask);
+ double expPow = Math.pow(2.0, exp - (1 << (expBits - 1)));
+ double ret = man * 1.0f;
+ ret /= manShift;
+ ret += 1.0;
+ ret *= expPow;
+ return ret;
}
- private void readRawFloat32(BitBuffer input, final int manBits,
+ private static double readRawFloat32(BitBuffer input, final int manBits,
final int expBits) {
long temp = input.getInt(32, false);
-
- value = createFloat(temp, manBits, expBits);
+ return createFloat(temp, manBits-1, expBits);
}
@Override
public Definition createDefinition(IDefinitionScope definitionScope,
String fieldName);
+
+ public long getAlignment();
}
// Attributes
// ------------------------------------------------------------------------
- private int length;
- private boolean signed;
- private int base;
- private ByteOrder byteOrder;
- private Encoding encoding;
- @SuppressWarnings("unused")
- private final String clock;
+ final private int length;
+ final private boolean signed;
+ final private int base;
+ final private ByteOrder byteOrder;
+ final private Encoding encoding;
+ final private long alignment;
+ final private String clock;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public IntegerDeclaration(int len, boolean signed, int base,
- ByteOrder byteOrder, Encoding encoding, String clock) {
+ ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
this.length = len;
this.signed = signed;
this.base = base;
this.byteOrder = byteOrder;
this.encoding = encoding;
this.clock = clock;
+ this.alignment = alignment;
}
// ------------------------------------------------------------------------
return signed;
}
- public void setSigned(boolean signed) {
- this.signed = signed;
- }
-
public int getBase() {
return base;
}
- public void setBase(int base) {
- this.base = base;
- }
-
public ByteOrder getByteOrder() {
return byteOrder;
}
- public void setByteOrder(ByteOrder byteOrder) {
- this.byteOrder = byteOrder;
- }
-
public Encoding getEncoding() {
return encoding;
}
- public void setEncoding(Encoding encoding) {
- this.encoding = encoding;
- }
-
- public void setLength(int length) {
- this.length = length;
- }
-
- public boolean isCharacter() {
+ public boolean isCharacter() {
return (length == 8) && (encoding != Encoding.NONE);
}
return length;
}
+ public long getAlignment(){
+ return alignment;
+ }
+
+ public String getClock(){
+ return clock;
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return lengthName;
}
+ @Override
+ public long getAlignment() {
+ return getElementType().getAlignment();
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
this.encoding = encoding;
}
+ @Override
+ public long getAlignment() {
+ return 8; //FIXME: should be the elementtype.
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return this.fieldsList;
}
+ @Override
+ public long getAlignment() {
+ return getMinAlign();
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
private String tag = null;
+ private long alignment;
private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
// ------------------------------------------------------------------------
return this.fields;
}
+ @Override
+ public long getAlignment() {
+ return alignment;
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
public void addField(String fieldTag, IDeclaration declaration) {
fields.put(fieldTag, declaration);
+ alignment = Math.max(alignment, declaration.getAlignment());
}
@Override
long timestamp = 0;
/*
- * Read thestream event header.
+ * Read the stream event header.
*/
if (getStreamEventHeaderDef() != null) {
getStreamEventHeaderDef().read(getBitBuffer());
* Read the event fields.
*/
if (eventDef.fields != null) {
+ int pos = getBitBuffer().position();
+ int minAlign = (int) eventDef.fields.getDeclaration().getMinAlign();
+ int offset = pos % minAlign;
+ pos += (minAlign - offset)%minAlign;
+ getBitBuffer().position(pos);
eventDef.fields.read(getBitBuffer());
}
}
}
- floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding);
+ floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding, alignment);
assert (floatDeclaration != null);
return floatDeclaration;
}
integerDeclaration = new IntegerDeclaration((int) size, signed, base,
- byteOrder, encoding, clock);
+ byteOrder, encoding, clock, alignment);
assert (integerDeclaration != null);
return integerDeclaration;
/* Parse the body */
parseStructBody(structBody, structDeclaration);
+ long maxFieldAlign = -1;
+ for( IDeclaration field : structDeclaration.getFields().values())
+ {
+ maxFieldAlign = Math.max(maxFieldAlign, field.getAlignment());
+ }
+ structDeclaration.setMinAlign(maxFieldAlign);
/* If struct has name, add it to the current scope. */
if (hasName) {