From 0316808c269c42fdb966c54c5c5631113a21b3cb Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Fri, 4 May 2012 09:49:40 -0400 Subject: [PATCH] Refactor TmfExperiment --- .../.gitignore | 1 + .../traces/.gitignore | 3 + .../core/tests/LttngTestPreparation.java | 2 - .../core/tests/trace/LTTngExperimentTest.java | 1 - .../lttng/core/event/LttngLocation.java | 22 +- .../lttng/core/trace/LTTngTextTrace.java | 14 +- .../internal/lttng/core/trace/LTTngTrace.java | 11 +- .../internal/lttng/stubs/LTTngTraceStub.java | 5 +- .../tmf/core/tests/event/AllTests.java | 3 +- .../core/tests/event/TmfEventFieldTest.java | 2 - .../tmf/core/tests/event/TmfEventTest.java | 2 - .../tests/event/TmfEventTypeManagerTest.java | 3 - .../core/tests/event/TmfEventTypeTest.java | 2 - .../tests/event/TmfSimpleTimestampTest.java | 2 - .../core/tests/event/TmfTimeRangeTest.java | 2 - .../core/tests/event/TmfTimestampTest.java | 2 - .../tmf/core/tests/experiment/AllTests.java | 16 + .../tests/experiment/TmfExperimentTest.java | 444 +++------ .../TmfMultiTraceExperimentTest.java | 440 +++------ .../tmf/core/tests/trace/AllTests.java | 3 +- .../tests/trace/TmfCheckpointIndexTest.java | 19 +- .../core/tests/trace/TmfCheckpointTest.java | 3 +- .../tmf/core/tests/trace/TmfContextTest.java | 3 +- .../tmf/core/tests/trace/TmfLocationTest.java | 2 - .../tmf/core/tests/trace/TmfTraceTest.java | 41 +- .../tests/stubs/trace/TmfEventParserStub.java | 56 +- .../tmf/tests/stubs/trace/TmfTraceStub.java | 28 +- .../linuxtools/tmf/core/event/ITmfEvent.java | 7 +- .../tmf/core/event/ITmfEventField.java | 7 +- .../tmf/core/event/ITmfEventType.java | 7 +- .../tmf/core/event/ITmfTimestamp.java | 7 +- .../linuxtools/tmf/core/event/TmfEvent.java | 3 +- .../tmf/core/event/TmfEventField.java | 3 +- .../tmf/core/event/TmfEventType.java | 3 +- .../tmf/core/event/TmfEventTypeManager.java | 1 - .../tmf/core/event/TmfSimpleTimestamp.java | 5 +- .../tmf/core/event/TmfTimeRange.java | 3 +- .../tmf/core/event/TmfTimestamp.java | 4 +- .../tmf/core/experiment/TmfExperiment.java | 881 ++++++++++-------- .../core/experiment/TmfExperimentContext.java | 53 +- .../experiment/TmfExperimentLocation.java | 122 ++- .../tmf/core/experiment/TmfLocationArray.java | 143 ++- .../tmf/core/trace/ITmfCheckpoint.java | 8 +- .../tmf/core/trace/ITmfContext.java | 7 +- .../tmf/core/trace/ITmfEventParser.java | 1 - .../tmf/core/trace/ITmfLocation.java | 7 +- .../linuxtools/tmf/core/trace/ITmfTrace.java | 19 +- .../tmf/core/trace/ITmfTraceIndexer.java | 1 - .../tmf/core/trace/TmfCheckpoint.java | 28 +- .../tmf/core/trace/TmfCheckpointIndexer.java | 47 +- .../linuxtools/tmf/core/trace/TmfContext.java | 25 +- .../tmf/core/trace/TmfLocation.java | 22 +- .../linuxtools/tmf/core/trace/TmfTrace.java | 120 ++- .../plugin.xml | 18 + .../META-INF/MANIFEST.MF | 18 +- .../tmf/ui/views/histogram/Histogram.java | 18 +- .../ui/views/histogram/HistogramRequest.java | 4 +- 57 files changed, 1331 insertions(+), 1393 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core.tests/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/.gitignore index 8d94ef8deb..e98343d9d0 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/.gitignore +++ b/org.eclipse.linuxtools.ctf.core.tests/.gitignore @@ -3,3 +3,4 @@ bin javaCompiler...args build.xml target +Tests/* diff --git a/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore index 6c4dbbfdaa..d5f79d55d4 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore +++ b/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore @@ -1,2 +1,5 @@ +*.bz2 /kernel /trace2 +*.ht + diff --git a/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/LttngTestPreparation.java b/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/LttngTestPreparation.java index aa5d574c54..15ca476542 100644 --- a/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/LttngTestPreparation.java +++ b/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/LttngTestPreparation.java @@ -77,10 +77,8 @@ public abstract class LttngTestPreparation extends TestCase { final ITmfTrace trace = prepareStreamToTest(); traces[0] = trace; - // create experiment and associate traces fTestExperiment = new TmfExperiment(LttngEvent.class, expId, traces, TmfTimestamp.ZERO, TmfExperiment.DEFAULT_BLOCK_SIZE, true); - // fTestExperiment.indexExperiment(waitForCompletion); // Set the current selected experiment as the test experiment final TmfExperimentSelectedSignal signal = new TmfExperimentSelectedSignal( diff --git a/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java b/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java index 456a9a67ee..b1d9dbbdd4 100644 --- a/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java +++ b/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java @@ -101,7 +101,6 @@ public class LTTngExperimentTest extends TestCase { public void testBasicTmfExperimentConstructor() { assertEquals("GetId", EXPERIMENT, fExperiment.getName()); - assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch()); assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents(); diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java index 4d693bfc42..08bfcafbb4 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java @@ -41,26 +41,8 @@ public class LttngLocation implements ITmfLocation, Comparable implements ITmfEventPar if ( positionToFirstEvent() == false ) throw new IOException("Fail to position to the beginning of the trace"); //$NON-NLS-1$ else { -// fCacheSize = 1000; - - // Skip indexing if asked - // if ( skipIndexing == true ) { -// fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation(0L))); + setCacheSize(1000); ITmfContext context = new TmfContext(new TmfLocation(0L), 0); - fIndexer.updateIndex(context, new LttngTimestamp(0L)); - fParser = (ITmfEventParser) this; - // } - // else { - // indexTrace(true); - // } + getIndexer().updateIndex(context, new LttngTimestamp(0L)); + setParser((ITmfEventParser) this); final Long endTime = currentLttngEvent.getTimestamp().getValue(); positionToFirstEvent(); diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java index 842f7cc3f0..0f5fe8d1e1 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java @@ -121,7 +121,6 @@ public class LTTngTrace extends TmfTrace implements ITmfEventParser< initialize(resource, path, eventType); } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected synchronized void initialize(final IResource resource, final String path, final Class eventType) throws TmfTraceException { @@ -153,8 +152,8 @@ public class LTTngTrace extends TmfTrace implements ITmfEventParser< // Set the currentEvent to the eventContent eventContent.setEvent(currentLttngEvent); - fParser = (ITmfEventParser) this; - fCacheSize = CHECKPOINT_PAGE_SIZE; + setParser((ITmfEventParser) this); + setCacheSize(CHECKPOINT_PAGE_SIZE); // // Bypass indexing if asked // if ( bypassIndexing == false ) { @@ -188,7 +187,7 @@ public class LTTngTrace extends TmfTrace implements ITmfEventParser< final LttngEvent event = readNextEvent(context); setEndTime(TmfTimestamp.BIG_BANG); final long startTime = event != null ? event.getTimestamp().getValue() : TmfTimestamp.BIG_BANG.getValue(); - fStreamingInterval = LTTNG_STREAMING_INTERVAL; + setStreamingInterval(LTTNG_STREAMING_INTERVAL); final Thread thread = new Thread("Streaming Monitor for trace " + getName()) { //$NON-NLS-1$ @@ -543,14 +542,14 @@ public class LTTngTrace extends TmfTrace implements ITmfEventParser< // timestamp = getStartTime(); // Position the trace at the checkpoint - final ITmfContext checkpointContext = fIndexer.seekIndex(rank); + final ITmfContext checkpointContext = getIndexer().seekIndex(rank); LttngLocation location = (LttngLocation) checkpointContext.getLocation(); ITmfTimestamp timestamp = location.getLocation(); long index = rank / getCacheSize(); // Seek to the found time final TmfContext tmpContext = seekEvent(timestamp); - tmpContext.setRank((index + 1) * fCacheSize); + tmpContext.setRank((index + 1) * getCacheSize()); previousLocation = (LttngLocation) tmpContext.getLocation(); // Ajust the index of the event we found at this check point position diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java index 3c55153ab2..26548d801a 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java @@ -23,6 +23,7 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; @@ -55,7 +56,7 @@ public class LTTngTraceStub extends TmfTrace implements ITmfEventPar * @throws FileNotFoundException */ public LTTngTraceStub(final IResource resource) throws TmfTraceException { - this(resource, DEFAULT_TRACE_CACHE_SIZE); + this(resource, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE); } /** @@ -76,7 +77,7 @@ public class LTTngTraceStub extends TmfTrace implements ITmfEventPar } public void indexTrace() { - fIndexer.buildIndex(true); + getIndexer().buildIndex(true); } // ======================================================================== diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java index f26e5ddc1e..a0b94e09b3 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java @@ -19,8 +19,7 @@ import junit.framework.TestSuite; import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin; /** - * AllTests - *

+ * Test suite for org.eclipse.linuxtools.tmf.core.event */ @SuppressWarnings("nls") public class AllTests { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java index dcfc605113..c710ee881c 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java @@ -19,8 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; /** - * TmfEventFieldTest - *

* Test suite for the TmfEventField class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java index 3ae06dac22..a87beae139 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java @@ -37,8 +37,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** - * TmfEventTest - *

* Test suite for the TmfEvent class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java index 5216666c7e..4ef3ba445a 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java @@ -22,10 +22,7 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager; /** - * TmfEventTypeManagerTest - *

* Test suite for the TmfEventTypeManager class. - *

*/ @SuppressWarnings("nls") public class TmfEventTypeManagerTest extends TestCase { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java index 76238f741c..ddd7889ffc 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java @@ -20,8 +20,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventType; /** - * TmfEventTypeTest - *

* Test suite for the TmfEventType class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java index 1bfd3f630f..bb198b5650 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java @@ -19,8 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfSimpleTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; /** - * TmfSimpleTimestampTest - *

* Test suite for the TmfSimpleTimestampTest class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java index 216677e259..a3e3e390cb 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java @@ -20,8 +20,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; /** - * TmfTimeRangeTest - *

* Test suite for the TmfTimeRange class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java index e60b94c3b5..95e1136ee2 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java @@ -19,8 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; /** - * TmfTimestampTest - *

* Test suite for the TmfTimestamp class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/AllTests.java index 21c10605e2..4b9c581773 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/AllTests.java @@ -1,3 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009, 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: + * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adjusted for new Trace Model + *******************************************************************************/ + package org.eclipse.linuxtools.tmf.core.tests.experiment; import junit.framework.Test; @@ -5,6 +18,9 @@ import junit.framework.TestSuite; import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin; +/** + * Test suite for org.eclipse.linuxtools.tmf.core.experiment + */ @SuppressWarnings("nls") public class AllTests { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java index c6d259726f..e8cd19099f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adjusted for new Trace Model *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.experiment; @@ -32,24 +33,26 @@ import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; -import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** - * TmfExperimentTest - *

- * TODO: Implement me. Please. + * Test suite for the TmfExperiment class (single trace). */ @SuppressWarnings("nls") public class TmfExperimentTest extends TestCase { + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM = "A-Test-10K"; private static final String EXPERIMENT = "MyExperiment"; private static int NB_EVENTS = 10000; - private static int fDefaultBlockSize = 1000; + private static int BLOCK_SIZE = 1000; private static ITmfTrace[] fTraces; private static TmfExperiment fExperiment; @@ -109,7 +112,6 @@ public class TmfExperimentTest extends TestCase { public void testBasicTmfExperimentConstructor() { assertEquals("GetId", EXPERIMENT, fExperiment.getName()); - assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch()); assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents(); @@ -131,422 +133,291 @@ public class TmfExperimentTest extends TestCase { assertTrue("Checkpoints exist", checkpoints != null); // Validate that each checkpoint points to the right event - for (int i = 0; i < checkpoints.size(); i++) { - final TmfCheckpoint checkpoint = checkpoints.get(i); + long expectedTS = 1; + for (TmfCheckpoint checkpoint : checkpoints) { final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation()); - final ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event rank", i * pageSize, context.getRank()); + final ITmfEvent event = fExperiment.readNextEvent(context); + assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); + assertEquals("Timestamp", expectedTS, checkpoint.getTimestamp().getValue()); + expectedTS += pageSize; } } // ------------------------------------------------------------------------ - // seekLocation + // seekEvent on rank // ------------------------------------------------------------------------ - public void testSeekLocationOnCacheBoundary() throws Exception { + public void testSeekRankOnCacheBoundary() throws Exception { - // Position trace at event rank 0 - TmfContext context = fExperiment.seekEvent(0); - assertEquals("Event rank", 0, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); + // On lower bound, returns the first event (TS = 1) + ITmfContext context = fExperiment.seekEvent(0); + assertEquals("Context rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 2, context.getRank()); - - // Position trace at event rank 1000 - TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 1000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank [cacheSize] + context = fExperiment.seekEvent(cacheSize); + assertEquals("Context rank", cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 1, context.getRank()); - // Position trace at event rank 4000 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 4000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank [4 * cacheSize] + context = fExperiment.seekEvent(4 * cacheSize); + assertEquals("Context rank", 4 * cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); - - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4002, event.getTimestamp().getValue()); - assertEquals("Event rank", 4002, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } - public void testSeekLocationNotOnCacheBoundary() throws Exception { + public void testSeekRankNotOnCacheBoundary() throws Exception { - // Position trace at event rank 9 - TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); - TmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 9, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + // Position trace at event rank 9 + ITmfContext context = fExperiment.seekEvent(9); + assertEquals("Context rank", 9, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + assertEquals("Context rank", 10, context.getRank()); - // Position trace at event rank 999 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + // Position trace at event rank [cacheSize - 1] + context = fExperiment.seekEvent(cacheSize - 1); + assertEquals("Context rank", cacheSize - 1, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize, context.getRank()); - // Position trace at event rank 1001 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 1001, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank [cacheSize + 1] + context = fExperiment.seekEvent(cacheSize + 1); + assertEquals("Context rank", cacheSize + 1, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 2, context.getRank()); // Position trace at event rank 4500 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 4500, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); + context = fExperiment.seekEvent(4500); + assertEquals("Context rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Context rank", 4501, context.getRank()); } - public void testSeekLocationOutOfScope() throws Exception { + public void testSeekRankOutOfScope() throws Exception { // Position trace at beginning - TmfContext tmpContext = fExperiment.seekEvent(0); - final TmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 0, context.getRank()); - - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + ITmfContext context = fExperiment.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); // Position trace at event passed the end - tmpContext = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - assertEquals("Event location", null, tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, tmpContext.getRank()); + context = fExperiment.seekEvent(NB_EVENTS); + assertEquals("Context rank", NB_EVENTS, context.getRank()); + + event = fExperiment.readNextEvent(context); + assertNull("Event", event); + assertEquals("Context rank", NB_EVENTS, context.getRank()); } // ------------------------------------------------------------------------ // seekEvent on timestamp // ------------------------------------------------------------------------ - public void testSeekEventOnTimestampOnCacheBoundary() throws Exception { + public void testSeekTimestampOnCacheBoundary() throws Exception { - // Position trace at event rank 0 - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); - assertEquals("Event rank", 0, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); + // Position trace at event rank 0 + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); + assertEquals("Context rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - // Position trace at event rank 1000 - context = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0)); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + // Position trace at event rank [cacheSize] + context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0)); + assertEquals("Event rank", cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 1, context.getRank()); - // Position trace at event rank 4000 - context = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0)); - assertEquals("Event rank", 4000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank [4 * cacheSize] + context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0)); + assertEquals("Context rank", 4 * cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } - public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception { + public void testSeekTimestampNotOnCacheBoundary() throws Exception { - // Position trace at event rank 1 - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); - assertEquals("Event rank", 1, context.getRank()); + // Position trace at event rank 1 (TS = 2) + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); + assertEquals("Context rank", 1, context.getRank()); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 2, context.getRank()); + assertEquals("Context rank", 2, context.getRank()); - // Position trace at event rank 9 + // Position trace at event rank 9 (TS = 10) context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); - assertEquals("Event rank", 9, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + assertEquals("Context rank", 9, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + assertEquals("Context rank", 10, context.getRank()); - // Position trace at event rank 999 + // Position trace at event rank 999 (TS = 1000) context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + assertEquals("Context rank", 999, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1000, context.getRank()); - // Position trace at event rank 1001 + // Position trace at event rank 1001 (TS = 1002) context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); - assertEquals("Event rank", 1001, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Context rank", 1001, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Context rank", 1002, context.getRank()); - // Position trace at event rank 4500 + // Position trace at event rank 4500 (TS = 4501) context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); - assertEquals("Event rank", 4500, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); + assertEquals("Context rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Context rank", 4501, context.getRank()); } - public void testSeekEventOnTimestampoutOfScope() throws Exception { + public void testSeekTimestampOutOfScope() throws Exception { // Position trace at beginning - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); - assertEquals("Event rank", 0, context.getRank()); - - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); assertEquals("Event rank", 1, context.getRank()); // Position trace at event passed the end context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - assertEquals("Event location", null, context.getLocation()); + event = fExperiment.readNextEvent(context); + assertNull("Event location", event); assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } // ------------------------------------------------------------------------ - // seekEvent on rank + // seekEvent by location (context rank is undefined) // ------------------------------------------------------------------------ - public void testSeekOnRankOnCacheBoundary() throws Exception { + public void testSeekLocationOnCacheBoundary() throws Exception { + + long cacheSize = fExperiment.getCacheSize(); - // On lower bound, returns the first event (ts = 1) - TmfContext context = fExperiment.seekEvent(0); - assertEquals("Event rank", 0, context.getRank()); + // Position trace at event rank 0 + ITmfContext tmpContext = fExperiment.seekEvent(0); + ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - ITmfEvent event = fExperiment.parseEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); + assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - // Position trace at event rank 1000 - context = fExperiment.seekEvent(1000); - assertEquals("Event rank", 1000, context.getRank()); + // Position trace at event rank 'cacheSize' + tmpContext = fExperiment.seekEvent(cacheSize); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); - // Position trace at event rank 4000 - context = fExperiment.seekEvent(4000); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank 4 * 'cacheSize' + tmpContext = fExperiment.seekEvent(4 * cacheSize); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); } - public void testSeekOnRankNotOnCacheBoundary() throws Exception { - - // Position trace at event rank 9 - TmfContext context = fExperiment.seekEvent(9); - assertEquals("Event rank", 9, context.getRank()); + public void testSeekLocationNotOnCacheBoundary() throws Exception { - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + // Position trace at event 'cacheSize' - 1 + ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1); + ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - // Position trace at event rank 999 - context = fExperiment.seekEvent(999); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + ITmfEvent event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); - // Position trace at event rank 1001 - context = fExperiment.seekEvent(1001); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank 2 * 'cacheSize' - 1 + tmpContext = fExperiment.seekEvent(2 * cacheSize - 1); + context = fExperiment.seekEvent(tmpContext.getLocation()); + context = fExperiment.seekEvent(2 * cacheSize - 1); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue()); // Position trace at event rank 4500 - context = fExperiment.seekEvent(4500); - assertEquals("Event rank", 4500, context.getRank()); + tmpContext = fExperiment.seekEvent(4500); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); + event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); } - public void testSeekEventOnRankOutOfScope() throws Exception { + public void testSeekLocationOutOfScope() throws Exception { // Position trace at beginning - TmfContext context = fExperiment.seekEvent(-1); - assertEquals("Event rank", 0, context.getRank()); + ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); - - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - // Position trace at event passed the end - context = fExperiment.seekEvent(NB_EVENTS); - assertEquals("Event location", null, context.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } // ------------------------------------------------------------------------ - // parseEvent - make sure parseEvent doesn't update the context - // Note: This test is essentially the same as the one from TmfTraceTest + // readtNextEvent - updates the context // ------------------------------------------------------------------------ - public void testParseEvent() throws Exception { - - final int NB_READS = 20; - - // On lower bound, returns the first event (ts = 1) - final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0)); - - // Read NB_EVENTS - ITmfEvent event = null;; - for (int i = 0; i < NB_READS; i++) { - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", i + 1, context.getRank()); - } - - // Make sure we stay positioned - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS, context.getRank()); - } - - // ------------------------------------------------------------------------ - // getNextEvent - updates the context - // ------------------------------------------------------------------------ - - public void testGetNextEvent() throws Exception { + public void testReadNextEvent() throws Exception { // On lower bound, returns the first event (ts = 0) - final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0)); + final ITmfContext context = fExperiment.seekEvent(0); ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); @@ -652,7 +523,7 @@ public class TmfExperimentTest extends TestCase { public void testCancel() throws Exception { final int nbEvents = NB_EVENTS; - final int blockSize = fDefaultBlockSize; + final int blockSize = BLOCK_SIZE; final Vector requestedEvents = new Vector(); final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); @@ -681,21 +552,6 @@ public class TmfExperimentTest extends TestCase { assertTrue("isCancelled", request.isCancelled()); } - // ------------------------------------------------------------------------ - // getRank - // ------------------------------------------------------------------------ - - // public void testGetRank() throws Exception { - // - // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp())); - // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp( 1, (byte) -3))); - // assertEquals("getRank", 10, fExperiment.getRank(new TmfTimestamp( 11, (byte) -3))); - // assertEquals("getRank", 100, fExperiment.getRank(new TmfTimestamp( 101, (byte) -3))); - // assertEquals("getRank", 1000, fExperiment.getRank(new TmfTimestamp(1001, (byte) -3))); - // assertEquals("getRank", 2000, fExperiment.getRank(new TmfTimestamp(2001, (byte) -3))); - // assertEquals("getRank", 2500, fExperiment.getRank(new TmfTimestamp(2501, (byte) -3))); - // } - // ------------------------------------------------------------------------ // getTimestamp // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java index bd27477611..76f9d1c95d 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adjusted for new Trace Model *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.experiment; @@ -32,19 +33,21 @@ import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; -import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** - * TmfExperimentTest - *

- * TODO: Implement me. Please. + * Test suite for the TmfExperiment class (multiple traces). */ @SuppressWarnings("nls") public class TmfMultiTraceExperimentTest extends TestCase { + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM1 = "O-Test-10K"; private static final String TEST_STREAM2 = "E-Test-10K"; @@ -116,7 +119,6 @@ public class TmfMultiTraceExperimentTest extends TestCase { public void testBasicTmfExperimentConstructor() { assertEquals("GetId", EXPERIMENT, fExperiment.getName()); - assertEquals("GetEpoch", TmfTimestamp.ZERO, fExperiment.getEpoch()); assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); final TmfTimeRange timeRange = fExperiment.getTimeRange(); @@ -135,422 +137,291 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertTrue("Checkpoints exist", checkpoints != null); // Validate that each checkpoint points to the right event - for (int i = 0; i < checkpoints.size(); i++) { - final TmfCheckpoint checkpoint = checkpoints.get(i); + long expectedTS = 1; + for (TmfCheckpoint checkpoint : checkpoints) { final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation()); - final ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event rank", context.getRank(), i * pageSize); + final ITmfEvent event = fExperiment.readNextEvent(context); + assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); + assertEquals("Timestamp", expectedTS, checkpoint.getTimestamp().getValue()); + expectedTS += pageSize; } } // ------------------------------------------------------------------------ - // seekLocation + // seekEvent on rank // ------------------------------------------------------------------------ - public void testSeekLocationOnCacheBoundary() throws Exception { + public void testSeekRankOnCacheBoundary() throws Exception { - // Position trace at event rank 0 - TmfContext context = fExperiment.seekEvent(0); - assertEquals("Event rank", 0, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); + // On lower bound, returns the first event (TS = 1) + ITmfContext context = fExperiment.seekEvent(0); + assertEquals("Context rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 2, context.getRank()); - - // Position trace at event rank 1000 - TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 1000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank [cacheSize] + context = fExperiment.seekEvent(cacheSize); + assertEquals("Context rank", cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 1, context.getRank()); - // Position trace at event rank 4000 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 4000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank [4 * cacheSize] + context = fExperiment.seekEvent(4 * cacheSize); + assertEquals("Context rank", 4 * cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); - - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4002, event.getTimestamp().getValue()); - assertEquals("Event rank", 4002, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } - public void testSeekLocationNotOnCacheBoundary() throws Exception { + public void testSeekRankNotOnCacheBoundary() throws Exception { - // Position trace at event rank 9 - TmfContext tmpContext = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); - TmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 9, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + // Position trace at event rank 9 + ITmfContext context = fExperiment.seekEvent(9); + assertEquals("Context rank", 9, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + assertEquals("Context rank", 10, context.getRank()); - // Position trace at event rank 999 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + // Position trace at event rank [cacheSize - 1] + context = fExperiment.seekEvent(cacheSize - 1); + assertEquals("Context rank", cacheSize - 1, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize, context.getRank()); - // Position trace at event rank 1001 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 1001, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank [cacheSize + 1] + context = fExperiment.seekEvent(cacheSize + 1); + assertEquals("Context rank", cacheSize + 1, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 2, context.getRank()); // Position trace at event rank 4500 - tmpContext = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); - context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 4500, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); + context = fExperiment.seekEvent(4500); + assertEquals("Context rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Context rank", 4501, context.getRank()); } - public void testSeekLocationOutOfScope() throws Exception { + public void testSeekRankOutOfScope() throws Exception { // Position trace at beginning - TmfContext tmpContext = fExperiment.seekEvent(0); - final TmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", 0, context.getRank()); - - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + ITmfContext context = fExperiment.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); // Position trace at event passed the end - tmpContext = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - assertEquals("Event location", null, tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, tmpContext.getRank()); + context = fExperiment.seekEvent(NB_EVENTS); + assertEquals("Context rank", NB_EVENTS, context.getRank()); + + event = fExperiment.readNextEvent(context); + assertNull("Event", event); + assertEquals("Context rank", NB_EVENTS, context.getRank()); } // ------------------------------------------------------------------------ // seekEvent on timestamp // ------------------------------------------------------------------------ - public void testSeekEventOnTimestampOnCacheBoundary() throws Exception { + public void testSeekTimestampOnCacheBoundary() throws Exception { - // Position trace at event rank 0 - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); - assertEquals("Event rank", 0, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); + // Position trace at event rank 0 + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); + assertEquals("Context rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - // Position trace at event rank 1000 - context = fExperiment.seekEvent(new TmfTimestamp(1001, SCALE, 0)); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1, context.getRank()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + // Position trace at event rank [cacheSize] + context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0)); + assertEquals("Event rank", cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", cacheSize + 1, context.getRank()); - // Position trace at event rank 4000 - context = fExperiment.seekEvent(new TmfTimestamp(4001, SCALE, 0)); - assertEquals("Event rank", 4000, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank [4 * cacheSize] + context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0)); + assertEquals("Context rank", 4 * cacheSize, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); + assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } - public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception { + public void testSeekTimestampNotOnCacheBoundary() throws Exception { - // Position trace at event rank 1 - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); - assertEquals("Event rank", 1, context.getRank()); + // Position trace at event rank 1 (TS = 2) + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); + assertEquals("Context rank", 1, context.getRank()); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - assertEquals("Event rank", 2, context.getRank()); + assertEquals("Context rank", 2, context.getRank()); - // Position trace at event rank 9 + // Position trace at event rank 9 (TS = 10) context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); - assertEquals("Event rank", 9, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + assertEquals("Context rank", 9, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + assertEquals("Context rank", 10, context.getRank()); - // Position trace at event rank 999 + // Position trace at event rank 999 (TS = 1000) context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + assertEquals("Context rank", 999, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Context rank", 1000, context.getRank()); - // Position trace at event rank 1001 + // Position trace at event rank 1001 (TS = 1002) context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); - assertEquals("Event rank", 1001, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Context rank", 1001, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Context rank", 1002, context.getRank()); - // Position trace at event rank 4500 + // Position trace at event rank 4500 (TS = 4501) context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); - assertEquals("Event rank", 4500, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); + assertEquals("Context rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Context rank", 4501, context.getRank()); } - public void testSeekEventOnTimestampOutOfScope() throws Exception { + public void testSeekTimestampOutOfScope() throws Exception { // Position trace at beginning - TmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); - assertEquals("Event rank", 0, context.getRank()); - - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); assertEquals("Event rank", 1, context.getRank()); // Position trace at event passed the end context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - assertEquals("Event location", null, context.getLocation()); + event = fExperiment.readNextEvent(context); + assertNull("Event location", event); assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } // ------------------------------------------------------------------------ - // seekEvent on rank + // seekEvent by location (context rank is undefined) // ------------------------------------------------------------------------ - public void testSeekOnRankOnCacheBoundary() throws Exception { + public void testSeekLocationOnCacheBoundary() throws Exception { + + long cacheSize = fExperiment.getCacheSize(); - // On lower bound, returns the first event (ts = 1) - TmfContext context = fExperiment.seekEvent(0); - assertEquals("Event rank", 0, context.getRank()); + // Position trace at event rank 0 + ITmfContext tmpContext = fExperiment.seekEvent(0); + ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - ITmfEvent event = fExperiment.parseEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); + assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); - // Position trace at event rank 1000 - context = fExperiment.seekEvent(1000); - assertEquals("Event rank", 1000, context.getRank()); + // Position trace at event rank 'cacheSize' + tmpContext = fExperiment.seekEvent(cacheSize); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); - // Position trace at event rank 4000 - context = fExperiment.seekEvent(4000); - assertEquals("Event rank", 4000, context.getRank()); + // Position trace at event rank 4 * 'cacheSize' + tmpContext = fExperiment.seekEvent(4 * cacheSize); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4000, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", 4001, context.getRank()); + assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); } - public void testSeekOnRankNotOnCacheBoundary() throws Exception { - - // Position trace at event rank 9 - TmfContext context = fExperiment.seekEvent(9); - assertEquals("Event rank", 9, context.getRank()); + public void testSeekLocationNotOnCacheBoundary() throws Exception { - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 9, context.getRank()); + long cacheSize = fExperiment.getCacheSize(); - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", 10, context.getRank()); + // Position trace at event 'cacheSize' - 1 + ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1); + ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); - // Position trace at event rank 999 - context = fExperiment.seekEvent(999); - assertEquals("Event rank", 999, context.getRank()); - - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 999, context.getRank()); + ITmfEvent event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", 1000, context.getRank()); + assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); - // Position trace at event rank 1001 - context = fExperiment.seekEvent(1001); - assertEquals("Event rank", 1001, context.getRank()); + // Position trace at event rank 2 * 'cacheSize' - 1 + tmpContext = fExperiment.seekEvent(2 * cacheSize - 1); + context = fExperiment.seekEvent(tmpContext.getLocation()); + context = fExperiment.seekEvent(2 * cacheSize - 1); - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1001, context.getRank()); + event = fExperiment.readNextEvent(context); + assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", 1002, context.getRank()); + assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue()); // Position trace at event rank 4500 - context = fExperiment.seekEvent(4500); - assertEquals("Event rank", 4500, context.getRank()); + tmpContext = fExperiment.seekEvent(4500); + context = fExperiment.seekEvent(tmpContext.getLocation()); - event = fExperiment.parseEvent(context); + event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4500, context.getRank()); event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", 4501, context.getRank()); + assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); } - public void testSeekEventOnRankOutOfScope() throws Exception { + public void testSeekLocationOutOfScope() throws Exception { // Position trace at beginning - TmfContext context = fExperiment.seekEvent(-1); - assertEquals("Event rank", 0, context.getRank()); + ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); - ITmfEvent event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); - - event = fExperiment.readNextEvent(context); + ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 1, context.getRank()); - - // Position trace at event passed the end - context = fExperiment.seekEvent(NB_EVENTS); - assertEquals("Event location", null, context.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } // ------------------------------------------------------------------------ - // parseEvent - make sure parseEvent doesn't update the context - // Note: This test is essentially the same as the one from TmfTraceTest + // readtNextEvent - updates the context // ------------------------------------------------------------------------ - public void testParseEvent() throws Exception { - - final int NB_READS = 20; - - // On lower bound, returns the first event (ts = 1) - final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0)); - - // Read NB_EVENTS - ITmfEvent event = null;; - for (int i = 0; i < NB_READS; i++) { - event = fExperiment.readNextEvent(context); - assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", i + 1, context.getRank()); - } - - // Make sure we stay positioned - event = fExperiment.parseEvent(context); - assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS, context.getRank()); - } - - // ------------------------------------------------------------------------ - // getNextEvent - updates the context - // ------------------------------------------------------------------------ - - public void testGetNextEvent() throws Exception { + public void testReadNextEvent() throws Exception { // On lower bound, returns the first event (ts = 0) - final TmfContext context = fExperiment.seekEvent(new TmfTimestamp(0, SCALE, 0)); + final ITmfContext context = fExperiment.seekEvent(0); ITmfEvent event = fExperiment.readNextEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); @@ -685,21 +556,6 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertTrue("isCancelled", request.isCancelled()); } - // ------------------------------------------------------------------------ - // getRank - // ------------------------------------------------------------------------ - - // public void testGetRank() throws Exception { - // - // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp())); - // assertEquals("getRank", 0, fExperiment.getRank(new TmfTimestamp( 1, (byte) -3))); - // assertEquals("getRank", 10, fExperiment.getRank(new TmfTimestamp( 11, (byte) -3))); - // assertEquals("getRank", 100, fExperiment.getRank(new TmfTimestamp( 101, (byte) -3))); - // assertEquals("getRank", 1000, fExperiment.getRank(new TmfTimestamp(1001, (byte) -3))); - // assertEquals("getRank", 2000, fExperiment.getRank(new TmfTimestamp(2001, (byte) -3))); - // assertEquals("getRank", 2500, fExperiment.getRank(new TmfTimestamp(2501, (byte) -3))); - // } - // ------------------------------------------------------------------------ // getTimestamp // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java index e5d304222d..167d55a405 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java @@ -19,8 +19,7 @@ import junit.framework.TestSuite; import org.eclipse.linuxtools.internal.tmf.core.TmfCorePlugin; /** - * AllTests - *

+ * Test suite for org.eclipse.linuxtools.tmf.core.trace */ @SuppressWarnings("nls") public class AllTests { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java index f61a8a9590..2371d82612 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 20112 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -17,7 +17,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; -import java.util.Vector; +import java.util.List; import junit.framework.TestCase; @@ -33,9 +33,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** - * TmfTraceTest - *

- * Test suite for the TmfTrace class. + * Test suite for the TmfCheckpointIndexTest class. */ @SuppressWarnings("nls") public class TmfCheckpointIndexTest extends TestCase { @@ -80,18 +78,19 @@ public class TmfCheckpointIndexTest extends TestCase { public TestIndexer(TestTrace testTrace) { super((ITmfTrace) testTrace); } - public Vector getCheckpoints() { - return fTraceIndex; + public List getCheckpoints() { + return getTraceIndex(); } } private class TestTrace extends TmfTraceStub { public TestTrace(String path, int blockSize) throws TmfTraceException { super(path, blockSize); - fIndexer = new TestIndexer(this); + setIndexer(new TestIndexer(this)); } + @Override public TestIndexer getIndexer() { - return (TestIndexer) fIndexer; + return (TestIndexer) super.getIndexer(); } } @@ -129,7 +128,7 @@ public class TmfCheckpointIndexTest extends TestCase { assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); - Vector checkpoints = fTrace.getIndexer().getCheckpoints(); + List checkpoints = fTrace.getIndexer().getCheckpoints(); int pageSize = fTrace.getCacheSize(); assertTrue("Checkpoints exist", checkpoints != null); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java index d9d32d3f10..55e373b86f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adapted for TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -20,8 +21,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; /** - * TmfCheckpointTest - *

* Test suite for the TmfCheckpoint class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java index 9eb3db9115..6dd13f1192 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adapted for TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -21,8 +22,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; /** - * TmfContextTest - *

* Test suite for the TmfContext class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java index af7c07797e..a0cf96e777 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java @@ -19,8 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; /** - * TmfLocationTest - *

* Test suite for the TmfLocation class. */ @SuppressWarnings("nls") diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index a6d63b90b4..0f352f1c98 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 20112 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -35,14 +35,12 @@ import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; -import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** - * TmfTraceTest - *

* Test suite for the TmfTrace class. */ @SuppressWarnings("nls") @@ -125,7 +123,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertNull ("getResource", trace.getResource()); assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", TEST_STREAM, trace.getName()); @@ -154,7 +152,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertNull ("getResource", trace.getResource()); assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", TEST_STREAM, trace.getName()); @@ -327,7 +325,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertNull ("getResource", trace.getResource()); assertEquals("getPath", path, trace.getPath()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", path, trace.getName()); @@ -356,7 +354,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertNull ("getResource", trace.getResource()); assertEquals("getPath", path, trace.getPath()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", name, trace.getName()); @@ -375,7 +373,7 @@ public class TmfTraceTest extends TestCase { assertFalse ("Open trace", trace == null); assertNull ("getType", trace.getType()); assertNull ("getResource", trace.getResource()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", "", trace.getName()); @@ -404,7 +402,7 @@ public class TmfTraceTest extends TestCase { assertFalse ("Open trace", trace == null); assertEquals("getType", TmfEvent.class, trace.getType()); assertNull ("getResource", trace.getResource()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); assertEquals("getName", TEST_STREAM, trace.getName()); @@ -619,17 +617,12 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); // Position trace at event passed the end - tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - context = fTrace.seekEvent(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", null, event); + context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); + assertNull("Event timestamp", context.getLocation()); assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); event = fTrace.readNextEvent(context); - assertEquals("Event timestamp", null, event); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); + assertNull("Event", event); } // ------------------------------------------------------------------------ @@ -765,15 +758,15 @@ public class TmfTraceTest extends TestCase { // Position trace at event passed the end context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - assertEquals("Event rank", NB_EVENTS, context.getRank()); + assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); event = fTrace.parseEvent(context); assertEquals("Event timestamp", null, event); - assertEquals("Event rank", NB_EVENTS, context.getRank()); + assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); event = fTrace.readNextEvent(context); assertEquals("Event timestamp", null, event); - assertEquals("Event rank", NB_EVENTS, context.getRank()); + assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } // ------------------------------------------------------------------------ @@ -881,7 +874,7 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 4501, context.getRank()); } - public void testSeekEventOnRankOfScope() throws Exception { + public void testSeekEventOnRankOutOfScope() throws Exception { // Position trace at beginning ITmfContext context = fTrace.seekEvent(-1); @@ -900,11 +893,11 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", NB_EVENTS, context.getRank()); event = fTrace.parseEvent(context); - assertEquals("Event timestamp", null, event); + assertNull("Event", event); assertEquals("Event rank", NB_EVENTS, context.getRank()); event = fTrace.readNextEvent(context); - assertEquals("Event timestamp", null, event); + assertNull("Event", event); assertEquals("Event rank", NB_EVENTS, context.getRank()); } diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEventParserStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEventParserStub.java index 47f64a6f8e..44b51f8913 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEventParserStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEventParserStub.java @@ -82,35 +82,35 @@ public class TmfEventParserStub implements ITmfEventParser { // no need to use synchronized since it's already cover by the calling method long location = 0; - if (context != null) + if (context != null && context.getLocation() != null) { location = ((TmfLocation) (context.getLocation())).getLocation(); - - try { - stream.seek(location); - - final long ts = stream.readLong(); - final String source = stream.readUTF(); - final String type = stream.readUTF(); - final Integer reference = stream.readInt(); - final int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); - final String[] fields = new String[typeIndex]; - for (int i = 0; i < typeIndex; i++) - fields[i] = stream.readUTF(); - - final StringBuffer content = new StringBuffer("["); - if (typeIndex > 0) - content.append(fields[0]); - for (int i = 1; i < typeIndex; i++) - content.append(", ").append(fields[i]); - content.append("]"); - - final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString()); - final TmfEvent event = new TmfEvent(fEventStream, - new TmfTimestamp(ts, -3, 0), // millisecs - source, fTypes[typeIndex], root, reference.toString()); - return event; - } catch (final EOFException e) { - } catch (final IOException e) { + try { + stream.seek(location); + + final long ts = stream.readLong(); + final String source = stream.readUTF(); + final String type = stream.readUTF(); + final Integer reference = stream.readInt(); + final int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); + final String[] fields = new String[typeIndex]; + for (int i = 0; i < typeIndex; i++) + fields[i] = stream.readUTF(); + + final StringBuffer content = new StringBuffer("["); + if (typeIndex > 0) + content.append(fields[0]); + for (int i = 1; i < typeIndex; i++) + content.append(", ").append(fields[i]); + content.append("]"); + + final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString()); + final TmfEvent event = new TmfEvent(fEventStream, + new TmfTimestamp(ts, -3, 0), // millisecs + source, fTypes[typeIndex], root, reference.toString()); + return event; + } catch (final EOFException e) { + } catch (final IOException e) { + } } return null; } diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java index b123368310..f038420de1 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java @@ -26,6 +26,7 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; @@ -62,7 +63,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< */ public TmfTraceStub() { super(); - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); } /** @@ -70,7 +71,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< * @throws FileNotFoundException */ public TmfTraceStub(final String path) throws TmfTraceException { - this(path, DEFAULT_TRACE_CACHE_SIZE, false); + this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false); } /** @@ -94,7 +95,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); } /** @@ -112,7 +113,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< * @throws FileNotFoundException */ public TmfTraceStub(final String path, final boolean waitForCompletion) throws TmfTraceException { - this(path, DEFAULT_TRACE_CACHE_SIZE, waitForCompletion); + this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, waitForCompletion); } /** @@ -128,7 +129,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); } /** @@ -144,7 +145,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); } /** @@ -162,7 +163,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = (parser != null) ? parser : new TmfEventParserStub(this); + setParser((parser != null) ? parser : new TmfEventParserStub(this)); } /** @@ -175,11 +176,11 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); } public void indexTrace() { - fIndexer.buildIndex(true); + getIndexer().buildIndex(true); } @Override @@ -189,7 +190,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< } catch (FileNotFoundException e) { throw new TmfTraceException(e.getMessage()); } - fParser = new TmfEventParserStub(this); + setParser(new TmfEventParserStub(this)); super.initTrace(resource, path, type); } @@ -299,13 +300,10 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser< fLock.lock(); try { // parseNextEvent will update the context - if (fTrace != null) { - final TmfEvent event = fParser.parseEvent(context.clone()); + if (fTrace != null && getParser() != null && context != null) { + final TmfEvent event = getParser().parseEvent(context.clone()); return event; } -// } -// catch (final IOException e) { -// e.printStackTrace(); } finally { fLock.unlock(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java index a3ffdcacff..eac36207e4 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java @@ -28,7 +28,6 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; * used as e.g. a location marker (filename:lineno) to indicate where the event * was generated. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * @@ -37,7 +36,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; * @see ITmfEventField * @see TmfEvent */ -public interface ITmfEvent extends Cloneable { +public interface ITmfEvent { // ------------------------------------------------------------------------ // Constants @@ -107,10 +106,6 @@ public interface ITmfEvent extends Cloneable { */ public String getReference(); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the event */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java index 0168e5fd76..7efb44dfaf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java @@ -16,14 +16,13 @@ package org.eclipse.linuxtools.tmf.core.event; * The generic event payload in TMF. Each field can be either a terminal or * further decomposed into subfields. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfEvent * @see ITmfEventType */ -public interface ITmfEventField extends Cloneable { +public interface ITmfEventField { // ------------------------------------------------------------------------ // Constants @@ -73,10 +72,6 @@ public interface ITmfEventField extends Cloneable { */ public ITmfEventField getField(int index); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the event field */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventType.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventType.java index e653471e3c..d3e8e690a9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventType.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventType.java @@ -18,14 +18,13 @@ package org.eclipse.linuxtools.tmf.core.event; *

* Types are unique within their context space. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfEvent * @see ITmfEventField */ -public interface ITmfEventType extends Cloneable { +public interface ITmfEventType { // ------------------------------------------------------------------------ // Constants @@ -71,10 +70,6 @@ public interface ITmfEventType extends Cloneable { */ public String getFieldName(int index); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the event type */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java index a5804edfd1..d51fd59030 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfTimestamp.java @@ -28,14 +28,13 @@ package org.eclipse.linuxtools.tmf.core.event; * timestamps in different scales). Default: 0. * * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfEvent * @see TmfTimeRange */ -public interface ITmfTimestamp extends Cloneable, Comparable { +public interface ITmfTimestamp extends Comparable { // ------------------------------------------------------------------------ // Getters @@ -86,10 +85,6 @@ public interface ITmfTimestamp extends Cloneable, Comparable { */ public ITmfTimestamp getDelta(ITmfTimestamp ts); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the timestamp */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java index 6e6ac3bb2b..c5d8299fd2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java @@ -23,7 +23,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; * copy of the event is needed, use the copy constructor. Otherwise (deep copy) * use clone(). * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * @@ -32,7 +31,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; * @see ITmfEventField * @see ITmfTrace */ -public class TmfEvent implements ITmfEvent { +public class TmfEvent implements ITmfEvent, Cloneable { // ------------------------------------------------------------------------ // Attributes diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java index 6d1ed59824..100e5ae478 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java @@ -23,14 +23,13 @@ import java.util.Map; * Non-value fields are structural (i.e. used to represent the event structure * including optional fields) while the valued fields are actual event fields. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfEvent * @see ITmfEventType */ -public class TmfEventField implements ITmfEventField { +public class TmfEventField implements ITmfEventField, Cloneable { // ------------------------------------------------------------------------ // Attributes diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventType.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventType.java index 48577ab2dd..14cff763c6 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventType.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventType.java @@ -16,14 +16,13 @@ package org.eclipse.linuxtools.tmf.core.event; /** * A basic implementation of ITmfEventType. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfEvent * @see ITmfEventField */ -public class TmfEventType implements ITmfEventType { +public class TmfEventType implements ITmfEventType, Cloneable { // ------------------------------------------------------------------------ // Attributes diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java index 8daf10b148..5f170c7f9a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java @@ -19,7 +19,6 @@ import java.util.Map; * A central repository for the available event types. Types are managed by * context space. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java index e99b779758..6ec7f3c428 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java @@ -15,11 +15,10 @@ package org.eclipse.linuxtools.tmf.core.event; /** * A simplified timestamp where scale and precision are set to 0. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard */ -public class TmfSimpleTimestamp extends TmfTimestamp { +public class TmfSimpleTimestamp extends TmfTimestamp implements Cloneable { // ------------------------------------------------------------------------ // Constructors @@ -61,7 +60,7 @@ public class TmfSimpleTimestamp extends TmfTimestamp { * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#normalize(long, int) */ @Override - public ITmfTimestamp normalize(final long offset, final int scale) throws ArithmeticException { + public ITmfTimestamp normalize(final long offset, final int scale) { if (scale == 0) { return new TmfSimpleTimestamp(getValue() + offset); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java index 794d3746a1..71886dbbd2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java @@ -16,7 +16,6 @@ package org.eclipse.linuxtools.tmf.core.event; /** * A utility class to define and manage time ranges. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * @@ -163,7 +162,7 @@ public final class TmfTimeRange implements Cloneable { * @see java.lang.Object#clone() */ @Override - public TmfTimeRange clone() { + public TmfTimeRange clone() throws CloneNotSupportedException { TmfTimeRange clone = null; try { clone = (TmfTimeRange) super.clone(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java index 7264468d2a..601ac3f829 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java @@ -14,11 +14,11 @@ package org.eclipse.linuxtools.tmf.core.event; + /** * A generic timestamp implementation. The timestamp is represented by the * tuple { value, scale, precision }. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard */ @@ -186,7 +186,7 @@ public class TmfTimestamp implements ITmfTimestamp, Cloneable { * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#normalize(long, int) */ @Override - public ITmfTimestamp normalize(final long offset, final int scale) throws ArithmeticException { + public ITmfTimestamp normalize(final long offset, final int scale) { long value = fValue; int precision = fPrecision; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index 7565efb231..5a4303d59d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,11 +8,11 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Updated as per TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.experiment; -import java.util.Collections; import java.util.Vector; import org.eclipse.core.resources.IFile; @@ -22,11 +22,11 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; @@ -37,46 +37,41 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; -import org.eclipse.linuxtools.tmf.core.trace.TmfContext; +import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; +import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; /** - * TmfExperiment - *

* TmfExperiment presents a time-ordered, unified view of a set of TmfTraces * that are part of a tracing experiment. - *

*/ -public class TmfExperiment extends TmfEventProvider implements ITmfTrace { +public class TmfExperiment extends TmfTrace implements ITmfEventParser { // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ // The currently selected experiment - protected static TmfExperiment fCurrentExperiment = null; + private static TmfExperiment fCurrentExperiment = null; // The set of traces that constitute the experiment - protected ITmfTrace[] fTraces; - - // The total number of events - protected long fNbEvents; + private ITmfTrace[] fTraces; // The experiment time range - protected TmfTimeRange fTimeRange; + private TmfTimeRange fTimeRange; - // The experiment reference timestamp (default: ZERO) - protected ITmfTimestamp fEpoch; + // The total number of events + private long fNbEvents; // The experiment index - protected Vector fCheckpoints = new Vector(); + private Vector fCheckpoints = new Vector(); // The current experiment context - protected TmfExperimentContext fExperimentContext; + private TmfExperimentContext fExperimentContext; // Flag to initialize only once private boolean fInitialized = false; @@ -91,11 +86,6 @@ public class TmfExperiment extends TmfEventProvider impl // Constructors // ------------------------------------------------------------------------ - @Override - public TmfExperiment clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); - } - @Override public boolean validate(final IProject project, final String path) { return true; @@ -112,35 +102,62 @@ public class TmfExperiment extends TmfEventProvider impl * @param traces * @param epoch * @param indexPageSize + * @throws TmfTraceException */ public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final ITmfTimestamp epoch, - final int indexPageSize) { + final int indexPageSize) + { this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false); } - public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final ITmfTimestamp epoch, - final int indexPageSize, final boolean preIndexExperiment) { - super(id, type); + @SuppressWarnings({ "unchecked", "rawtypes" }) + public TmfExperiment(final Class type, final String path, final ITmfTrace[] traces, final ITmfTimestamp epoch, + final int indexPageSize, final boolean preIndexExperiment) + { + setCacheSize(indexPageSize); + setStreamingInterval(0); + setIndexer(new TmfCheckpointIndexer(this)); + setParser(this); + try { + super.initialize(null, path, type); + } catch (TmfTraceException e) { + e.printStackTrace(); + } fTraces = traces; - fEpoch = epoch; - fIndexPageSize = indexPageSize; fTimeRange = TmfTimeRange.NULL_RANGE; - if (preIndexExperiment) { - indexExperiment(true, 0, TmfTimeRange.ETERNITY); - updateTimeRange(); - } +// if (preIndexExperiment) { +// indexExperiment(true, 0, TmfTimeRange.ETERNITY); +// updateTimeRange(); +// } } - protected TmfExperiment(final String id, final Class type) { - super(id, type); - } +// /** +// * Initialize the trace common attributes and the base component. +// * +// * @param resource the Eclipse resource (trace) +// * @param path the trace path +// * @param type the trace event type +// * +// * @throws TmfTraceException +// */ +// @Override +// @SuppressWarnings("unchecked") +// protected void initialize(final IResource resource, final String path, final Class type) { +// setParser(this); +// super.initialize(resource, path, type); +// } + +// protected TmfExperiment(final String id, final Class type) { +// super(id, type); +// } /** * @param type * @param id * @param traces + * @throws TmfTraceException */ public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces) { this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE); @@ -151,6 +168,7 @@ public class TmfExperiment extends TmfEventProvider impl * @param id * @param traces * @param indexPageSize + * @throws TmfTraceException */ public TmfExperiment(final Class type, final String id, final ITmfTrace[] traces, final int indexPageSize) { this(type, id, traces, TmfTimestamp.ZERO, indexPageSize); @@ -230,10 +248,6 @@ public class TmfExperiment extends TmfEventProvider impl return fCurrentExperiment; } - public ITmfTimestamp getEpoch() { - return fEpoch; - } - public ITmfTrace[] getTraces() { return fTraces; } @@ -246,7 +260,8 @@ public class TmfExperiment extends TmfEventProvider impl * @return the corresponding event timestamp */ public ITmfTimestamp getTimestamp(final int index) { - final TmfExperimentContext context = seekEvent(index); +// final TmfExperimentContext context = seekEvent(index); + final ITmfContext context = seekEvent(index); final ITmfEvent event = readNextEvent(context); return (event != null) ? event.getTimestamp() : null; } @@ -283,7 +298,8 @@ public class TmfExperiment extends TmfEventProvider impl ITmfTimestamp timestamp = (request instanceof ITmfEventRequest) ? ((ITmfEventRequest) request).getRange().getStartTime() : null; if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) timestamp = null; // use request index - TmfExperimentContext context = null; +// TmfExperimentContext context = null; + ITmfContext context = null; if (timestamp != null) { // seek by timestamp context = seekEvent(timestamp); @@ -298,13 +314,13 @@ public class TmfExperiment extends TmfEventProvider impl return context; } - @Override - @SuppressWarnings("unchecked") - public T getNext(final ITmfContext context) { - if (context instanceof TmfExperimentContext) - return (T) readNextEvent(context); - return null; - } +// @Override +// @SuppressWarnings("unchecked") +// public T getNext(final ITmfContext context) { +// if (context instanceof TmfExperimentContext) +// return (T) readNextEvent(context); +// return null; +// } // ------------------------------------------------------------------------ // ITmfTrace trace positioning @@ -323,29 +339,29 @@ public class TmfExperiment extends TmfEventProvider impl // Instantiate the location final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray( - new ITmfLocation[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone(); + new ITmfLocation[fTraces.length])) : (TmfExperimentLocation) location.clone(); // Create and populate the context's traces contexts - final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]); + final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]); // Tracer.trace("Ctx: SeekLocation - start"); - long rank = 0; +// long rank = 0; for (int i = 0; i < fTraces.length; i++) { // Get the relevant trace attributes - final ITmfLocation traceLocation = expLocation.getLocation().locations[i]; - final long traceRank = expLocation.getRanks()[i]; + final ITmfLocation traceLocation = expLocation.getLocation().getLocations()[i]; +// final long traceRank = expLocation.getRanks()[i]; // Set the corresponding sub-context context.getContexts()[i] = fTraces[i].seekEvent(traceLocation); - context.getContexts()[i].setRank(traceRank); - rank += traceRank; +// context.getContexts()[i].setRank(traceRank); +// rank += traceRank; // Set the trace location and read the corresponding event /* * The (TmfContext) cast should be safe since we created 'context' * ourselves higher up. */ - expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone(); + expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone(); context.getEvents()[i] = fTraces[i].readNextEvent(context.getContexts()[i]); } @@ -354,105 +370,137 @@ public class TmfExperiment extends TmfEventProvider impl // Finalize context context.setLocation(expLocation); context.setLastTrace(TmfExperimentContext.NO_TRACE); - context.setRank(rank); +// context.setRank(rank); + context.setRank(ITmfContext.UNKNOWN_RANK); fExperimentContext = context; return context; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp) - */ - @Override - public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) { - - // Tracer.trace("Ctx: seekEvent(TS) - start"); - - if (timestamp == null) - timestamp = TmfTimestamp.BIG_BANG; - - // First, find the right checkpoint - int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null)); - - // In the very likely case that the checkpoint was not found, bsearch - // returns its negated would-be location (not an offset...). From that - // index, we can then position the stream and get the event. - if (index < 0) - index = Math.max(0, -(index + 2)); - - // Position the experiment at the checkpoint - ITmfLocation location; - synchronized (fCheckpoints) { - if (fCheckpoints.size() > 0) { - if (index >= fCheckpoints.size()) - index = fCheckpoints.size() - 1; - location = fCheckpoints.elementAt(index).getLocation(); - } else - location = null; - } - - final TmfExperimentContext context = seekEvent(location); - context.setRank((long) index * fIndexPageSize); - - // And locate the event - ITmfEvent event = parseEvent(context); - while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) { - readNextEvent(context); - event = parseEvent(context); - } - - if (event == null) { - context.setLocation(null); - context.setRank(ITmfContext.UNKNOWN_RANK); - } - - return context; - } +// /* (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp) +// */ +// @Override +// public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) { +// +// // Tracer.trace("Ctx: seekEvent(TS) - start"); +// +// if (timestamp == null) +// timestamp = TmfTimestamp.BIG_BANG; +// +// // First, find the right checkpoint +// int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null)); +// +// // In the very likely case that the checkpoint was not found, bsearch +// // returns its negated would-be location (not an offset...). From that +// // index, we can then position the stream and get the event. +// if (index < 0) +// index = Math.max(0, -(index + 2)); +// +// // Position the experiment at the checkpoint +// ITmfLocation location; +// synchronized (fCheckpoints) { +// if (fCheckpoints.size() > 0) { +// if (index >= fCheckpoints.size()) +// index = fCheckpoints.size() - 1; +// location = fCheckpoints.elementAt(index).getLocation(); +// } else +// location = null; +// } +// +// final TmfExperimentContext context = seekEvent(location); +// context.setRank((long) index * fIndexPageSize); +// +// // And locate the requested event context +// final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype... +// ITmfEvent event = readNextEvent(nextEventContext); +// while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { +// context.setLocation(nextEventContext.getLocation().clone()); +// context.increaseRank(); +// event = readNextEvent(nextEventContext); +// } +// if (event == null) { +// context.setLocation(null); +// context.setRank(ITmfContext.UNKNOWN_RANK); +// } +// return context; +// +//// // And locate the event +//// ITmfEvent event = parseEvent(context); +//// while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) { +//// readNextEvent(context); +//// event = parseEvent(context); +//// } +// +//// if (event == null) { +//// context.setLocation(null); +//// context.setRank(ITmfContext.UNKNOWN_RANK); +//// } +//// +//// return context; +// } /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long) */ - @Override - public synchronized TmfExperimentContext seekEvent(final long rank) { - - // Tracer.trace("Ctx: seekEvent(rank) - start"); - - // Position the stream at the previous checkpoint - int index = (int) rank / fIndexPageSize; - ITmfLocation location; - synchronized (fCheckpoints) { - if (fCheckpoints.size() == 0) - location = null; - else { - if (index >= fCheckpoints.size()) - index = fCheckpoints.size() - 1; - location = fCheckpoints.elementAt(index).getLocation(); - } - } - - final TmfExperimentContext context = seekEvent(location); - context.setRank((long) index * fIndexPageSize); - - // And locate the event - ITmfEvent event = parseEvent(context); - long pos = context.getRank(); - while ((event != null) && (pos++ < rank)) { - readNextEvent(context); - event = parseEvent(context); - } - - if (event == null) { - context.setLocation(null); - context.setRank(ITmfContext.UNKNOWN_RANK); - } - - return context; - } +// @Override +// public synchronized TmfExperimentContext seekEvent(final long rank) { +// +// // Tracer.trace("Ctx: seekEvent(rank) - start"); +// +// // Position the stream at the previous checkpoint +// int index = (int) rank / fIndexPageSize; +// ITmfLocation location; +// synchronized (fCheckpoints) { +// if (fCheckpoints.size() == 0) +// location = null; +// else { +// if (index >= fCheckpoints.size()) +// index = fCheckpoints.size() - 1; +// location = fCheckpoints.elementAt(index).getLocation(); +// } +// } +// +// final TmfExperimentContext context = seekEvent(location); +// context.setRank((long) index * fIndexPageSize); +// +//// // Position the trace at the checkpoint +//// final ITmfContext context = fIndexer.seekIndex(rank); +// +// // And locate the requested event context +// long pos = context.getRank(); +// if (pos < rank) { +// ITmfEvent event = readNextEvent(context); +// while (event != null && ++pos < rank) { +// event = readNextEvent(context); +// } +// if (event == null) { +// context.setLocation(null); +// context.setRank(ITmfContext.UNKNOWN_RANK); +// } +// } +// return context; +// +//// // And locate the event +//// ITmfEvent event = parseEvent(context); +//// long pos = context.getRank(); +//// while ((event != null) && (pos++ < rank)) { +//// readNextEvent(context); +//// event = parseEvent(context); +//// } +//// +//// if (event == null) { +//// context.setLocation(null); +//// context.setRank(ITmfContext.UNKNOWN_RANK); +//// } +//// +//// return context; +// } @Override - public TmfContext seekEvent(final double ratio) { - final TmfContext context = seekEvent((long) (ratio * getNbEvents())); + public ITmfContext seekEvent(final double ratio) { + final ITmfContext context = seekEvent((long) (ratio * getNbEvents())); return context; } @@ -486,107 +534,107 @@ public class TmfExperiment extends TmfEventProvider impl // Tracer.trace(result.toString()); // } - /** - * Scan the next events from all traces and return the next one in - * chronological order. - * - * @param context the trace context - * @return the next event - */ - @Override - public synchronized ITmfEvent readNextEvent(final ITmfContext context) { - - // Validate the context - if (!(context instanceof TmfExperimentContext)) - return null; // Throw an exception? - - if (!context.equals(fExperimentContext)) - // Tracer.trace("Ctx: Restoring context"); - fExperimentContext = seekEvent(context.getLocation()); - - final TmfExperimentContext expContext = (TmfExperimentContext) context; - - // dumpContext(expContext, true); - - // If an event was consumed previously, get the next one from that trace - final int lastTrace = expContext.getLastTrace(); - if (lastTrace != TmfExperimentContext.NO_TRACE) { - final ITmfContext traceContext = expContext.getContexts()[lastTrace]; - expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext); - expContext.setLastTrace(TmfExperimentContext.NO_TRACE); - } - - // Scan the candidate events and identify the "next" trace to read from - final ITmfEvent eventArray[] = expContext.getEvents(); - if (eventArray == null) - return null; - int trace = TmfExperimentContext.NO_TRACE; - ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; - if (eventArray.length == 1) { - if (eventArray[0] != null) { - timestamp = eventArray[0].getTimestamp(); - trace = 0; - } - } else - for (int i = 0; i < eventArray.length; i++) { - final ITmfEvent event = eventArray[i]; - if (event != null && event.getTimestamp() != null) { - final ITmfTimestamp otherTS = event.getTimestamp(); - if (otherTS.compareTo(timestamp, true) < 0) { - trace = i; - timestamp = otherTS; - } - } - } - // Update the experiment context and set the "next" event - ITmfEvent event = null; - if (trace != TmfExperimentContext.NO_TRACE) { - updateIndex(expContext, timestamp); - - final ITmfContext traceContext = expContext.getContexts()[trace]; - final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); - // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); - expLocation.getLocation().locations[trace] = traceContext.getLocation().clone(); - - // updateIndex(expContext, timestamp); - - expLocation.getRanks()[trace] = traceContext.getRank(); - expContext.setLastTrace(trace); - expContext.increaseRank(); - event = expContext.getEvents()[trace]; - fExperimentContext = expContext; - } - - // if (event != null) { - // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); - // dumpContext(expContext, false); - // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); - // } - - return event; - } - - public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) { - // Build the index as we go along - final long rank = context.getRank(); - if (context.hasValidRank() && (rank % fIndexPageSize) == 0) { - // Determine the table position - final long position = rank / fIndexPageSize; - // Add new entry at proper location (if empty) - if (fCheckpoints.size() == position) { - final ITmfLocation location = context.getLocation().clone(); - fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location)); - // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " - // + location.toString()); - } - } - } +// /** +// * Scan the next events from all traces and return the next one in +// * chronological order. +// * +// * @param context the trace context +// * @return the next event +// */ +// @Override +// public synchronized ITmfEvent readNextEvent(final ITmfContext context) { +// +// // Validate the context +// if (!(context instanceof TmfExperimentContext)) +// return null; // Throw an exception? +// +// if (!context.equals(fExperimentContext)) +// // Tracer.trace("Ctx: Restoring context"); +// fExperimentContext = seekEvent(context.getLocation()); +// +// final TmfExperimentContext expContext = (TmfExperimentContext) context; +// +// // dumpContext(expContext, true); +// // If an event was consumed previously, get the next one from that trace +// final int lastTrace = expContext.getLastTrace(); +// if (lastTrace != TmfExperimentContext.NO_TRACE) { +// final ITmfContext traceContext = expContext.getContexts()[lastTrace]; +// expContext.getEvents()[lastTrace] = fTraces[lastTrace].readNextEvent(traceContext); +// expContext.setLastTrace(TmfExperimentContext.NO_TRACE); +// } +// +// // Scan the candidate events and identify the "next" trace to read from +// final ITmfEvent eventArray[] = expContext.getEvents(); +// if (eventArray == null) +// return null; +// int trace = TmfExperimentContext.NO_TRACE; +// ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; +// if (eventArray.length == 1) { +// if (eventArray[0] != null) { +// timestamp = eventArray[0].getTimestamp(); +// trace = 0; +// } +// } else +// for (int i = 0; i < eventArray.length; i++) { +// final ITmfEvent event = eventArray[i]; +// if (event != null && event.getTimestamp() != null) { +// final ITmfTimestamp otherTS = event.getTimestamp(); +// if (otherTS.compareTo(timestamp, true) < 0) { +// trace = i; +// timestamp = otherTS; +// } +// } +// } +// +// // Update the experiment context and set the "next" event +// ITmfEvent event = null; +// if (trace != TmfExperimentContext.NO_TRACE) { +// updateIndex(expContext, timestamp); +// +// final ITmfContext traceContext = expContext.getContexts()[trace]; +// final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); +// // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); +// expLocation.getLocation().getLocations()[trace] = traceContext.getLocation().clone(); +// +// // updateIndex(expContext, timestamp); +// +//// expLocation.getRanks()[trace] = traceContext.getRank(); +// expContext.setLastTrace(trace); +// expContext.increaseRank(); +// event = expContext.getEvents()[trace]; +// fExperimentContext = expContext; +// } +// +// // if (event != null) { +// // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); +// // dumpContext(expContext, false); +// // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); +// // } +// +// return event; +// } + +// public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) { +// // Build the index as we go along +// final long rank = context.getRank(); +// if (context.hasValidRank() && (rank % fIndexPageSize) == 0) { +// // Determine the table position +// final long position = rank / fIndexPageSize; +// // Add new entry at proper location (if empty) +// if (fCheckpoints.size() == position) { +// final ITmfLocation location = context.getLocation().clone(); +// fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location)); +//// System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString()); +// } +// } +// } /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext) */ -// @Override - public ITmfEvent parseEvent(final ITmfContext context) { + @SuppressWarnings("unchecked") + @Override + public T parseEvent(final ITmfContext context) { // Validate the context if (!(context instanceof TmfExperimentContext)) @@ -594,7 +642,7 @@ public class TmfExperiment extends TmfEventProvider impl if (!context.equals(fExperimentContext)) // Tracer.trace("Ctx: Restoring context"); - seekEvent(context.getLocation()); + fExperimentContext = seekEvent(context.getLocation()); final TmfExperimentContext expContext = (TmfExperimentContext) context; @@ -602,15 +650,15 @@ public class TmfExperiment extends TmfEventProvider impl final int lastTrace = expContext.getLastTrace(); if (lastTrace != TmfExperimentContext.NO_TRACE) { final ITmfContext traceContext = expContext.getContexts()[lastTrace]; - expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext); + expContext.getEvents()[lastTrace] = fTraces[lastTrace].readNextEvent(traceContext); expContext.setLastTrace(TmfExperimentContext.NO_TRACE); - fExperimentContext = (TmfExperimentContext) context; +// fExperimentContext = (TmfExperimentContext) context; } // Scan the candidate events and identify the "next" trace to read from int trace = TmfExperimentContext.NO_TRACE; ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; - for (int i = 0; i < expContext.getTraces().length; i++) { + for (int i = 0; i < fTraces.length; i++) { final ITmfEvent event = expContext.getEvents()[i]; if (event != null && event.getTimestamp() != null) { final ITmfTimestamp otherTS = event.getTimestamp(); @@ -620,10 +668,61 @@ public class TmfExperiment extends TmfEventProvider impl } } } - - ITmfEvent event = null; + fExperimentContext.setLastTrace(trace); + +// // Scan the candidate events and identify the "next" trace to read from +// final ITmfEvent eventArray[] = expContext.getEvents(); +// if (eventArray == null) +// return null; +// int trace = TmfExperimentContext.NO_TRACE; +// ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; +// if (eventArray.length == 1) { +// if (eventArray[0] != null) { +// timestamp = eventArray[0].getTimestamp(); +// trace = 0; +// } +// } else +// for (int i = 0; i < eventArray.length; i++) { +// final ITmfEvent event = eventArray[i]; +// if (event != null && event.getTimestamp() != null) { +// final ITmfTimestamp otherTS = event.getTimestamp(); +// if (otherTS.compareTo(timestamp, true) < 0) { +// trace = i; +// timestamp = otherTS; +// } +// } +// } +// +// // Update the experiment context and set the "next" event +// ITmfEvent event = null; +// if (trace != TmfExperimentContext.NO_TRACE) { +// updateIndex(expContext, timestamp); +// +// final ITmfContext traceContext = expContext.getContexts()[trace]; +// final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation(); +// // expLocation.getLocation()[trace] = traceContext.getLocation().clone(); +// expLocation.getLocation().getLocations()[trace] = traceContext.getLocation().clone(); +// +// // updateIndex(expContext, timestamp); +// +//// expLocation.getRanks()[trace] = traceContext.getRank(); +// expContext.setLastTrace(trace); +// expContext.increaseRank(); +// event = expContext.getEvents()[trace]; +// fExperimentContext = expContext; +// } +// +// // if (event != null) { +// // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString()); +// // dumpContext(expContext, false); +// // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString()); +// // } +// +// return event; + + T event = null; if (trace != TmfExperimentContext.NO_TRACE) - event = expContext.getEvents()[trace]; + event = (T) expContext.getEvents()[trace]; return event; } @@ -647,7 +746,7 @@ public class TmfExperiment extends TmfEventProvider impl fInitialized = true; if (getStreamingInterval() == 0) { - final TmfContext context = seekEvent(0); + final ITmfContext context = seekEvent(0); final ITmfEvent event = getNext(context); if (event == null) return; @@ -750,118 +849,120 @@ public class TmfExperiment extends TmfEventProvider impl } } - @SuppressWarnings("unchecked") - private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) { - - synchronized (fCheckpoints) { - if (fIndexing) - return; - fIndexing = true; - } - - final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$ - - @Override - protected IStatus run(final IProgressMonitor monitor) { - while (!monitor.isCanceled()) - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - return Status.OK_STATUS; - } - monitor.done(); - return Status.OK_STATUS; - } - }; - job.schedule(); - - // fEventLog = openLogFile("TraceEvent.log"); - // System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); - - final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, timeRange, index, - TmfDataRequest.ALL_DATA, - fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA - // FOREGROUND - - // long indexingStart = System.nanoTime(); - - ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime(); - ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime(); - long initialNbEvents = fNbEvents; - - @Override - public void handleStarted() { - super.handleStarted(); - } - - @Override - public void handleData(final ITmfEvent event) { - super.handleData(event); - if (event != null) { - final ITmfTimestamp ts = event.getTimestamp(); - if (startTime == null) - startTime = ts.clone(); - lastTime = ts.clone(); - } - if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) - updateExperiment(); - } - - @Override - public void handleSuccess() { - // long indexingEnd = System.nanoTime(); - - // if the end time is a real value then it is the streaming safe - // time stamp - // set the last time to the safe time stamp to prevent - // unnecessary indexing requests - if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH) - lastTime = getRange().getEndTime(); - updateExperiment(); - // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); - - // long average = (indexingEnd - indexingStart) / fNbEvents; - // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" - // + (indexingEnd * 1.0 - indexingStart) / 1000000000); - // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." - // + (average % 1000) + " us/evt)"); - super.handleSuccess(); - } - - @Override - public void handleCompleted() { - job.cancel(); - super.handleCompleted(); - synchronized (fCheckpoints) { - fIndexing = false; - if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) { - indexExperiment(false, (int) fNbEvents, fIndexingPendingRange); - fIndexingPendingRange = TmfTimeRange.NULL_RANGE; - } - } - } - - private void updateExperiment() { - final int nbRead = getNbRead(); - if (startTime != null) - fTimeRange = new TmfTimeRange(startTime, lastTime.clone()); - if (nbRead != 0) { - // updateTimeRange(); - // updateNbEvents(); - fNbEvents = initialNbEvents + nbRead; - notifyListeners(); - } - } - }; - - sendRequest((ITmfDataRequest) request); - if (waitForCompletion) - try { - request.waitForCompletion(); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - } +// @SuppressWarnings("unchecked") +// private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) { +// +// synchronized (fCheckpoints) { +// if (fIndexing) +// return; +// fIndexing = true; +// } +// +// final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$ +// +// @Override +// protected IStatus run(final IProgressMonitor monitor) { +// while (!monitor.isCanceled()) +// try { +// Thread.sleep(100); +// } catch (final InterruptedException e) { +// return Status.OK_STATUS; +// } +// monitor.done(); +// return Status.OK_STATUS; +// } +// }; +// job.schedule(); +// +// // fEventLog = openLogFile("TraceEvent.log"); +// // System.out.println(System.currentTimeMillis() + ": Experiment indexing started"); +// +// final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, timeRange, index, +// TmfDataRequest.ALL_DATA, +// fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA +// // FOREGROUND +// +//// long indexingStart = System.nanoTime(); +// +// ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime(); +// ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime(); +// long initialNbEvents = fNbEvents; +// +// @Override +// public void handleStarted() { +// super.handleStarted(); +// } +// +// @Override +// public void handleData(final ITmfEvent event) { +// super.handleData(event); +// if (event != null) { +// final ITmfTimestamp ts = event.getTimestamp(); +// if (startTime == null) +// startTime = ts.clone(); +// lastTime = ts.clone(); +// } +// if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) { +// updateExperiment(); +// } +// } +// +// @Override +// public void handleSuccess() { +//// long indexingEnd = System.nanoTime(); +// +// // if the end time is a real value then it is the streaming safe +// // time stamp +// // set the last time to the safe time stamp to prevent +// // unnecessary indexing requests +// if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH) +// lastTime = getRange().getEndTime(); +// updateExperiment(); +// /////////////////////////////////////////////////////////////////// +//// System.out.println(System.currentTimeMillis() + ": Experiment indexing completed"); +//// long average = (indexingEnd - indexingStart) / fNbEvents; +//// System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" +//// + (indexingEnd * 1.0 - indexingStart) / 1000000000); +//// System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." +//// + (average % 1000) + " us/evt)"); +// /////////////////////////////////////////////////////////////////// +// super.handleSuccess(); +// } +// +// @Override +// public void handleCompleted() { +// job.cancel(); +// super.handleCompleted(); +// synchronized (fCheckpoints) { +// fIndexing = false; +// if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) { +// indexExperiment(false, (int) fNbEvents, fIndexingPendingRange); +// fIndexingPendingRange = TmfTimeRange.NULL_RANGE; +// } +// } +// } +// +// private void updateExperiment() { +// final int nbRead = getNbRead(); +// if (startTime != null) +// fTimeRange = new TmfTimeRange(startTime, lastTime.clone()); +// if (nbRead != 0) { +// // updateTimeRange(); +// // updateNbEvents(); +// fNbEvents = initialNbEvents + nbRead; +// notifyListeners(); +// } +// } +// }; +// +// sendRequest((ITmfDataRequest) request); +// if (waitForCompletion) +// try { +// request.waitForCompletion(); +// } catch (final InterruptedException e) { +// e.printStackTrace(); +// } +// } protected void notifyListeners() { broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null)); @@ -879,6 +980,8 @@ public class TmfExperiment extends TmfEventProvider impl if (experiment == this) { setCurrentExperiment(experiment); fEndSynchReference = Integer.valueOf(signal.getReference()); + fCheckpoints.clear(); + fNbEvents = 0; } } @@ -896,34 +999,36 @@ public class TmfExperiment extends TmfEventProvider impl @TmfSignalHandler public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) { - if (signal.getExperiment() == this) - indexExperiment(false, (int) fNbEvents, signal.getRange()); + if (signal.getExperiment() == this) { +// indexExperiment(false, (int) fNbEvents, signal.getRange()); + getIndexer().buildIndex(false); + } } - @TmfSignalHandler - public void traceUpdated(final TmfTraceUpdatedSignal signal) { - for (final ITmfTrace trace : fTraces) - if (trace == signal.getTrace()) { - synchronized (fCheckpoints) { - if (fIndexing) { - if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE) - fIndexingPendingRange = signal.getRange(); - else { - ITmfTimestamp startTime = fIndexingPendingRange.getStartTime(); - ITmfTimestamp endTime = fIndexingPendingRange.getEndTime(); - if (signal.getRange().getStartTime().compareTo(startTime) < 0) - startTime = signal.getRange().getStartTime(); - if (signal.getRange().getEndTime().compareTo(endTime) > 0) - endTime = signal.getRange().getEndTime(); - fIndexingPendingRange = new TmfTimeRange(startTime, endTime); - } - return; - } - } - indexExperiment(false, (int) fNbEvents, signal.getRange()); - return; - } - } +// @TmfSignalHandler +// public void traceUpdated(final TmfTraceUpdatedSignal signal) { +// for (final ITmfTrace trace : fTraces) +// if (trace == signal.getTrace()) { +// synchronized (fCheckpoints) { +// if (fIndexing) { +// if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE) +// fIndexingPendingRange = signal.getRange(); +// else { +// ITmfTimestamp startTime = fIndexingPendingRange.getStartTime(); +// ITmfTimestamp endTime = fIndexingPendingRange.getEndTime(); +// if (signal.getRange().getStartTime().compareTo(startTime) < 0) +// startTime = signal.getRange().getStartTime(); +// if (signal.getRange().getEndTime().compareTo(endTime) > 0) +// endTime = signal.getRange().getEndTime(); +// fIndexingPendingRange = new TmfTimeRange(startTime, endTime); +// } +// return; +// } +// } +// indexExperiment(false, (int) fNbEvents, signal.getRange()); +// return; +// } +// } @Override public String getPath() { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java index e1d2b5afd6..5c41718434 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Put in shape for 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.experiment; @@ -15,19 +16,18 @@ package org.eclipse.linuxtools.tmf.core.experiment; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; -import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; /** - * TmfExperimentContext + * The experiment context in TMF. *

* The experiment keeps track of the next event from each of its traces so it * can pick the next one in chronological order. *

* This implies that the "next" event from each trace has already been * read and that we at least know its timestamp. This doesn't imply that a - * full parse of the event content was performed (read: LTTng works like - * this). + * full parse of the event content was performed (read: the legacy LTTng works + * like this...). *

* The last trace refers to the trace from which the last event was "consumed" * at the experiment level. @@ -38,13 +38,16 @@ public class TmfExperimentContext extends TmfContext { // Constants // ------------------------------------------------------------------------ - public static final int NO_TRACE = -1; + /** + * No last trace read indicator + */ + static final int NO_TRACE = -1; // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - private ITmfTrace[] fTraces = new ITmfTrace[0]; +// private ITmfTrace[] fTraces = new ITmfTrace[0]; private final ITmfContext[] fContexts; private ITmfEvent[] fEvents; private int lastTraceRead; @@ -53,28 +56,28 @@ public class TmfExperimentContext extends TmfContext { // Constructors // ------------------------------------------------------------------------ - public TmfExperimentContext(final ITmfTrace[] traces, final ITmfContext[] contexts) { + public TmfExperimentContext(final ITmfContext[] contexts) { super(); - fTraces = traces; +// fTraces = traces; fContexts = contexts; - fEvents = new ITmfEvent[fTraces.length]; - final ITmfLocation[] locations = new ITmfLocation[fTraces.length]; - final long[] ranks = new long[fTraces.length]; + fEvents = new ITmfEvent[fContexts.length]; + final ITmfLocation[] locations = new ITmfLocation[fContexts.length]; + final long[] ranks = new long[fContexts.length]; long rank = 0; - for (int i = 0; i < fTraces.length; i++) + for (int i = 0; i < fContexts.length; i++) if (contexts[i] != null) { locations[i] = contexts[i].getLocation(); ranks[i] = contexts[i].getRank(); rank += contexts[i].getRank(); } - setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks)); + setLocation(new TmfExperimentLocation(new TmfLocationArray(locations))); setRank(rank); lastTraceRead = NO_TRACE; } public TmfExperimentContext(final TmfExperimentContext other) { - this(other.fTraces, other.cloneContexts()); + this(other.cloneContexts()); fEvents = other.fEvents; if (other.getLocation() != null) setLocation(other.getLocation().clone()); @@ -82,9 +85,9 @@ public class TmfExperimentContext extends TmfContext { setLastTrace(other.lastTraceRead); } - public TmfExperimentContext(final ITmfTrace[] traces) { - this(traces, new TmfContext[traces.length]); - } +// public TmfExperimentContext(final ITmfTrace[] traces) { +// this(traces, new TmfContext[traces.length]); +// } private ITmfContext[] cloneContexts() { final ITmfContext[] contexts = new ITmfContext[fContexts.length]; @@ -114,9 +117,9 @@ public class TmfExperimentContext extends TmfContext { // Accessors // ------------------------------------------------------------------------ - public ITmfTrace[] getTraces() { - return fTraces; - } +// public ITmfTrace[] getTraces() { +// return fTraces; +// } public ITmfContext[] getContexts() { return fContexts; @@ -141,8 +144,8 @@ public class TmfExperimentContext extends TmfContext { @Override public int hashCode() { int result = 17; - for (int i = 0; i < fTraces.length; i++) { - result = 37 * result + fTraces[i].hashCode(); + for (int i = 0; i < fContexts.length; i++) { +// result = 37 * result + fTraces[i].hashCode(); result = 37 * result + fContexts[i].hashCode(); } return result; @@ -159,8 +162,8 @@ public class TmfExperimentContext extends TmfContext { final TmfExperimentContext o = (TmfExperimentContext) other; boolean isEqual = true; int i = 0; - while (isEqual && (i < fTraces.length)) { - isEqual &= fTraces[i].equals(o.fTraces[i]); + while (isEqual && (i < fContexts.length)) { +// isEqual &= fTraces[i].equals(o.fTraces[i]); isEqual &= fContexts[i].equals(o.fContexts[i]); i++; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentLocation.java index f3bd092c0d..57ca5d48bb 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperimentLocation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 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 @@ -7,72 +7,110 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Updated as per TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.experiment; -import java.util.Arrays; - +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; /** - * TmfExperimentLocation + * The experiment location in TMF. + *

+ * An experiment location is actually the set of locations of the traces it + * contains. By setting the individual traces to their corresponding locations, + * the experiment can be positioned to read the next chronological event. *

- * The experiment location is the set of its traces' locations. + * It is the responsibility of the user the individual trace locations are valid + * and that they are matched to the correct trace. + * + * @version 1.0 + * @author Francois Chouinard + * + * @see TmfLocationArray */ -public class TmfExperimentLocation extends TmfLocation { +public class TmfExperimentLocation extends TmfLocation implements Cloneable { - private long[] fRanks; + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ - public TmfExperimentLocation(TmfLocationArray locations, long[] ranks) { - super(locations); - fRanks = ranks; - } + /** + * The standard constructor + * + * @param locations the set of trace locations + */ + public TmfExperimentLocation(TmfLocationArray locations) { + super(locations); + } - @Override - public TmfExperimentLocation clone() { - super.clone(); // To keep FindBugs happy - TmfLocationArray array = (TmfLocationArray) getLocation(); - TmfLocationArray clones = array.clone(); - return new TmfExperimentLocation(clones, fRanks.clone()); - } + /** + * The copy constructor + * + * @param location the other experiment location + */ + public TmfExperimentLocation(TmfExperimentLocation location) { + this(location.getLocation()); + } - @Override - @SuppressWarnings("nls") - public String toString() { - StringBuilder result = new StringBuilder("[TmfExperimentLocation"); - TmfLocationArray array = (TmfLocationArray) getLocation(); - for (int i = 0; i < array.locations.length; i++) { - result.append("[" + array.locations[i].toString() + "," + fRanks[i] + "]"); - } - result.append("]"); - return result.toString(); - } + // ------------------------------------------------------------------------ + // Cloneable + // ------------------------------------------------------------------------ - public long[] getRanks() { - return fRanks; + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#clone() + */ + @Override + public TmfExperimentLocation clone() { +// super.clone(); // To keep FindBugs happy + TmfLocationArray array = (TmfLocationArray) getLocation(); + TmfLocationArray clones = array.clone(); + return new TmfExperimentLocation(clones); } + // ------------------------------------------------------------------------ + // Object + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#toString() + */ + @Override + @SuppressWarnings("nls") + public String toString() { + StringBuilder result = new StringBuilder("[TmfExperimentLocation"); + ITmfLocation>[] locations = ((TmfLocationArray) getLocation()).getLocations(); + for (ITmfLocation location : locations) { + result.append("[" + location.toString() + "]"); + } + result.append("]"); + return result.toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#hashCode() + */ @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + Arrays.hashCode(fRanks); - return result; + return super.hashCode(); } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfLocation#equals(java.lang.Object) + */ @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) + } + if (!super.equals(obj)) { return false; - TmfExperimentLocation other = (TmfExperimentLocation) obj; - if (!Arrays.equals(fRanks, other.fRanks)) + } + if (getClass() != obj.getClass()) { return false; + } return true; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfLocationArray.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfLocationArray.java index 605be73409..f01b56ca35 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfLocationArray.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfLocationArray.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011, 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 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Patrick Tasse - Initial API and implementation + * Patrick Tasse - Initial API and implementation + * Francois Chouinard - Put in shape for 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.experiment; @@ -16,60 +17,124 @@ import java.util.Arrays; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; +/** + * A convenience class to store trace location arrays. The main purpose is to + * provide a Comparable implementation for TmfExperimentLocation. + * + * @version 1.0 + * @author Patrick Tasse + */ public class TmfLocationArray implements Comparable, Cloneable { - public ITmfLocation>[] locations; - - public TmfLocationArray(ITmfLocation>[] locations) { - this.locations = locations; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public int compareTo(TmfLocationArray o) { - for (int i = 0; i < locations.length; i++) { - ITmfLocation l1 = (ITmfLocation) locations[i].getLocation(); - ITmfLocation l2 = (ITmfLocation) o.locations[i].getLocation(); - int result = l1.getLocation().compareTo(l2.getLocation()); - if (result != 0) { - return result; - } - } - return 0; - } - - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ - @Override - protected TmfLocationArray clone() { - ITmfLocation>[] clones = (ITmfLocation>[]) new ITmfLocation[locations.length]; - for (int i = 0; i < locations.length; i++) { - clones[i] = locations[i].clone(); - } - return new TmfLocationArray(clones); - } + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private ITmfLocation>[] fLocations; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * The standard constructor + * + * @param locations the locations + */ + public TmfLocationArray(ITmfLocation>[] locations) { + fLocations = locations; + } + + // ------------------------------------------------------------------------ + // Getters + // ------------------------------------------------------------------------ + + /** + * The standard constructor + * + * @param locations the locations + */ + public ITmfLocation>[] getLocations() { + return fLocations; + } + + // ------------------------------------------------------------------------ + // Cloneable + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public TmfLocationArray clone() { + ITmfLocation>[] clones = (ITmfLocation>[]) new ITmfLocation[fLocations.length]; + for (int i = 0; i < fLocations.length; i++) { + clones[i] = fLocations[i].clone(); + } + return new TmfLocationArray(clones); + } + + // ------------------------------------------------------------------------ + // Comparable + // ------------------------------------------------------------------------ + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public int compareTo(TmfLocationArray o) { + for (int i = 0; i < fLocations.length; i++) { + ITmfLocation l1 = (ITmfLocation) fLocations[i].getLocation(); + ITmfLocation l2 = (ITmfLocation) o.fLocations[i].getLocation(); + int result = l1.getLocation().compareTo(l2.getLocation()); + if (result != 0) { + return result; + } + } + return 0; + } + + // ------------------------------------------------------------------------ + // Object + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Arrays.hashCode(locations); + result = prime * result + Arrays.hashCode(fLocations); return result; } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } TmfLocationArray other = (TmfLocationArray) obj; - if (!Arrays.equals(locations, other.locations)) + if (!Arrays.equals(fLocations, other.fLocations)) { return false; + } return true; } -} + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + @SuppressWarnings("nls") + public String toString() { + return "TmfLocationArray [locations=" + Arrays.toString(fLocations) + "]"; + } +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java index e36626b14b..796b144eac 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java @@ -18,15 +18,13 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; * The basic trace checkpoint structure in TMF. The purpose of the checkpoint is * to associate a trace location to an event timestamp. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * - * @see TmfCheckpoint * @see ITmfTimestamp * @see ITmfLocation */ -public interface ITmfCheckpoint extends Cloneable, Comparable { +public interface ITmfCheckpoint extends Comparable { // ------------------------------------------------------------------------ // Getters @@ -42,10 +40,6 @@ public interface ITmfCheckpoint extends Cloneable, Comparable { */ public ITmfLocation> getLocation(); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the checkpoint */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java index 4ba1ec14d9..a65e020ad2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java @@ -20,13 +20,12 @@ package org.eclipse.linuxtools.tmf.core.trace; * The context should be sufficient to allow the trace to position itself so * that performing a trace read operation will yield the corresponding event. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * * @see ITmfLocation */ -public interface ITmfContext extends Cloneable { +public interface ITmfContext { // ------------------------------------------------------------------------ // Constants @@ -80,10 +79,6 @@ public interface ITmfContext extends Cloneable { */ public void dispose(); - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - /** * @return a clone of the context */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfEventParser.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfEventParser.java index fd2526231f..1b7920ba52 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfEventParser.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfEventParser.java @@ -18,7 +18,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; /** * The generic trace parser in TMF. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java index 5ec399f77d..708ff96562 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java @@ -23,13 +23,10 @@ package org.eclipse.linuxtools.tmf.core.trace; *

* This location is trace-specific and must be comparable. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard - * - * @see TmfLocation */ -public interface ITmfLocation> extends Cloneable { +public interface ITmfLocation> { // ------------------------------------------------------------------------ // Getters @@ -41,7 +38,7 @@ public interface ITmfLocation> extends Cloneable { public L getLocation(); // ------------------------------------------------------------------------ - // Cloneable + // Operations // ------------------------------------------------------------------------ /** diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index 9f877ba7b0..fa7697e030 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -20,7 +20,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; /** * The event stream structure in TMF. In its basic form, a trace has: @@ -100,17 +99,25 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; * } * * - * @since 1.0 * @version 1.0 * @author Francois Chouinard - * + * + * @see ITmfContext * @see ITmfEvent - * @see ITmfDataProvider - * @see ITmfEventRequest - * @see TmfTrace + * @see ITmfTraceIndexer + * @see ITmfEventParser */ public interface ITmfTrace extends ITmfDataProvider { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * The default trace cache size + */ + public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; + // ------------------------------------------------------------------------ // Initializers // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java index 76d878a82e..1f16da37bf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java @@ -18,7 +18,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; /** * The generic trace indexer in TMF. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java index 967aecaa84..76eca5e37d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java @@ -19,15 +19,13 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp * to a generic location. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * - * @see ITmfCheckpoint * @see ITmfLocation * @see ITmfTimestamp */ -public class TmfCheckpoint implements ITmfCheckpoint { +public class TmfCheckpoint implements ITmfCheckpoint, Cloneable { // ------------------------------------------------------------------------ // Attributes @@ -67,8 +65,9 @@ public class TmfCheckpoint implements ITmfCheckpoint { * @param other the other checkpoint */ public TmfCheckpoint(final TmfCheckpoint other) { - if (other == null) + if (other == null) { throw new IllegalArgumentException(); + } fTimestamp = other.fTimestamp; fLocation = other.fLocation; } @@ -154,23 +153,30 @@ public class TmfCheckpoint implements ITmfCheckpoint { */ @Override public boolean equals(final Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (!(obj instanceof TmfCheckpoint)) + } + if (!(obj instanceof TmfCheckpoint)) { return false; + } final TmfCheckpoint other = (TmfCheckpoint) obj; if (fLocation == null) { - if (other.fLocation != null) + if (other.fLocation != null) { return false; - } else if (!fLocation.equals(other.fLocation)) + } + } else if (!fLocation.equals(other.fLocation)) { return false; + } if (fTimestamp == null) { - if (other.fTimestamp != null) + if (other.fTimestamp != null) { return false; - } else if (!fTimestamp.equals(other.fTimestamp)) + } + } else if (!fTimestamp.equals(other.fTimestamp)) { return false; + } return true; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java index aaedb788d0..49b2bf9e81 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java @@ -12,8 +12,9 @@ package org.eclipse.linuxtools.tmf.core.trace; +import java.util.ArrayList; import java.util.Collections; -import java.util.Vector; +import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -41,11 +42,9 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; * Locating a specific checkpoint is trivial for both rank (rank % interval) and * timestamp (bsearch in the array). * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * - * @see ITmfTraceIndexer * @see ITmfTrace * @see ITmfEvent */ @@ -55,21 +54,17 @@ public class TmfCheckpointIndexer> implements ITm // Attributes // ------------------------------------------------------------------------ - /** - * The event trace to index - */ + // The event trace to index private final ITmfTrace fTrace; - /** - * The interval between checkpoints - */ - protected final int fCheckpointInterval; + // The interval between checkpoints + private final int fCheckpointInterval; /** * The trace index. It is composed of checkpoints taken at intervals of * fCheckpointInterval events. */ - protected final Vector fTraceIndex; + private final List fTraceIndex; // ------------------------------------------------------------------------ // Construction @@ -94,7 +89,7 @@ public class TmfCheckpointIndexer> implements ITm public TmfCheckpointIndexer(final ITmfTrace trace, final int interval) { fTrace = trace; fCheckpointInterval = interval; - fTraceIndex = new Vector(); + fTraceIndex = new ArrayList(); } // ------------------------------------------------------------------------ @@ -138,8 +133,8 @@ public class TmfCheckpointIndexer> implements ITm final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND) { - ITmfTimestamp startTime = null; - ITmfTimestamp lastTime = null; + private ITmfTimestamp startTime = null; + private ITmfTimestamp lastTime = null; @Override public void handleData(final ITmfEvent event) { @@ -228,8 +223,9 @@ public class TmfCheckpointIndexer> implements ITm public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) { // A null timestamp indicates to seek the first event - if (timestamp == null) + if (timestamp == null) { return fTrace.seekEvent(0); + } // Find the checkpoint at or before the requested timestamp. // In the very likely event that the timestamp is not at a checkpoint @@ -251,8 +247,9 @@ public class TmfCheckpointIndexer> implements ITm public ITmfContext seekIndex(final long rank) { // A rank < 0 indicates to seek the first event - if (rank < 0) + if (rank < 0) { return fTrace.seekEvent(0); + } // Find the checkpoint at or before the requested rank. final int index = (int) rank / fCheckpointInterval; @@ -264,18 +261,18 @@ public class TmfCheckpointIndexer> implements ITm /** * Position the trace at the given checkpoint * - * @param index - * the checkpoint index + * @param checkpoint the checkpoint index * @return the corresponding context */ - private ITmfContext seekCheckpoint(int index) { + private ITmfContext seekCheckpoint(final int checkpoint) { ITmfLocation location; + int index = checkpoint; synchronized (fTraceIndex) { if (!fTraceIndex.isEmpty()) { if (index >= fTraceIndex.size()) { index = fTraceIndex.size() - 1; } - location = fTraceIndex.elementAt(index).getLocation(); + location = fTraceIndex.get(index).getLocation(); } else { location = null; } @@ -285,4 +282,14 @@ public class TmfCheckpointIndexer> implements ITm return context; } + // ------------------------------------------------------------------------ + // Getters + // ------------------------------------------------------------------------ + + /** + * @return the trace index + */ + protected List getTraceIndex() { + return fTraceIndex; + } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java index dfba34f7bc..add489ddcc 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java @@ -19,7 +19,6 @@ package org.eclipse.linuxtools.tmf.core.trace; * It ties a trace location to an event rank. The context should be enough to * restore the trace state so the corresponding event can be read. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * @@ -74,8 +73,9 @@ public class TmfContext implements ITmfContext, Cloneable { * @param context the other context */ public TmfContext(final TmfContext context) { - if (context == null) + if (context == null) { throw new IllegalArgumentException(); + } fLocation = context.fLocation; fRank = context.fRank; } @@ -140,8 +140,9 @@ public class TmfContext implements ITmfContext, Cloneable { */ @Override public void increaseRank() { - if (hasValidRank()) + if (hasValidRank()) { fRank++; + } } /* (non-Javadoc) @@ -180,20 +181,26 @@ public class TmfContext implements ITmfContext, Cloneable { */ @Override public boolean equals(final Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final TmfContext other = (TmfContext) obj; if (fLocation == null) { - if (other.fLocation != null) + if (other.fLocation != null) { return false; - } else if (!fLocation.equals(other.fLocation)) + } + } else if (!fLocation.equals(other.fLocation)) { return false; - if (fRank != other.fRank) + } + if (fRank != other.fRank) { return false; + } return true; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java index 2ffb6c701c..8a438dc622 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java @@ -19,11 +19,10 @@ import java.lang.reflect.Method; * A convenience implementation on of ITmfLocation. The generic class (L) must * be comparable. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard */ -public class TmfLocation> implements ITmfLocation { +public class TmfLocation> implements ITmfLocation, Cloneable { // ------------------------------------------------------------------------ // Attributes @@ -40,7 +39,6 @@ public class TmfLocation> implements ITmfLocation { */ @SuppressWarnings("unused") private TmfLocation() { - fLocation = null; } /** @@ -91,8 +89,9 @@ public class TmfLocation> implements ITmfLocation { final Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$ final Object copy = method.invoke(this.fLocation, new Object[0]); clone.fLocation = (L) copy; - } else + } else { clone.fLocation = null; + } } catch (final CloneNotSupportedException e) { } catch (final NoSuchMethodException e) { } catch (final Exception e) { @@ -122,18 +121,23 @@ public class TmfLocation> implements ITmfLocation { @Override @SuppressWarnings("unchecked") public boolean equals(final Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final TmfLocation other = (TmfLocation) obj; if (fLocation == null) { - if (other.fLocation != null) + if (other.fLocation != null) { return false; - } else if (!fLocation.equals(other.fLocation)) + } + } else if (!fLocation.equals(other.fLocation)) { return false; + } return true; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index e0c5fc726e..5487e67727 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -14,7 +14,6 @@ package org.eclipse.linuxtools.tmf.core.trace; import java.io.File; -import java.io.FileNotFoundException; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.Path; @@ -47,7 +46,6 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; * TmfCheckpointIndexer (default). In this case, the trace cache size will be * used as checkpoint interval. * - * @since 1.0 * @version 1.0 * @author Francois Chouinard * @@ -57,15 +55,6 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; */ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /** - * The default trace cache size - */ - public static final int DEFAULT_TRACE_CACHE_SIZE = 10000; - // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ @@ -76,34 +65,24 @@ public abstract class TmfTrace extends TmfEventProvider // The trace path private String fPath; - /** - * The trace cache page size - */ - protected int fCacheSize = DEFAULT_TRACE_CACHE_SIZE; + // The trace cache page size + private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE; - /** - * The number of events collected (so far) - */ - protected long fNbEvents = 0; + // The number of events collected (so far) + private long fNbEvents = 0; // The time span of the event stream private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH; private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG; - /** - * The trace streaming interval (0 = no streaming) - */ - protected long fStreamingInterval = 0; + // The trace streaming interval (0 = no streaming) + private long fStreamingInterval = 0; - /** - * The trace indexer - */ - protected ITmfTraceIndexer> fIndexer; + // The trace indexer + private ITmfTraceIndexer> fIndexer; - /** - * The trace parser - */ - protected ITmfEventParser fParser; + // The trace parser + private ITmfEventParser fParser; // ------------------------------------------------------------------------ // Construction @@ -160,7 +139,7 @@ public abstract class TmfTrace extends TmfEventProvider */ protected TmfTrace(final IResource resource, final Class type, final String path, final int cacheSize, final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException { - this(resource, type, path, cacheSize, interval, null, null); + this(resource, type, path, cacheSize, interval, indexer, null); } /** @@ -178,7 +157,7 @@ public abstract class TmfTrace extends TmfEventProvider protected TmfTrace(final IResource resource, final Class type, final String path, final int cacheSize, final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException { super(); - fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE; + fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE; fStreamingInterval = interval; fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize); fParser = parser; @@ -193,8 +172,9 @@ public abstract class TmfTrace extends TmfEventProvider @SuppressWarnings({ "unchecked", "rawtypes" }) public TmfTrace(final TmfTrace trace) throws TmfTraceException { super(); - if (trace == null) + if (trace == null) { throw new IllegalArgumentException(); + } fCacheSize = trace.getCacheSize(); fStreamingInterval = trace.getStreamingInterval(); fIndexer = new TmfCheckpointIndexer(this); @@ -222,12 +202,13 @@ public abstract class TmfTrace extends TmfEventProvider * @param path the trace path * @param type the trace event type * - * @throws FileNotFoundException + * @throws TmfTraceException */ @SuppressWarnings("unchecked") protected void initialize(final IResource resource, final String path, final Class type) throws TmfTraceException { - if (path == null) + if (path == null) { throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$ + } fPath = path; fResource = resource; String traceName = (resource != null) ? resource.getName() : null; @@ -302,6 +283,20 @@ public abstract class TmfTrace extends TmfEventProvider return fStreamingInterval; } + /** + * @return the trace indexer + */ + protected ITmfTraceIndexer> getIndexer() { + return fIndexer; + } + + /** + * @return the trace parser + */ + protected ITmfEventParser getParser() { + return fParser; + } + // ------------------------------------------------------------------------ // ITmfTrace - Trace characteristics getters // ------------------------------------------------------------------------ @@ -339,9 +334,28 @@ public abstract class TmfTrace extends TmfEventProvider } // ------------------------------------------------------------------------ - // Convenience setters + // Convenience setters/getters // ------------------------------------------------------------------------ + /** + * Set the trace cache size. Must be done at initialization time. + * + * @param cacheSize The trace cache size + */ + protected void setCacheSize(final int cacheSize) { + fCacheSize = cacheSize; + } + + /** + * Set the trace known number of events. This can be quite dynamic + * during indexing or for live traces. + * + * @param nbEvents The number of events + */ + protected synchronized void setNbEvents(final long nbEvents) { + fNbEvents = (nbEvents > 0) ? nbEvents : 0; + } + /** * Update the trace events time range * @@ -371,7 +385,7 @@ public abstract class TmfTrace extends TmfEventProvider } /** - * Update the trace streaming interval + * Set the polling interval for live traces (default = 0 = no streaming). * * @param interval the new trace streaming interval */ @@ -379,6 +393,24 @@ public abstract class TmfTrace extends TmfEventProvider fStreamingInterval = (interval > 0) ? interval : 0; } + /** + * Set the trace indexer. Must be done at initialization time. + * + * @param indexer the trace indexer + */ + protected void setIndexer(final ITmfTraceIndexer> indexer) { + fIndexer = indexer; + } + + /** + * Set the trace parser. Must be done at initialization time. + * + * @param parser the new trace parser + */ + protected void setParser(final ITmfEventParser parser) { + fParser = parser; + } + // ------------------------------------------------------------------------ // ITmfTrace - SeekEvent operations (returning a trace context) // ------------------------------------------------------------------------ @@ -434,6 +466,10 @@ public abstract class TmfTrace extends TmfEventProvider context.increaseRank(); event = readNextEvent(nextEventContext); } + if (event == null) { + context.setLocation(null); + context.setRank(ITmfContext.UNKNOWN_RANK); + } return context; } @@ -499,8 +535,9 @@ public abstract class TmfTrace extends TmfEventProvider @Override public ITmfContext armRequest(final ITmfDataRequest request) { if (request instanceof ITmfEventRequest - && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime()) - && request.getIndex() == 0) { + && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime()) + && request.getIndex() == 0) + { final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime()); ((ITmfEventRequest) request).setStartIndex((int) context.getRank()); return context; @@ -515,8 +552,9 @@ public abstract class TmfTrace extends TmfEventProvider @Override @SuppressWarnings("unchecked") public T getNext(final ITmfContext context) { - if (context instanceof TmfContext) + if (context instanceof TmfContext) { return (T) readNextEvent(context); + } return null; } diff --git a/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml index 73084a37db..3b939e7dd3 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui.tests/plugin.xml @@ -56,4 +56,22 @@ + + + + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 3d1d33b354..6d37bbb855 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -8,16 +8,24 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.ui;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.ui;bundle-version="3.7.0", - org.eclipse.ui.ide;bundle-version="3.7.0", - org.eclipse.core.resources;bundle-version="3.7.100", +Require-Bundle: org.eclipse.core.expressions, org.eclipse.core.filesystem;bundle-version="1.3.100", + org.eclipse.core.resources;bundle-version="3.7.100", org.eclipse.core.runtime;bundle-version="3.7.0", org.eclipse.linuxtools.tmf.core;bundle-version="0.5.0", + org.eclipse.ui;bundle-version="3.7.0", + org.eclipse.ui.ide;bundle-version="3.7.0", org.eclipse.ui.navigator;bundle-version="3.5.100", - org.eclipse.ui.navigator.resources;bundle-version="3.4.300", - org.eclipse.core.expressions + org.eclipse.ui.navigator.resources;bundle-version="3.4.300" Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.linuxtools.tmf.ui.tests", + org.eclipse.linuxtools.internal.tmf.ui.commands;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.dialogs;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.editors.handlers;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.preferences;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.project.handlers;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.signal;x-internal:=true, org.eclipse.linuxtools.tmf.ui.editors, org.eclipse.linuxtools.tmf.ui.project.model, org.eclipse.linuxtools.tmf.ui.project.wizards, diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java index 0398916fb7..fd53cdcfbb 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java @@ -384,14 +384,16 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi return; fDataModel.setCurrentEvent(fCurrentEventTime); fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, HISTOGRAM_BAR_WIDTH); - if (fScaledData != null) { - fCanvas.redraw(); - // Display histogram and update X-,Y-axis labels - fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime())); - fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime())); - fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue)); - // The Y-axis area might need to be re-sized - fMaxNbEventsText.getParent().layout(); + synchronized(fScaledData) { + if (fScaledData != null) { + fCanvas.redraw(); + // Display histogram and update X-,Y-axis labels + fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime())); + fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime())); + fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue)); + // The Y-axis area might need to be re-sized + fMaxNbEventsText.getParent().layout(); + } } } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java index b386e4f7b1..7cc41e51d0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java @@ -19,7 +19,7 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; -import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; /** * HistogramRequest @@ -38,7 +38,7 @@ public class HistogramRequest extends TmfEventRequest { // ------------------------------------------------------------------------ public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range, int rank, int nbEvents, ITmfDataRequest.ExecutionType execType) { - super(ITmfEvent.class, range, rank, nbEvents, TmfTrace.DEFAULT_TRACE_CACHE_SIZE, execType); + super(ITmfEvent.class, range, rank, nbEvents, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, execType); fHistogram = histogram; } -- 2.34.1