From: Francois Chouinard Date: Tue, 12 Jun 2012 12:43:40 +0000 (-0400) Subject: Revert "Fix for bug 381411: Incorrect experiment location after getNext." X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=f3fd42d101c1fe406f56b64cf776220218e75ca2;p=deliverable%2Ftracecompass.git Revert "Fix for bug 381411: Incorrect experiment location after getNext." This reverts commit 0f1360c864a16324f86dd0b6629c6c545a59110e. --- diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index b2b4a595ac..8a89d8e397 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -537,10 +537,10 @@ public class TmfExperimentTest extends TestCase { } // ------------------------------------------------------------------------ - // getNext - updates the context + // readtNextEvent - updates the context // ------------------------------------------------------------------------ - public void testGetNext() throws Exception { + public void testReadNextEvent() throws Exception { // On lower bound, returns the first event (ts = 0) final ITmfContext context = fExperiment.seekEvent(0); @@ -553,26 +553,6 @@ public class TmfExperimentTest extends TestCase { } } - public void testGetNextLocation() throws Exception { - - ITmfContext context1 = fExperiment.seekEvent(0); - fExperiment.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfEvent event1 = fExperiment.getNext(context1); - ITmfContext context2 = fExperiment.seekEvent(location); - ITmfEvent event2 = fExperiment.getNext(context2); - assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); - } - - public void testGetNextEndLocation() throws Exception { - ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); - fExperiment.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfContext context2 = fExperiment.seekEvent(location); - ITmfEvent event = fExperiment.getNext(context2); - assertNull("Event", event); - } - // ------------------------------------------------------------------------ // processRequest // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java index 740de4ceb6..b5d7198464 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java @@ -386,10 +386,10 @@ public class TmfMultiTraceExperimentTest extends TestCase { } // ------------------------------------------------------------------------ - // getNext - updates the context + // readtNextEvent - updates the context // ------------------------------------------------------------------------ - public void testGetNext() throws Exception { + public void testReadNextEvent() throws Exception { // On lower bound, returns the first event (ts = 0) final ITmfContext context = fExperiment.seekEvent(0); @@ -402,26 +402,6 @@ public class TmfMultiTraceExperimentTest extends TestCase { } } - public void testGetNextLocation() throws Exception { - - ITmfContext context1 = fExperiment.seekEvent(0); - fExperiment.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfEvent event1 = fExperiment.getNext(context1); - ITmfContext context2 = fExperiment.seekEvent(location); - ITmfEvent event2 = fExperiment.getNext(context2); - assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); - } - - public void testGetNextEndLocation() throws Exception { - ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); - fExperiment.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfContext context2 = fExperiment.seekEvent(location); - ITmfEvent event = fExperiment.getNext(context2); - assertNull("Event", event); - } - // ------------------------------------------------------------------------ // processRequest // ------------------------------------------------------------------------ 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 aacc1aef90..bb73b1bcab 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 @@ -35,7 +35,6 @@ 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.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; @@ -969,10 +968,10 @@ public class TmfTraceTest extends TestCase { } // ------------------------------------------------------------------------ - // getNext - updates the context + // readNextEvent - updates the context // ------------------------------------------------------------------------ - public void testGetNext() throws Exception { + public void testReadNextEvent() throws Exception { final int NB_READS = 20; @@ -993,26 +992,6 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", NB_READS, context.getRank()); } - public void testGetNextLocation() throws Exception { - - ITmfContext context1 = fTrace.seekEvent(0); - fTrace.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfEvent event1 = fTrace.getNext(context1); - ITmfContext context2 = fTrace.seekEvent(location); - ITmfEvent event2 = fTrace.getNext(context2); - assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); - } - - public void testGetNextEndLocation() throws Exception { - ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); - fTrace.getNext(context1); - ITmfLocation location = context1.getLocation().clone(); - ITmfContext context2 = fTrace.seekEvent(location); - ITmfEvent event = fTrace.getNext(context2); - assertNull("Event", event); - } - // ------------------------------------------------------------------------ // processRequest // ------------------------------------------------------------------------ @@ -1217,4 +1196,4 @@ public class TmfTraceTest extends TestCase { assertEquals("toString", expected, fTrace.toString()); } -} +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java index a5d0716f3a..a6a189cd16 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java @@ -263,6 +263,37 @@ public class TmfExperiment extends TmfTrace implements I // ITmfTrace trace positioning // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#seekEvent(long) + * + * TmfTrace.seekEvent(rank) will return a context that will position the + * trace to read the event at rank 'rank' in the trace. In the case of an + * experiment context, that event has to be actually read in the fEvents + * buffer and the corresponding trace context has to point to the next + * event (rank + 1) in the trace (the sum of the traces contexts ranks + * should equal [exp context rank + #traces] (corner cases not considered). + * + * In the likely case that TmfTrace.seekEvent() computed the context + * by using a read loop (reading from the experiment), the 'lastTraceRead' + * field will be set to the actual trace that needs to be read to obtain + * event at rank 'rank'. + * + * Therefore, if 'lastTraceRead' is set, we need to read that particular + * trace *and* then decrease the context rank (which has to correspond to + * the rank of the event to be returned next by TmfExperiemnt.getNext(). + */ + @Override + public synchronized ITmfContext seekEvent(final long rank) { + TmfExperimentContext context = (TmfExperimentContext) super.seekEvent(rank); + int lastTrace = context.getLastTrace(); + if (lastTrace != TmfExperimentContext.NO_TRACE) { + getNext(context); + context.setRank(rank); + context.setLastTrace(TmfExperimentContext.NO_TRACE); + } + return context; + } + /* (non-Javadoc) * * Returns a brand new context based on the location provided and @@ -379,6 +410,12 @@ public class TmfExperiment extends TmfTrace implements I final int lastTrace = expContext.getLastTrace(); if (lastTrace != TmfExperimentContext.NO_TRACE) { final ITmfContext traceContext = expContext.getContexts()[lastTrace]; + + TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); + if (location != null) { + location.getLocation().getLocations()[lastTrace] = traceContext.getLocation().clone(); + } + expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext); expContext.setLastTrace(TmfExperimentContext.NO_TRACE); } @@ -404,9 +441,6 @@ public class TmfExperiment extends TmfTrace implements I updateAttributes(expContext, event.getTimestamp()); expContext.increaseRank(); expContext.setLastTrace(trace); - final TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); - final ITmfContext traceContext = expContext.getContexts()[trace]; - location.getLocation().getLocations()[trace] = traceContext.getLocation().clone(); fExperimentContext = expContext; processEvent(event); }