From: Alexandre Montplaisir Date: Tue, 29 Jan 2013 22:02:22 +0000 (-0500) Subject: tmf: CtfTmfContext rename X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=81a2d02ecdfb198982de8c7fda2fd880cbf4759f;p=deliverable%2Ftracecompass.git tmf: CtfTmfContext rename Renamed from CtfTmfLightweighContext (there are no heavyweight contexts anymore) + fixed the clone() method. After much experimentation, I gave up trying to not make those extend TmfContext (sorry bug 387929). It seems the iterator manager depends on CtfTmfContext.equals() to not be overriden. Fixing this behavior (by making the manager track the locations instead of the contexts, for example) works, but then reading events becomes unbearably slow. I think it's better to not touch this until a proper iterator API comes to TMF, at which point we can use that directly. Change-Id: I57cedac2702d0b70950687bdfa7a681ac7582be8 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/10194 Tested-by: Hudson CI Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse --- diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java index 7af0b41aa8..894f5450db 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java @@ -29,7 +29,7 @@ import org.junit.runners.Suite; CtfIteratorTest.class, CtfLocationDataTest.class, CtfLocationTest.class, - CtfTmfLightweightContextTest.class, + CtfTmfContextTest.class, CtfTmfEventFieldTest.class, CtfTmfEventTest.class, CtfTmfEventTypeTest.class, diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java new file mode 100644 index 0000000000..d95217398b --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Khouzam - Initial implementation + * Alexandre Montplaisir + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; + +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; + +import org.eclipse.core.resources.IResource; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests for the CtfTmfLightweightContext class + * + * @author Matthew Khouzam + * @version 1.1 + */ +public class CtfTmfContextTest { + + private static final String PATH = TestParams.getPath(); + private static final long begin = 1332170682440133097L; /* Trace start time */ + private static final long end = 1332170692664579801L; /* Trace end time */ + + private CtfTmfTrace trace; + + private class SeekerThread extends Thread { + long val; + + public void setVal(long val) { + this.val = val; + } + } + + /** + * Pre-test initialization + * + * @throws TmfTraceException + * If the trace couldn't be init'ed, which shouldn't happen. + */ + @Before + public void setUp() throws TmfTraceException { + trace = new CtfTmfTrace(); + trace.initTrace((IResource) null, PATH, CtfTmfEvent.class); + } + + /** + * Index all the events in the test trace. + */ + @Test + public void testIndexing() { + CtfTmfContext context = new CtfTmfContext(trace); + context.seek(0); + + int count = 0; + while (trace.getNext(context) != null) { + count++; + } + assertTrue(count > 0); + } + + /** + * Context fuzzer. Use an amount of contexts greater than the size of the + * iterator cache and have them access the trace in parallel. + * + * @throws InterruptedException + * Would fail the test + */ + @Test + public void testTooManyContexts() throws InterruptedException { + final int lwcCount = 101; + double increment = (end - begin) / lwcCount; + final ArrayList vals = new ArrayList(); + final ArrayList threads = new ArrayList(); + final ArrayList tooManyContexts = new ArrayList(); + + for (double i = begin; i < end; i += increment) { + SeekerThread thread = new SeekerThread() { + @Override + public void run() { + CtfTmfContext lwc = new CtfTmfContext(trace); + lwc.seek(val); + trace.getNext(lwc); + synchronized(trace){ + if (lwc.getCurrentEvent() != null) { + vals.add(lwc.getCurrentEvent().getTimestamp().getValue()); + } + tooManyContexts.add(lwc); + } + } + }; + thread.setVal((long)i); + threads.add(thread); + thread.start(); + } + + for( Thread t: threads){ + t.join(); + } + + for( Long val : vals){ + assertTrue(val >= begin); + assertTrue(val <= end); + } + } + + /** + * Test for clone method + */ + @Test + public void testClone() { + CtfTmfContext fixture1 = new CtfTmfContext(trace); + CtfTmfContext fixture2 = fixture1.clone(); + //assertTrue(fixture1.equals(fixture2)); FIXME no .equals() override! + assertNotSame(fixture1, fixture2); + + /* Make sure clone() did its job */ + assertSame(fixture1.getTrace(), fixture2.getTrace()); + assertSame(fixture1.getLocation(), fixture2.getLocation()); + assertSame(fixture1.getRank(), fixture2.getRank()); + } +} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java deleted file mode 100644 index c345509736..0000000000 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial implementation - * Alexandre Montplaisir - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; - -import org.eclipse.core.resources.IResource; -import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; -import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfLightweightContext; -import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; -import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests for the CtfTmfLightweightContext class - * - * @author Matthew Khouzam - * @version 1.1 - */ -public class CtfTmfLightweightContextTest { - - private static final String PATH = TestParams.getPath(); - private static final long begin = 1332170682440133097L; /* Trace start time */ - private static final long end = 1332170692664579801L; /* Trace end time */ - - private CtfTmfTrace fixture; - - private class SeekerThread extends Thread { - long val; - - public void setVal(long val) { - this.val = val; - } - } - - /** - * Pre-test initialization - * - * @throws TmfTraceException - * If the trace couldn't be init'ed, which shouldn't happen. - */ - @Before - public void setUp() throws TmfTraceException { - fixture = new CtfTmfTrace(); - fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class); - } - - /** - * Index all the events in the test trace. - */ - @Test - public void testIndexing() { - CtfTmfLightweightContext context = new CtfTmfLightweightContext(fixture); - context.seek(0); - - int count = 0; - while (fixture.getNext(context) != null) { - count++; - } - assertTrue(count > 0); - } - - /** - * Context fuzzer. Use an amount of contexts greater than the size of the - * iterator cache and have them access the trace in parallel. - * - * @throws InterruptedException - * Would fail the test - */ - @Test - public void testTooManyContexts() throws InterruptedException { - final int lwcCount = 101; - double increment = (end - begin) / lwcCount; - final ArrayList vals = new ArrayList(); - final ArrayList threads = new ArrayList(); - final ArrayList tooManyContexts = new ArrayList(); - - for (double i = begin; i < end; i += increment) { - SeekerThread thread = new SeekerThread() { - @Override - public void run() { - CtfTmfLightweightContext lwc = new CtfTmfLightweightContext(fixture); - lwc.seek(val); - fixture.getNext(lwc); - synchronized(fixture){ - if (lwc.getCurrentEvent() != null) { - vals.add(lwc.getCurrentEvent().getTimestamp().getValue()); - } - tooManyContexts.add(lwc); - } - } - }; - thread.setVal((long)i); - threads.add(thread); - thread.start(); - } - - for( Thread t: threads){ - t.join(); - } - - for( Long val : vals){ - assertTrue(val >= begin); - assertTrue(val <= end); - } - } -} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java index dca3716795..75a931463b 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java @@ -15,7 +15,7 @@ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; import java.util.Vector; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; -import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfLightweightContext; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; @@ -55,7 +55,7 @@ public class Benchmark { start = System.nanoTime(); if (nbEvent != -1) { - final CtfTmfLightweightContext traceReader = (CtfTmfLightweightContext) trace.seekEvent(0); + final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0); start = System.nanoTime(); CtfTmfEvent current = traceReader.getCurrentEvent(); 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 0ebacde13d..a97fca8b55 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 @@ -25,7 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; * @author Matthew Khouzam */ public class CtfIterator extends CTFTraceReader implements ITmfContext, - Comparable, Cloneable { + Comparable { private final CtfTmfTrace ctfTmfTrace; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java index db14b396c2..1abf28b002 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java @@ -65,9 +65,10 @@ public abstract class CtfIteratorManager { * @param ctx * the context * @return the iterator + * @since 2.0 */ public static synchronized CtfIterator getIterator(final CtfTmfTrace trace, - final CtfTmfLightweightContext ctx) { + final CtfTmfContext ctx) { return map.get(trace).getIterator(ctx); } } @@ -86,11 +87,11 @@ class CtfTraceManager { /* * The map of the cache. */ - private final HashMap fMap; + private final HashMap fMap; /* * An array pointing to the same cache. this allows fast "random" accesses. */ - private final ArrayList fRandomAccess; + private final ArrayList fRandomAccess; /* * The parent trace */ @@ -101,8 +102,8 @@ class CtfTraceManager { private final Random fRnd; public CtfTraceManager(CtfTmfTrace trace) { - fMap = new HashMap(); - fRandomAccess = new ArrayList(); + fMap = new HashMap(); + fRandomAccess = new ArrayList(); fRnd = new Random(System.nanoTime()); fTrace = trace; } @@ -122,7 +123,7 @@ class CtfTraceManager { * the context to look up * @return the iterator refering to the context */ - public CtfIterator getIterator(final CtfTmfLightweightContext context) { + public CtfIterator getIterator(final CtfTmfContext context) { /* * if the element is in the map, we don't need to do anything else. */ @@ -161,7 +162,7 @@ class CtfTraceManager { * @param elem * the iterator */ - private void addElement(final CtfTmfLightweightContext context, + private void addElement(final CtfTmfContext context, final CtfIterator elem) { fMap.put(context, elem); fRandomAccess.add(context); @@ -175,7 +176,7 @@ class CtfTraceManager { * @return the iterator of the removed elements. */ private CtfIterator replaceRandomElement( - final CtfTmfLightweightContext context) { + final CtfTmfContext context) { /* * This needs some explanation too: We need to select a random victim * and remove it. The order of the elements is not important, so instead @@ -185,7 +186,7 @@ class CtfTraceManager { */ final int size = fRandomAccess.size(); final int pos = fRnd.nextInt(size); - final CtfTmfLightweightContext victim = fRandomAccess.get(pos); + final CtfTmfContext victim = fRandomAccess.get(pos); fRandomAccess.set(pos, context); final CtfIterator elem = fMap.remove(victim); fMap.put(context, elem); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java new file mode 100644 index 0000000000..9f6e2856e7 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; + +/** + * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to + * a boxed Long, a long and an int. + * + * @author Matthew Khouzam + * @version 1.0 + * @since 2.0 + */ +public class CtfTmfContext implements ITmfContext { + + // ------------------------------------------- + // Fields + // ------------------------------------------- + + private CtfLocation curLocation; + private long curRank; + + private final CtfTmfTrace fTrace; + + // ------------------------------------------- + // Constructor + // ------------------------------------------- + + /** + * Constructor + * + * @param ctfTmfTrace + * the parent trace + * @since 1.1 + */ + public CtfTmfContext(CtfTmfTrace ctfTmfTrace) { + fTrace = ctfTmfTrace; + curLocation = new CtfLocation(new CtfLocationData(0, 0)); + } + + // ------------------------------------------- + // TmfContext Overrides + // ------------------------------------------- + + @Override + public long getRank() { + return curRank; + } + + @Override + public ITmfLocation getLocation() { + return curLocation; + } + + @Override + public boolean hasValidRank() { + return curRank != CtfLocation.INVALID_LOCATION.getTimestamp(); + } + + @Override + public void setLocation(ITmfLocation location) { + curLocation = (CtfLocation) location; + if (curLocation != null) { + getIterator().seek(curLocation.getLocationInfo()); + } + } + + @Override + public void setRank(long rank) { + curRank = rank; + + } + + @Override + public void increaseRank() { + if (hasValidRank()) { + curRank++; + } + } + + // ------------------------------------------- + // CtfTmfTrace Helpers + // ------------------------------------------- + + /** + * Gets the trace of this context. + * + * @return The trace of this context + */ + public CtfTmfTrace getTrace() { + return fTrace; + } + + /** + * Gets the current event. Wrapper to help CtfTmfTrace + * + * @return The event or null + */ + public synchronized CtfTmfEvent getCurrentEvent() { + return getIterator().getCurrentEvent(); + } + + /** + * Advances to a the next event. Wrapper to help CtfTmfTrace + * + * @return success or not + */ + public synchronized boolean advance() { + final CtfLocationData curLocationData = this.curLocation.getLocationInfo(); + boolean retVal = getIterator().advance(); + CtfTmfEvent currentEvent = getIterator().getCurrentEvent(); + + if (currentEvent != null) { + final long timestampValue = currentEvent.getTimestamp().getValue(); + if (curLocationData.getTimestamp() == timestampValue) { + curLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1); + } else { + curLocation = new CtfLocation(timestampValue, 0L); + } + } else { + curLocation = new CtfLocation(CtfLocation.INVALID_LOCATION); + } + + return retVal; + } + + @Override + public void dispose() { + // do nothing + } + + /** + * Seeks to a given timestamp. Wrapper to help CtfTmfTrace + * + * @param timestamp + * desired timestamp + * @return success or not + */ + public synchronized boolean seek(final long timestamp) { + curLocation = new CtfLocation(timestamp, 0); + return getIterator().seek(timestamp); + } + + /** + * Seeks to a given location. Wrapper to help CtfTmfTrace + * @param location + * unique location to find the event. + * + * @return success or not + * @since 2.0 + */ + public synchronized boolean seek(final CtfLocationData location) { + curLocation = new CtfLocation(location); + return getIterator().seek(location); + } + + @Override + public CtfTmfContext clone() { + CtfTmfContext ret = null; + try { + ret = (CtfTmfContext) super.clone(); + /* Fields are immutable, no need to deep-copy them */ + } catch (CloneNotSupportedException e) { + /* Should not happen, we're calling Object.clone() */ + } + return ret; + } + + // ------------------------------------------- + // Private helpers + // ------------------------------------------- + + /** + * Get iterator, called every time to get an iterator, no local copy is + * stored so that there is no need to "update" + * + * @return an iterator + */ + private CtfIterator getIterator() { + return CtfIteratorManager.getIterator(fTrace, this); + } +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java deleted file mode 100644 index f1162f8448..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.ctfadaptor; - -import java.util.ArrayList; -import java.util.ListIterator; - -import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; -import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; - -/** - * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to - * a boxed Long, a long and an int. - * - * @version 1.0 - * @author Matthew Khouzam - */ -public class CtfTmfLightweightContext implements ITmfContext { - - // ------------------------------------------- - // Fields - // ------------------------------------------- - private CtfLocation curLocation; - private long curRank; - - private final CtfTmfTrace fTrace; - - // ------------------------------------------- - // Constructor - // ------------------------------------------- - /** - * Deprecated, use CtfTmfLightweightContext( CtfTmfTrace please ) - * - * @param iters - * the shared iterator pool. - * @param pos - * the iterator position. - */ - @Deprecated - public CtfTmfLightweightContext(ArrayList iters, - ListIterator pos) { - fTrace = iters.get(0).getCtfTmfTrace(); - curLocation = new CtfLocation(new CtfLocationData(0, 0)); - } - - /** - * - * @param ctfTmfTrace - * the parent trace - * @since 1.1 - */ - public CtfTmfLightweightContext(CtfTmfTrace ctfTmfTrace) { - fTrace = ctfTmfTrace; - curLocation = new CtfLocation(new CtfLocationData(0, 0)); - } - - // ------------------------------------------- - // TmfContext Overrides - // ------------------------------------------- - - @Override - public long getRank() { - return curRank; - } - - @Override - public ITmfLocation getLocation() { - return curLocation; - } - - @Override - public boolean hasValidRank() { - return curRank != CtfLocation.INVALID_LOCATION.getTimestamp(); - } - - @Override - public void setLocation(ITmfLocation location) { - curLocation = (CtfLocation) location; - if (curLocation != null) { - getIterator().seek(curLocation.getLocationInfo()); - } - } - - @Override - public void setRank(long rank) { - curRank = rank; - - } - - @Override - public void increaseRank() { - if (hasValidRank()) { - curRank++; - } - } - - // ------------------------------------------- - // CtfTmfTrace Helpers - // ------------------------------------------- - - /** - * Gets the current event. Wrapper to help CtfTmfTrace - * - * @return The event or null - */ - public synchronized CtfTmfEvent getCurrentEvent() { - return getIterator().getCurrentEvent(); - } - - /** - * Advances to a the next event. Wrapper to help CtfTmfTrace - * - * @return success or not - */ - public synchronized boolean advance() { - final CtfLocationData curLocationData = this.curLocation.getLocationInfo(); - boolean retVal = getIterator().advance(); - CtfTmfEvent currentEvent = getIterator().getCurrentEvent(); - - if (currentEvent != null) { - final long timestampValue = currentEvent.getTimestamp().getValue(); - if (curLocationData.getTimestamp() == timestampValue) { - curLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1); - } else { - curLocation = new CtfLocation(timestampValue, 0L); - } - } else { - curLocation = new CtfLocation(CtfLocation.INVALID_LOCATION); - } - - return retVal; - } - - @Override - public void dispose() { - // do nothing - } - - /** - * Seeks to a given timestamp. Wrapper to help CtfTmfTrace - * - * @param timestamp - * desired timestamp - * @return success or not - */ - public synchronized boolean seek(final long timestamp) { - curLocation = new CtfLocation(timestamp, 0); - return getIterator().seek(timestamp); - } - - /** - * Seeks to a given location. Wrapper to help CtfTmfTrace - * @param location - * unique location to find the event. - * - * @return success or not - * @since 2.0 - */ - public synchronized boolean seek(final CtfLocationData location) { - curLocation = new CtfLocation(location); - return getIterator().seek(location); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#clone() - */ - @Override - public CtfTmfLightweightContext clone() { - CtfTmfLightweightContext ret = new CtfTmfLightweightContext(fTrace); - ret.curLocation = curLocation.clone(); - ret.curRank = curRank; - return ret; - } - - // ------------------------------------------- - // Private helpers - // ------------------------------------------- - /** - * Get iterator, called every time to get an iterator, no local copy is - * stored so that there is no need to "update" - * - * @return an iterator - */ - private CtfIterator getIterator() { - return CtfIteratorManager.getIterator(fTrace, this); - } -} 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 ef5852ae05..7a78f092a4 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 @@ -80,9 +80,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { try { this.fTrace = new CTFTrace(path); CtfIteratorManager.addTrace(this); - CtfTmfLightweightContext ctx; + CtfTmfContext ctx; /* Set the start and (current) end times for this trace */ - ctx = (CtfTmfLightweightContext) seekEvent(0L); + ctx = (CtfTmfContext) seekEvent(0L); CtfTmfEvent event = getNext(ctx); if((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) { /* Handle the case where the trace is empty */ @@ -151,7 +151,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { @Override public double getLocationRatio(ITmfLocation location) { final CtfLocation curLocation = (CtfLocation) location; - final CtfTmfLightweightContext context = new CtfTmfLightweightContext(this); + final CtfTmfContext context = new CtfTmfContext(this); context.setLocation(curLocation); context.seek(curLocation.getLocationInfo()); final CtfLocationData currentTime = ((CtfLocationData)context.getLocation().getLocationInfo()); @@ -169,7 +169,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { @Override public synchronized ITmfContext seekEvent(final ITmfLocation location) { CtfLocation currentLocation = (CtfLocation) location; - CtfTmfLightweightContext context = new CtfTmfLightweightContext(this); + CtfTmfContext context = new CtfTmfContext(this); if (fTrace == null) { context.setLocation(null); context.setRank(ITmfContext.UNKNOWN_RANK); @@ -203,7 +203,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { @Override public synchronized ITmfContext seekEvent(double ratio) { - CtfTmfLightweightContext context = new CtfTmfLightweightContext(this); + CtfTmfContext context = new CtfTmfContext(this); if (fTrace == null) { context.setLocation(null); context.setRank(ITmfContext.UNKNOWN_RANK); @@ -230,11 +230,11 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { return null; } CtfTmfEvent event = null; - if (context instanceof CtfTmfLightweightContext) { + if (context instanceof CtfTmfContext) { if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) { return null; } - CtfTmfLightweightContext ctfContext = (CtfTmfLightweightContext) context; + CtfTmfContext ctfContext = (CtfTmfContext) context; event = ctfContext.getCurrentEvent(); if (event != null) { @@ -311,8 +311,8 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { @Override public CtfTmfEvent parseEvent(ITmfContext context) { CtfTmfEvent event = null; - if( context instanceof CtfTmfLightweightContext ){ - CtfTmfLightweightContext itt = (CtfTmfLightweightContext) context.clone(); + if( context instanceof CtfTmfContext ){ + CtfTmfContext itt = (CtfTmfContext) context.clone(); event = itt.getCurrentEvent(); } return event; @@ -329,7 +329,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { // Helpers //------------------------------------------- - private static CtfIterator getIterator(CtfTmfTrace trace, CtfTmfLightweightContext context) { + private static CtfIterator getIterator(CtfTmfTrace trace, CtfTmfContext context) { return CtfIteratorManager.getIterator(trace, context); } 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 3d6fa30ceb..1c2cd13ba2 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 @@ -26,7 +26,7 @@ package org.eclipse.linuxtools.tmf.core.trace; * * @see ITmfLocation */ -public interface ITmfContext { +public interface ITmfContext extends Cloneable { // ------------------------------------------------------------------------ // Constants 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 6e08185653..2555e7a6d0 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 @@ -24,7 +24,7 @@ package org.eclipse.linuxtools.tmf.core.trace; * * @see ITmfLocation */ -public class TmfContext implements ITmfContext, Cloneable { +public class TmfContext implements ITmfContext { // ------------------------------------------------------------------------ // Attributes