aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2012-04-17 15:33:21 (EDT)
committerMatthew Khouzam2012-05-01 09:47:44 (EDT)
commitcb942f7a60a2256ee8879b955b55cdf2c7fe11ee (patch)
tree20d9340ecf1eb2a5c985d74ec9ab61de9df2f74c
parent8b6543cfe7abf4cd3ca3c68f3b16cb62dd340ce3 (diff)
downloadorg.eclipse.linuxtools-cb942f7a60a2256ee8879b955b55cdf2c7fe11ee.zip
org.eclipse.linuxtools-cb942f7a60a2256ee8879b955b55cdf2c7fe11ee.tar.gz
org.eclipse.linuxtools-cb942f7a60a2256ee8879b955b55cdf2c7fe11ee.tar.bz2
Add floating point support and Loglevel support
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java13
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java89
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java116
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java97
4 files changed, 311 insertions, 4 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java
index 1650ed1..791634f 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java
@@ -52,6 +52,11 @@ public class EventDeclaration {
*/
private Stream stream = null;
+ /**
+ * Loglevel of an event
+ */
+ private long logLevel;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
@@ -141,6 +146,14 @@ public class EventDeclaration {
return stream != null;
}
+ public long getLogLevel() {
+ return logLevel;
+ }
+
+ public void setLogLevel( long level){
+ logLevel = level;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java
new file mode 100644
index 0000000..da99c81
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+import java.nio.ByteOrder;
+
+
+public class FloatDeclaration implements IDeclaration {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final int mant;
+ private final int exp;
+ private final ByteOrder byteOrder;
+ private final Encoding encoding;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder,
+ Encoding encoding) {
+ mant = mantissa;
+ exp = exponent;
+ this.byteOrder = byteOrder;
+ this.encoding = encoding;
+
+ }
+
+ // ------------------------------------------------------------------------
+ // Gettters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+
+
+ /**
+ * @return the mant
+ */
+ public int getMantissa() {
+ return mant;
+ }
+
+ /**
+ * @return the exp
+ */
+ public int getExponent() {
+ return exp;
+ }
+
+ /**
+ * @return the byteOrder
+ */
+ public ByteOrder getByteOrder() {
+ return byteOrder;
+ }
+
+ /**
+ * @return the encoding
+ */
+ public Encoding getEncoding() {
+ return encoding;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public Definition createDefinition(IDefinitionScope definitionScope,
+ String fieldName) {
+ return new FloatDefinition(this, definitionScope, fieldName);
+ }
+
+ @Override
+ public String toString() {
+ /* Only used for debugging */
+ return "[declaration] float[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java
new file mode 100644
index 0000000..cdb0a52
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+
+public class FloatDefinition extends Definition {
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final FloatDeclaration declaration;
+ private double value;
+
+ // ------------------------------------------------------------------------
+ // Contructors
+ // ------------------------------------------------------------------------
+
+ public FloatDefinition(FloatDeclaration declaration,
+ IDefinitionScope definitionScope, String fieldName) {
+ super(definitionScope, fieldName);
+ this.declaration = declaration;
+ }
+ // ------------------------------------------------------------------------
+ // Gettters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double val) {
+ value = val;
+ }
+
+ public FloatDeclaration getDeclaration() {
+ return declaration;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+
+
+ @Override
+ public void read(BitBuffer input) {
+ int exp = declaration.getExponent();
+ int mant = declaration.getMantissa();
+ if( (exp + mant) == 32 ){
+ readRawFloat32(input, mant , exp);
+ }
+ else if((exp + mant) == 64)
+ {
+ readRawFloat64(input, mant,exp);
+ }
+ else
+ {
+ value = Double.NaN;
+ }
+ }
+
+
+
+ private void 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);
+ }
+
+ /**
+ * @param rawValue
+ * @param manBits
+ * @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;
+ }
+
+ private void readRawFloat32(BitBuffer input, final int manBits,
+ final int expBits) {
+ long temp = input.getInt(32, false);
+
+ value = createFloat(temp, manBits, expBits);
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(value);
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
index 40588eb..45707a7 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
@@ -28,6 +28,7 @@ import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
@@ -36,7 +37,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.parser.CTFParser;
-import org.eclipse.linuxtools.internal.ctf.core.Activator;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
@@ -720,7 +720,11 @@ public class IOStructGen {
*/
final StructDeclaration fields = (StructDeclaration) fieldsDecl;
event.setFields(fields);
+ }
+ else if (left.equals("loglevel")){ //$NON-NLS-1$
+ long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0)) ;
+ event.setLogLevel(logLevel);
} else {
throw new ParseException("Unknown event attribute : " + left); //$NON-NLS-1$
}
@@ -1132,9 +1136,10 @@ public class IOStructGen {
switch (firstChild.getType()) {
case CTFParser.FLOATING_POINT:
- Activator
- .getDefault()
- .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$
+// Activator
+// .getDefault()
+// .log("parseTypeSpecifierList: floating_point not implemented yet"); //$NON-NLS-1$
+ declaration = parseFloat(firstChild);
break;
case CTFParser.INTEGER:
declaration = parseInteger(firstChild);
@@ -1174,6 +1179,90 @@ public class IOStructGen {
return declaration;
}
+ private IDeclaration parseFloat(CommonTree floatingPoint) throws ParseException {
+ assert (floatingPoint.getType() == CTFParser.INTEGER);
+
+ List<CommonTree> children = floatingPoint.getChildren();
+
+ /*
+ * If the integer has no attributes, then it is missing the size
+ * attribute which is required
+ */
+ if (children == null) {
+ throw new ParseException("float: missing size attribute"); //$NON-NLS-1$
+ }
+
+ /* The return value */
+ FloatDeclaration floatDeclaration = null;
+ ByteOrder byteOrder = trace.getByteOrder();
+ long alignment = 0;
+ int base = 2;
+ int exponent = 8;
+ int mantissa = 24;
+
+ Encoding encoding = Encoding.NONE;
+
+ /* Iterate on all integer children */
+ for (CommonTree child : children) {
+ switch (child.getType()) {
+ case CTFParser.CTF_EXPRESSION_VAL:
+ /*
+ * An assignment expression must have 2 children, left and right
+ */
+ assert (child.getChildCount() == 2);
+
+ CommonTree leftNode = (CommonTree) child.getChild(0);
+ assert (leftNode.getType() == CTFParser.CTF_LEFT);
+ CommonTree rightNode = (CommonTree) child.getChild(1);
+ assert (rightNode.getType() == CTFParser.CTF_RIGHT);
+
+ List<CommonTree> leftStrings = leftNode.getChildren();
+ assert (leftStrings != null);
+
+ if (!isUnaryString(leftStrings.get(0))) {
+ throw new ParseException(
+ "Left side of ctf expression must be a string"); //$NON-NLS-1$
+ }
+ String left = concatenateUnaryStrings(leftStrings);
+
+ if (left.equals("exp_dig")) { //$NON-NLS-1$
+ exponent = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
+ } else if (left.equals("byte_order")) { //$NON-NLS-1$
+ byteOrder = getByteOrder(rightNode);
+ } else if (left.equals("mant_dig")) { //$NON-NLS-1$
+ mantissa = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0));
+ } else if (left.equals("align")) { //$NON-NLS-1$
+ alignment = getAlignment(rightNode);
+ } else {
+ throw new ParseException("Float: unknown attribute " + left); //$NON-NLS-1$
+ }
+
+ break;
+ default:
+ childTypeError(child);
+ break;
+ }
+ }
+ int size = mantissa + exponent;
+ if (size == 0) {
+ throw new ParseException("Float missing size attribute"); //$NON-NLS-1$
+ }
+
+ if (alignment == 0) {
+ if ((size % 8) == 0) {
+ alignment = 1;
+ } else {
+ alignment = 8;
+ }
+ }
+
+ floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding);
+
+ assert (floatDeclaration != null);
+ return floatDeclaration;
+
+ }
+
/**
* Parses a type specifier list as a user-declared type.
*