aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernd Hufmann2012-11-21 15:10:45 (EST)
committerBernd Hufmann2012-11-22 20:18:09 (EST)
commit56ecb313ec5ce46cfb5a85a6c52e3f3db563c4c4 (patch)
tree7e719d43ac482ca290fe96c3c3ec42126d282a10
parent99a0f482a753dddd3d8f4b92d81eb1af479bea04 (diff)
downloadorg.eclipse.linuxtools-56ecb313ec5ce46cfb5a85a6c52e3f3db563c4c4.zip
org.eclipse.linuxtools-56ecb313ec5ce46cfb5a85a6c52e3f3db563c4c4.tar.gz
org.eclipse.linuxtools-56ecb313ec5ce46cfb5a85a6c52e3f3db563c4c4.tar.bz2
Support for multiple events for same timestamp at checkpointrefs/changes/58/8758/6
If a trace has multiple events with the same timestamps before a checkpoint and at the checkpoint, the seek to this timestamp used to return the event at the checkpoint. The implementation was changed so that the first event in the trace with this timestamp is returned. Also the compareTo() method of TmfCheckpoint has been updated to consider the checkpoint location if the timestamp to search is equal to the timestamp of a checkpoint. This ensure that the first checkpoint is found of multiple checkpoints with same timestamp Change-Id: I73fa8f19d8a2dcc45da10bd44eaaa4e402f4a0dd Reviewed-on: https://git.eclipse.org/r/8758 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI IP-Clean: Bernd Hufmann <bhufmann@gmail.com> Tested-by: Bernd Hufmann <bhufmann@gmail.com> Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java227
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/testfiles/A-Test-10K-2bin0 -> 45094 bytes
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java31
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java4
5 files changed, 258 insertions, 5 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java
index 4dfea6c..ab44c9c 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java
@@ -34,6 +34,7 @@ public class AllTests {
suite.addTestSuite(TmfContextTest.class);
suite.addTestSuite(TmfCheckpointTest.class);
suite.addTestSuite(TmfCheckpointIndexTest.class);
+ suite.addTestSuite(TmfCheckpointIndexTest2.class);
suite.addTestSuite(TmfTraceTest.class);
suite.addTestSuite(TmfExperimentCheckpointIndexTest.class);
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java
new file mode 100644
index 0000000..eabcf33
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * 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:
+ * Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+
+/**
+ * Test suite for the TmfCheckpointIndexer class (events with same
+ * timestamp around checkpoint).
+ */
+@SuppressWarnings({"nls","javadoc"})
+public class TmfCheckpointIndexTest2 extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
+ private static final String DIRECTORY = "testfiles";
+ // Trace has 3 events at t=101 at rank 99, 100, 101
+ // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
+ private static final String TEST_STREAM = "A-Test-10K-2";
+ private static final int BLOCK_SIZE = 100;
+ private static final int NB_EVENTS = 702;
+ private static TestTrace fTrace = null;
+ private static EmptyTestTrace fEmptyTrace = null;
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ /**
+ * @param name the test name
+ */
+ public TmfCheckpointIndexTest2(final String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fTrace.dispose();
+ fTrace = null;
+ fEmptyTrace.dispose();
+ fEmptyTrace = null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper classes
+ // ------------------------------------------------------------------------
+
+ private static class TestIndexer extends TmfCheckpointIndexer {
+ @SuppressWarnings({ })
+ public TestIndexer(TestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ @SuppressWarnings({ })
+ public TestIndexer(EmptyTestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ public List<ITmfCheckpoint> getCheckpoints() {
+ return getTraceIndex();
+ }
+ }
+
+ private class TestTrace extends TmfTraceStub {
+ public TestTrace(String path, int blockSize) throws TmfTraceException {
+ super(path, blockSize);
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ private class EmptyTestTrace extends TmfEmptyTraceStub {
+ public EmptyTestTrace() {
+ super();
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper functions
+ // ------------------------------------------------------------------------
+
+ private synchronized void setupTrace(final String path) {
+ if (fTrace == null) {
+ try {
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
+ final File test = new File(FileLocator.toFileURL(location).toURI());
+ fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
+ fTrace.indexTrace();
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (fEmptyTrace == null) {
+ fEmptyTrace = new EmptyTestTrace();
+ fEmptyTrace.indexTrace();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ @SuppressWarnings("null")
+ public void testTmfTraceMultiTimestamps() {
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
+ assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", 102, fTrace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
+ assertEquals("getEndTime", 102, fTrace.getEndTime().getValue());
+
+ List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE + 1, checkpoints.size());
+
+ // Trace has 3 events with same timestamp (ts=101) at rank 99, 100, 101
+
+ // Verify that the event at rank=99 is returned when seeking to ts=101 (first event with this timestamp)
+ // and not the event at checkpoint boundary
+ TmfTimestamp seekTs = new TmfTimestamp(101, -3, 0);
+ ITmfContext ctx = fTrace.seekEvent(seekTs);
+ ITmfEvent event = fTrace.getNext(ctx);
+
+ assertEquals(99, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ event = fTrace.getNext(ctx);
+
+ assertEquals(100, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ event = fTrace.getNext(ctx);
+
+ assertEquals(101, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
+ // Verify that the event at rank=102 is returned when seeking to ts=102 (first event with this timestamp)
+ // and not the event at checkpoint boundary
+ seekTs = new TmfTimestamp(102, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(102, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to first checkpoint
+ seekTs = new TmfTimestamp(1, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(1, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp before first event
+ seekTs = new TmfTimestamp(0, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(1, ctx.getRank());
+ assertEquals(0, new TmfTimestamp(1, -3, 0).compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp between first and second checkpoint
+ seekTs = new TmfTimestamp(50, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(50, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp after last event in trace
+ seekTs = new TmfTimestamp(103, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(-1, ctx.getRank());
+ assertNull(event);
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/testfiles/A-Test-10K-2 b/lttng/org.eclipse.linuxtools.tmf.core.tests/testfiles/A-Test-10K-2
new file mode 100644
index 0000000..4cb2422
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/testfiles/A-Test-10K-2
Binary files differ
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java
index a2135ec..ee58f00 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java
@@ -132,12 +132,33 @@ public class TmfCheckpoint implements ITmfCheckpoint, Cloneable {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public int compareTo(final ITmfCheckpoint other) {
- if (fTimestamp == null || other.getTimestamp() == null) {
- final Comparable location1 = getLocation().getLocationInfo();
- final Comparable location2 = other.getLocation().getLocationInfo();
- return location1.compareTo(location2);
+ int comp = 0;
+ if ((fTimestamp != null) && (other.getTimestamp() != null)) {
+ comp = fTimestamp.compareTo(other.getTimestamp(), false);
+ if (comp != 0) {
+ return comp;
+ }
+ // compare locations if timestamps are the same
+ }
+
+ if ((getContext() == null) && (other.getContext() == null)) {
+ return 0;
+ }
+
+ // treat location of other as null location which is before any location
+ if ((getContext() != null) && (other.getContext() == null)) {
+ return 1;
+ }
+
+ // treat this as null location which is before any other locations
+ if ((getContext() == null) && (other.getContext() != null)) {
+ return -1;
}
- return fTimestamp.compareTo(other.getTimestamp(), false);
+
+ // compare location
+ final Comparable location1 = getLocation().getLocationInfo();
+ final Comparable location2 = other.getLocation().getLocationInfo();
+ return location1.compareTo(location2);
}
// ------------------------------------------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
index 1861403..7acd78a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
@@ -265,6 +265,10 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer {
int index = Collections.binarySearch(fTraceIndex, new TmfCheckpoint(timestamp, null));
if (index < 0) {
index = Math.max(0, -(index + 2));
+ } else {
+ // If timestamp was in the list, use previous index to be able to find the
+ // first event with the same timestamp before the checkpoint
+ index = Math.max(0, index - 1);
}
// Position the trace at the checkpoint