From 408e65d267a3d30eb7e2fbfd7e7a4be3a2c9019b Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Mon, 4 Jun 2012 11:41:35 -0400 Subject: [PATCH] Replace location by context in checkpoint indexer --- .../core/tests/trace/TmfCheckpointTest.java | 4 +- .../core/trace/TmfExperimentCheckpoint.java | 13 ++++--- .../tmf/core/trace/TmfExperimentContext.java | 33 ++++++++++------ .../tmf/core/component/TmfDataProvider.java | 5 ++- .../tmf/core/ctfadaptor/CtfIterator.java | 11 +----- .../tmf/core/ctfadaptor/CtfLocation.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 2 +- .../tmf/core/trace/ITmfCheckpoint.java | 2 +- .../tmf/core/trace/ITmfContext.java | 8 ++-- .../tmf/core/trace/TmfCheckpoint.java | 13 +++---- .../tmf/core/trace/TmfCheckpointIndexer.java | 12 +++--- .../linuxtools/tmf/core/trace/TmfContext.java | 8 ---- .../tmf/core/trace/TmfExperiment.java | 38 ++++++++----------- .../linuxtools/tmf/core/trace/TmfTrace.java | 10 +++-- 14 files changed, 76 insertions(+), 85 deletions(-) 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 fc786073b5..fb0872f014 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 @@ -113,8 +113,8 @@ public class TmfCheckpointTest extends TestCase { checkpoint1 = new TmfCheckpoint(fTimestamp1, null); checkpoint2 = checkpoint1.clone(); assertEquals("clone", checkpoint1, checkpoint2); - assertNull(checkpoint1.getLocation()); - assertNull(checkpoint2.getLocation()); + assertNull(checkpoint1.getContext()); + assertNull(checkpoint2.getContext()); checkpoint1 = new TmfCheckpoint(null, new TmfContext(fLocation1)); checkpoint3 = checkpoint1.clone(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentCheckpoint.java index 09cd982dc0..d103252142 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentCheckpoint.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentCheckpoint.java @@ -27,7 +27,7 @@ public class TmfExperimentCheckpoint implements Comparable extends TmfComponent if (Tracer.isRequestTraced()) Tracer.traceRequest(request, "read first event"); //$NON-NLS-1$ while (data != null && !isCompleted(request, data, nbRead)) { -// if (fLogData) -// Tracer.traceEvent(provider, request, data); + if (fLogData) { + Tracer.traceEvent(provider, request, data); + } if (request.getDataType().isInstance(data)) { request.handleData(data); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java index f688f9d7a7..a2f57ab297 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java @@ -152,19 +152,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparab @Override public CtfIterator clone() { CtfIterator clone = null; - clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent() - .getTimestampValue(), curRank); + clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent().getTimestampValue(), curRank); return clone; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#clone2() - */ - @Override - public CtfIterator clone2() { - return clone(); - } - /** * Method dispose. * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose() diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java index fcb2b2bf40..d87c413f59 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java @@ -64,7 +64,7 @@ public class CtfLocation implements ITmfLocation, Cloneable { */ @Override public CtfLocation clone() { - return new CtfLocation(getLocation()); + return new CtfLocation(getLocation().longValue()); } /* (non-Javadoc) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index be3f94d457..02ef51d97b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -315,7 +315,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParse public CtfTmfEvent parseEvent(ITmfContext context) { CtfTmfEvent event = null; if( context instanceof CtfIterator ){ - CtfIterator itt = (CtfIterator) context; + CtfIterator itt = (CtfIterator) context.clone(); event = itt.getCurrentEvent(); } return event; 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 aaead0c174..6eda5c7295 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 @@ -36,7 +36,7 @@ public interface ITmfCheckpoint extends Comparable { public ITmfTimestamp getTimestamp(); /** - * @return the trace context + * @return the location of the event referred to by the context */ public ITmfContext getContext(); 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 1d78bb6998..62d2c1bf76 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 @@ -85,9 +85,9 @@ public interface ITmfContext { */ public ITmfContext clone(); - /** - * @return a clone of the context - */ - public ITmfContext clone2(); +// /** +// * @return a clone of the context +// */ +// public ITmfContext clone2(); } 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 f74391e178..9740dac623 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 @@ -107,16 +107,15 @@ public class TmfCheckpoint implements ITmfCheckpoint, Cloneable { * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation() */ @Override - public ITmfLocation getLocation() { - return (fContext != null) ? fContext.getLocation() : null; + public ITmfContext getContext() { + return fContext; } /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getContext() + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation() */ - @Override - public ITmfContext getContext() { - return fContext; + public ITmfLocation> getLocation() { + return fContext.getLocation(); } // ------------------------------------------------------------------------ @@ -133,7 +132,7 @@ public class TmfCheckpoint implements ITmfCheckpoint, Cloneable { @SuppressWarnings({ "unchecked", "rawtypes" }) public int compareTo(final ITmfCheckpoint other) { if (fTimestamp == null || other.getTimestamp() == null) { - final Comparable location1 = fContext.getLocation().getLocation(); + final Comparable location1 = getLocation().getLocation(); final Comparable location2 = other.getLocation().getLocation(); return location1.compareTo(location2); } 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 cb8de737ec..f2b4688c39 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 @@ -245,7 +245,7 @@ public class TmfCheckpointIndexer> implements ITm final long position = rank / fCheckpointInterval; // Add new entry at proper location (if empty) if (fTraceIndex.size() == position) { - fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), context.clone2())); + fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), context.clone())); } } } @@ -275,7 +275,7 @@ public class TmfCheckpointIndexer> implements ITm } // Position the trace at the checkpoint - return seekCheckpoint(index); + return restoreCheckpoint(index); } /* (non-Javadoc) @@ -293,7 +293,7 @@ public class TmfCheckpointIndexer> implements ITm final int index = (int) rank / fCheckpointInterval; // Position the trace at the checkpoint - return seekCheckpoint(index); + return restoreCheckpoint(index); } /** @@ -302,7 +302,7 @@ public class TmfCheckpointIndexer> implements ITm * @param checkpoint the checkpoint index * @return the corresponding context */ - private ITmfContext seekCheckpoint(final int checkpoint) { + private ITmfContext restoreCheckpoint(final int checkpoint) { ITmfLocation location = null; int index = 0; synchronized (fTraceIndex) { @@ -311,9 +311,7 @@ public class TmfCheckpointIndexer> implements ITm if (index >= fTraceIndex.size()) { index = fTraceIndex.size() - 1; } - final ITmfContext context = fTraceIndex.get(index).getContext().clone2(); -// fTrace.seekEvent(context.getLocation()); - return context; + return fTraceIndex.get(index).getContext().clone(); } } final ITmfContext context = fTrace.seekEvent(location); 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 f8efb047bc..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 @@ -99,14 +99,6 @@ public class TmfContext implements ITmfContext, Cloneable { return clone; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#clone2() - */ - @Override - public TmfContext clone2() { - return clone(); - } - // ------------------------------------------------------------------------ // ITmfContext // ------------------------------------------------------------------------ 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 fa06bd49fa..15698f92f1 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 @@ -231,7 +231,7 @@ public class TmfExperiment extends TmfTrace implements I // ------------------------------------------------------------------------ @Override - protected ITmfContext armRequest(final ITmfDataRequest request) { + protected synchronized ITmfContext armRequest(final ITmfDataRequest request) { if (request instanceof ITmfEventRequest && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime()) && request.getIndex() == 0) @@ -335,40 +335,26 @@ public class TmfExperiment extends TmfTrace implements I // ------------------------------------------------------------------------ /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser#parseEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) */ @Override - public synchronized T getNext(final ITmfContext context) { - final ITmfContext previousContext = context.clone(); - final T event = parseEvent(context); - if (event != null) { - updateAttributes(previousContext, event.getTimestamp()); - - fExperimentContext = (TmfExperimentContext) context; - int trace = fExperimentContext.getLastTrace(); - if (trace != TmfExperimentContext.NO_TRACE) { - TmfExperimentLocation location = (TmfExperimentLocation) fExperimentContext.getLocation(); - location.getLocation().getLocations()[trace] = fExperimentContext.getContexts()[trace].getLocation(); - } - - context.increaseRank(); - processEvent(event); - } + public synchronized T parseEvent(final ITmfContext context) { + final ITmfContext savedContext = context.clone(); + final T event = getNext(savedContext); return event; } /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser#parseEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) + * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) */ @SuppressWarnings("unchecked") @Override - public T parseEvent(ITmfContext context) { + public synchronized T getNext(ITmfContext context) { // Validate the context if (!(context instanceof TmfExperimentContext)) { return null; // Throw an exception? } - TmfExperimentContext expContext = (TmfExperimentContext) context; // If an event was consumed previously, first get the next one from that trace @@ -396,9 +382,17 @@ public class TmfExperiment extends TmfTrace implements I T event = null; if (trace != TmfExperimentContext.NO_TRACE) { event = (T) expContext.getEvents()[trace]; + if (event != null) { + updateAttributes(expContext, event.getTimestamp()); + TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation(); + location.getLocation().getLocations()[trace] = expContext.getContexts()[trace].getLocation(); + expContext.increaseRank(); + expContext.setLastTrace(trace); + fExperimentContext = expContext; + processEvent(event); + } } - expContext.setLastTrace(trace); return event; } 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 3303c6ba8b..c308b92622 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 @@ -459,6 +459,11 @@ public abstract class TmfTrace extends TmfEventProvider event = getNext(context); } } +// System.out.println("seekEvent() before parseEvent() context=" + context); +// ITmfEvent event = fParser.parseEvent(context); +// System.out.println("seekEvent() after parseEvent() context=" + context + " TS=" + event.getTimestamp()); +// event = fParser.parseEvent(context); +// System.out.println("seekEvent() after parseEvent() context=" + context + " TS=" + event.getTimestamp()); return context; } @@ -476,14 +481,13 @@ public abstract class TmfTrace extends TmfEventProvider } // Position the trace at the checkpoint - final ITmfContext context = fIndexer.seekIndex(timestamp); + ITmfContext context = fIndexer.seekIndex(timestamp); // And locate the requested event context final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype... ITmfEvent event = getNext(nextEventContext); while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { - context.setLocation(nextEventContext.getLocation().clone()); - context.increaseRank(); + context = nextEventContext.clone(); event = getNext(nextEventContext); } if (event == null) { -- 2.34.1