summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorFrançois Rajotte2013-03-05 14:43:48 (EST)
committer Alexandre Montplaisir2013-03-14 16:08:05 (EDT)
commit2734ce3ae4afab5a5ae841ec76e1c379d28a5640 (patch)
treed9e2107021f118e8d1a9b9afffaad157e67246df
parent3a2422fb76db6f1ff9c8c79fd76795ea98c9e7b2 (diff)
downloadorg.eclipse.linuxtools-2734ce3ae4afab5a5ae841ec76e1c379d28a5640.zip
org.eclipse.linuxtools-2734ce3ae4afab5a5ae841ec76e1c379d28a5640.tar.gz
org.eclipse.linuxtools-2734ce3ae4afab5a5ae841ec76e1c379d28a5640.tar.bz2
[TMF] Add support for 64-bit integers in the history treerefs/changes/68/10868/8
Change-Id: Ib37fc52bcb3e032bb671ba836023281f4c4f0b01 Signed-off-by: François Rajotte <francois.rajotte@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/10868 Tested-by: Hudson CI IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java14
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java93
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/ITmfStateValue.java14
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java53
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java30
5 files changed, 178 insertions, 26 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java
index e0447d0..27103f2 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java
@@ -59,6 +59,7 @@ public class StateSystemPushPopTest {
private final static ITmfStateValue value2 = TmfStateValue.newValueInt(10);
private final static ITmfStateValue value3 = TmfStateValue.nullValue();
private final static ITmfStateValue value4 = TmfStateValue.newValueString("D"); //$NON-NLS-1$
+ private final static ITmfStateValue value5 = TmfStateValue.newValueLong(Long.MAX_VALUE);
/**
* Test case constructor
@@ -99,7 +100,11 @@ public class StateSystemPushPopTest {
ss.pushAttribute( 2, value1, attrib);
ss.pushAttribute( 4, value2, attrib);
ss.pushAttribute( 6, value3, attrib);
- ss.pushAttribute(10, value4, attrib);
+ ss.pushAttribute( 8, value4, attrib);
+ ss.pushAttribute(10, value5, attrib);
+
+ value = ss.popAttribute(11, attrib);
+ assertEquals(value5, value);
value = ss.popAttribute(12, attrib);
assertEquals(value4, value);
@@ -212,6 +217,9 @@ public class StateSystemPushPopTest {
public void testStackTop() {
try {
interval = ss.querySingleStackTop(10, attribute);
+ assertEquals(value5, interval.getStateValue());
+
+ interval = ss.querySingleStackTop(9, attribute);
assertEquals(value4, interval.getStateValue());
interval = ss.querySingleStackTop(13, attribute);
@@ -281,9 +289,9 @@ public class StateSystemPushPopTest {
final int subAttrib3 = ss.getQuarkRelative(attribute, "3"); //$NON-NLS-1$
final int subAttrib4 = ss.getQuarkRelative(attribute, "4"); //$NON-NLS-1$
- /* Stack depth = 4 */
+ /* Stack depth = 5 */
state = ss.queryFullState(10);
- assertEquals(4, state.get(attribute).getStateValue().unboxInt());
+ assertEquals(5, state.get(attribute).getStateValue().unboxInt());
assertEquals(value1, state.get(subAttrib1).getStateValue());
assertEquals(value2, state.get(subAttrib2).getStateValue());
assertEquals(value3, state.get(subAttrib3).getStateValue());
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
index 5cb8158..ce733e8 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
@@ -36,6 +36,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
private static final byte TYPE_NULL = -1;
private static final byte TYPE_INTEGER = 0;
private static final byte TYPE_STRING = 1;
+ private static final byte TYPE_LONG = 2;
private final long start;
private final long end;
@@ -135,6 +136,19 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
*/
buffer.reset();
break;
+
+ case TYPE_LONG:
+ /* Go read the matching entry in the Strings section of the block */
+ buffer.mark();
+ buffer.position(valueOrOffset);
+ value = TmfStateValue.newValueLong(buffer.getLong());
+
+ /*
+ * Restore the file pointer's position (so we can read the next
+ * interval)
+ */
+ buffer.reset();
+ break;
default:
/* Unknown data, better to not make anything up... */
throw new IOException(errMsg);
@@ -171,9 +185,10 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
buffer.putInt(attribute);
buffer.put(getByteFromType(sv.getType()));
- byteArrayToWrite = sv.toByteArray();
+ switch (getByteFromType(sv.getType())) {
- if (byteArrayToWrite == null) {
+ case TYPE_NULL:
+ case TYPE_INTEGER:
/* We write the 'valueOffset' field as a straight value. In the case
* of a null value, it will be unboxed as -1 */
try {
@@ -187,27 +202,59 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
}
return 0; /* we didn't use a Strings section entry */
+ case TYPE_STRING:
+ byteArrayToWrite = sv.toByteArray();
+ /*
+ * Size to write (+2 = +1 for size at the start, +1 for the 0 at the
+ * end)
+ */
+ sizeOfStringEntry = byteArrayToWrite.length + 2;
+
+ /* we use the valueOffset as an offset. */
+ buffer.putInt(endPosOfStringEntry - sizeOfStringEntry);
+ buffer.mark();
+ buffer.position(endPosOfStringEntry - sizeOfStringEntry);
+
+ /*
+ * write the Strings entry (1st byte = size, then the bytes, then the 0)
+ */
+ buffer.put((byte) sizeOfStringEntry);
+ buffer.put(byteArrayToWrite);
+ buffer.put((byte) 0);
+ assert (buffer.position() == endPosOfStringEntry);
+ buffer.reset();
+ return sizeOfStringEntry;
+
+ case TYPE_LONG:
+ /*
+ * Size to write is the number of bytes in a Long
+ */
+ sizeOfStringEntry = 8;
+
+ /* we use the valueOffset as an offset. */
+ buffer.putInt(endPosOfStringEntry - sizeOfStringEntry);
+ buffer.mark();
+ buffer.position(endPosOfStringEntry - sizeOfStringEntry);
+
+ /*
+ * write the Long in the Strings section
+ */
+ try {
+ buffer.putLong(sv.unboxLong());
+ } catch (StateValueTypeException e) {
+ /*
+ * This should not happen, since the value told us it was of
+ * type Long (corrupted value?)
+ */
+ e.printStackTrace();
+ }
+ assert (buffer.position() == endPosOfStringEntry);
+ buffer.reset();
+ return sizeOfStringEntry;
+
+ default:
+ return 0;
}
- /*
- * Size to write (+2 = +1 for size at the start, +1 for the 0 at the
- * end)
- */
- sizeOfStringEntry = byteArrayToWrite.length + 2;
-
- /* we use the valueOffset as an offset. */
- buffer.putInt(endPosOfStringEntry - sizeOfStringEntry);
- buffer.mark();
- buffer.position(endPosOfStringEntry - sizeOfStringEntry);
-
- /*
- * write the Strings entry (1st byte = size, then the bytes, then the 0)
- */
- buffer.put((byte) sizeOfStringEntry);
- buffer.put(byteArrayToWrite);
- buffer.put((byte) 0);
- assert (buffer.position() == endPosOfStringEntry);
- buffer.reset();
- return sizeOfStringEntry;
}
@Override
@@ -327,6 +374,8 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
return TYPE_INTEGER;
case STRING:
return TYPE_STRING;
+ case LONG:
+ return TYPE_LONG;
default:
/* Should not happen if the switch is fully covered */
throw new RuntimeException();
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/ITmfStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/ITmfStateValue.java
index 7ea8c2e..6ecb233 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/ITmfStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/ITmfStateValue.java
@@ -33,7 +33,9 @@ public interface ITmfStateValue {
/** 32-bit integer value */
INTEGER,
/** Variable-length string value */
- STRING
+ STRING,
+ /** 64-bit integer value */
+ LONG
}
/**
@@ -71,4 +73,14 @@ public interface ITmfStateValue {
* If the contained value cannot be read as a String
*/
public String unboxStr() throws StateValueTypeException;
+
+ /**
+ * Read the contained value as a 'long' primitive
+ *
+ * @return The long contained in the state value
+ * @throws StateValueTypeException
+ * If the contained value cannot be read as a long
+ * @since 2.0
+ */
+ public long unboxLong() throws StateValueTypeException;
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java
new file mode 100644
index 0000000..3a353b3
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/LongStateValue.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2013 École Polytechnique de Montréal
+ *
+ * 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:
+ * François Rajotte - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statevalue;
+
+/**
+ * A state value containing a long integer (8 bytes).
+ *
+ * @version 1.0
+ * @author François Rajotte
+ */
+final class LongStateValue extends TmfStateValue {
+
+ private final long valueLong;
+
+ public LongStateValue(long valueAsLong) {
+ this.valueLong = valueAsLong;
+ }
+
+ @Override
+ public Type getType() {
+ return Type.LONG;
+ }
+
+ @Override
+ public boolean isNull() {
+ return false;
+ }
+
+ @Override
+ public Long getValue() {
+ return valueLong;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%3d", valueLong); //$NON-NLS-1$
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
index e085930..ec2fa4e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
@@ -138,6 +138,20 @@ public abstract class TmfStateValue implements ITmfStateValue {
return new StringStateValue(strValue);
}
+ /**
+ * Factory constructor for Long state values
+ *
+ * @param longValue The long value to contain
+ * @return The newly-create TmfStateValue object
+ * @since 2.0
+ */
+ public static TmfStateValue newValueLong(long longValue) {
+ if (longValue == -1) {
+ return nullValue();
+ }
+ return new LongStateValue(longValue);
+ }
+
@Override
public int unboxInt() throws StateValueTypeException {
if (this.isNull()) {
@@ -163,4 +177,20 @@ public abstract class TmfStateValue implements ITmfStateValue {
}
return (String) this.getValue();
}
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public long unboxLong() throws StateValueTypeException {
+ if (this.isNull()) {
+ /* Long value expected, return "-1" instead */
+ return -1;
+ }
+
+ if (this.getType() != Type.LONG) {
+ throw new StateValueTypeException();
+ }
+ return (Long) this.getValue();
+ }
}