From ea271da66fba6eb855708b1197e7f676e8693385 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 19 Feb 2013 14:26:02 -0500 Subject: [PATCH] Remove context clone and add trace ranks to experiment location Change-Id: I97bf73d63e2788d66013e4c5cfb2057083ba5de4 Reviewed-on: https://git.eclipse.org/r/10460 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir Tested-by: Alexandre Montplaisir Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Reviewed-by: Patrick Tasse --- .../tests/ctfadaptor/CtfTmfContextTest.java | 21 +--- .../core/tests/trace/TmfCheckpointTest.java | 32 +++--- .../tmf/core/tests/trace/TmfContextTest.java | 28 +---- .../TmfExperimentCheckpointIndexTest.java | 34 ++---- .../core/tests/trace/TmfExperimentTest.java | 13 +-- .../tmf/tests/stubs/trace/TmfTraceStub.java | 5 +- .../tmf/core/trace/TmfExperimentContext.java | 79 ++----------- .../tmf/core/trace/TmfExperimentLocation.java | 24 +--- .../tmf/core/trace/TmfLocationArray.java | 108 ++++++++++++++---- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 12 +- .../tmf/core/trace/ITmfCheckpoint.java | 12 +- .../tmf/core/trace/ITmfContext.java | 10 +- .../tmf/core/trace/TmfCheckpoint.java | 42 +++---- .../tmf/core/trace/TmfCheckpointIndexer.java | 71 +----------- .../linuxtools/tmf/core/trace/TmfContext.java | 22 +--- .../tmf/core/trace/TmfExperiment.java | 65 ++++++----- .../linuxtools/tmf/core/trace/TmfTrace.java | 19 +-- 17 files changed, 222 insertions(+), 375 deletions(-) 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 index c75d733b81..528405f8cb 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,12 +9,11 @@ * Contributors: * Matthew Khouzam - Initial implementation * Alexandre Montplaisir + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ 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 static org.junit.Assume.assumeTrue; @@ -124,20 +123,4 @@ public class CtfTmfContextTest { 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/trace/TmfCheckpointTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java index 95c2535e44..d8d8187254 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 @@ -10,6 +10,7 @@ * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 * Alexandre Montplaisir - Port to JUnit4 + * Patrick Tasse - Updated for location in checkpoint *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -23,7 +24,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; -import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; import org.junit.Test; @@ -48,9 +48,9 @@ public class TmfCheckpointTest { private ITmfLocation fLocation2 = new TmfLongLocation(aLong2); private ITmfLocation fLocation3 = new TmfLongLocation(aLong3); - private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation1)); - private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, new TmfContext(fLocation2)); - private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, new TmfContext(fLocation3)); + private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); + private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2); + private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3); // ------------------------------------------------------------------------ // Constructors @@ -104,10 +104,10 @@ public class TmfCheckpointTest { @Test public void testCompareToNull() { - final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, new TmfContext(fLocation1)); - final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, new TmfContext(fLocation2)); - final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, new TmfContext(fLocation3)); - final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, new TmfContext(fLocation1)); + final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1); + final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, fLocation2); + final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, fLocation3); + final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, fLocation1); // Test the various 'null' vs. '!null' combinations assertEquals("compareTo", 0, checkpoint1.compareTo(fCheckpoint1)); @@ -144,7 +144,7 @@ public class TmfCheckpointTest { @Test public void testHashCodeNull() { - final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, new TmfContext(fLocation1)); + final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null); final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint1); final TmfCheckpoint checkpoint4 = new TmfCheckpoint(checkpoint2); @@ -195,11 +195,11 @@ public class TmfCheckpointTest { @Test public void testNotEqual() { // Various checkpoints - final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation1)); - final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, new TmfContext(fLocation1)); - final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation2)); + final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); + final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1); + final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2); final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null); - final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, new TmfContext(fLocation1)); + final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1); // Null check assertFalse("equals", checkpoint1.equals(null)); @@ -224,11 +224,11 @@ public class TmfCheckpointTest { @Test public void testToString() { - final String expected1 = "TmfCheckpoint [fContext=" + fCheckpoint1.getContext() + + final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() + ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]"; - final String expected2 = "TmfCheckpoint [fContext=" + fCheckpoint2.getContext() + + final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() + ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]"; - final String expected3 = "TmfCheckpoint [fContext=" + fCheckpoint3.getContext() + + final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() + ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]"; assertEquals("toString", expected1, fCheckpoint1.toString()); 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 2358768c92..07116f55c0 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 @@ -10,13 +10,13 @@ * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 * Alexandre Montplaisir - Port to JUnit4 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -228,32 +228,6 @@ public class TmfContextTest { assertEquals("toString", expected3, fContext3.toString()); } - // ------------------------------------------------------------------------ - // clone - // ------------------------------------------------------------------------ - - @Test - public void testClone() { - try { - final TmfContext context1 = fContext1.clone(); - final TmfContext context2 = fContext2.clone(); - final TmfContext context3 = fContext3.clone(); - - assertEquals("clone", context1, fContext1); - assertEquals("clone", context2, fContext2); - assertEquals("clone", context3, fContext3); - - context1.setLocation(null); - final TmfContext context4 = context1.clone(); - assertEquals("clone", context1, context4); - assertNull(context1.getLocation()); - assertNull(context4.getLocation()); - - } catch (final InternalError e) { - fail("clone()"); - } - } - // ------------------------------------------------------------------------ // setLocation, setRank, updateRank // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java index f439c95f57..8fbe14f406 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Alexandre Montplaisir - Port to JUnit4 + * Patrick Tasse - Updated for ranks in experiment location *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -24,9 +25,6 @@ import java.util.List; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; -import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; -import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; @@ -34,8 +32,8 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; import org.junit.After; @@ -128,16 +126,10 @@ public class TmfExperimentCheckpointIndexTest { // Validate that each checkpoint points to the right event for (int i = 0; i < checkpoints.size(); i++) { ITmfCheckpoint checkpoint = checkpoints.get(i); - TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation(); - TmfLocationArray locations = expLocation.getLocationInfo(); - ITmfContext[] trcContexts = new ITmfContext[2]; - trcContexts[0] = new TmfContext(locations.getLocation(0), (i * pageSize) / 2); - trcContexts[1] = new TmfContext(locations.getLocation(1), (i * pageSize) / 2); - TmfExperimentContext expContext = new TmfExperimentContext(trcContexts); - expContext.getEvents()[0] = fTestTraces[0].getNext(fTestTraces[0].seekEvent((i * pageSize) / 2)); - expContext.getEvents()[1] = fTestTraces[1].getNext(fTestTraces[1].seekEvent((i * pageSize) / 2)); - ITmfEvent event = fExperiment.parseEvent(expContext); - assertTrue(expContext.getRank() == i * pageSize); + ITmfLocation location = checkpoint.getLocation(); + ITmfContext context = fExperiment.seekEvent(location); + ITmfEvent event = fExperiment.parseEvent(context); + assertTrue(context.getRank() == i * pageSize); assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); } } @@ -186,16 +178,10 @@ public class TmfExperimentCheckpointIndexTest { assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size()); for (int i = 0; i < checkpoints.size(); i++) { ITmfCheckpoint checkpoint = checkpoints.get(i); - TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation(); - TmfLocationArray locations = expLocation.getLocationInfo(); - ITmfContext[] trcContexts = new ITmfContext[2]; - trcContexts[0] = new TmfContext(locations.getLocation(0), (i * pageSize) / 2); - trcContexts[1] = new TmfContext(locations.getLocation(1), (i * pageSize) / 2); - TmfExperimentContext expContext = new TmfExperimentContext(trcContexts); - expContext.getEvents()[0] = testTraces[0].getNext(testTraces[0].seekEvent((i * pageSize) / 2)); - expContext.getEvents()[1] = testTraces[1].getNext(testTraces[1].seekEvent((i * pageSize) / 2)); - ITmfEvent event = experiment.parseEvent(expContext); - assertTrue(expContext.getRank() == i * pageSize); + ITmfLocation location = checkpoint.getLocation(); + ITmfContext context = experiment.seekEvent(location); + ITmfEvent event = experiment.parseEvent(context); + assertTrue(context.getRank() == i * pageSize); assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue()); } 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 f2dbb426d0..8516300e12 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 @@ -10,6 +10,7 @@ * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Trace Model * Alexandre Montplaisir - Port to JUnit4 + * Patrick Tasse - Updated for rank in experiment location *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -261,23 +262,17 @@ public class TmfExperimentTest { // First event ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); double ratio = fExperiment.getLocationRatio(context.getLocation()); - context = fExperiment.seekEvent(ratio); - double ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2, DELTA); + assertEquals("getLocationRatio", 0.0, ratio, DELTA); // Middle event context = fExperiment.seekEvent(NB_EVENTS / 2); ratio = fExperiment.getLocationRatio(context.getLocation()); - context = fExperiment.seekEvent(ratio); - ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2, DELTA); + assertEquals("getLocationRatio", (double) (NB_EVENTS / 2) / NB_EVENTS, ratio, DELTA); // Last event context = fExperiment.seekEvent(NB_EVENTS - 1); ratio = fExperiment.getLocationRatio(context.getLocation()); - context = fExperiment.seekEvent(ratio); - ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2, DELTA); + assertEquals("getLocationRatio", (double) (NB_EVENTS - 1) / NB_EVENTS, ratio, DELTA); } // @SuppressWarnings("rawtypes") 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 5629baa0f1..6968ce8903 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 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 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.tests.stubs.trace; @@ -316,7 +317,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser { try { // parseNextEvent will update the context if (fTrace != null && getParser() != null && context != null) { - final ITmfEvent event = getParser().parseEvent(context.clone()); + final ITmfEvent event = getParser().parseEvent(context); return event; } } finally { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java index 9109fd35bd..862ea793c6 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,13 +9,13 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Put in shape for 1.0 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.core.trace; 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.TmfContext; /** @@ -25,9 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext; * 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: the legacy LTTng works - * like this...). + * read and that we at least know its timestamp. *

* The last trace refers to the trace from which the last event was "consumed" * at the experiment level. @@ -58,48 +56,16 @@ public class TmfExperimentContext extends TmfContext { /** * Standard constructor * - * @param contexts - * The matching context for each trace in the experiment + * @param nbTraces + * The number of traces in the experiment */ - public TmfExperimentContext(final ITmfContext[] contexts) { + public TmfExperimentContext(final int nbTraces) { super(); - fContexts = contexts; - fEvents = new ITmfEvent[fContexts.length]; - final ITmfLocation[] locations = new ITmfLocation[fContexts.length]; - - setLocation(new TmfExperimentLocation(new TmfLocationArray(locations.clone()))); - - final long[] ranks = new long[fContexts.length]; - long rank = 0; - 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))); - setRank(rank); + fContexts = new ITmfContext[nbTraces]; + fEvents = new ITmfEvent[nbTraces]; fLastTraceRead = NO_TRACE; } - /** - * Copy constructor - * - * @param other - * The experiment context to copy - */ - public TmfExperimentContext(final TmfExperimentContext other) { - this(other.cloneContexts()); - fEvents = other.fEvents; - if (other.getLocation() != null) { - setLocation(other.getLocation()); - } - setRank(other.getRank()); - setLastTrace(other.fLastTraceRead); - } - /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#dispose() */ @@ -111,35 +77,6 @@ public class TmfExperimentContext extends TmfContext { super.dispose(); } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone() - */ - @Override - public TmfExperimentContext clone() { - TmfExperimentContext clone = null; - clone = (TmfExperimentContext) super.clone(); - clone.fContexts = cloneContexts(); - clone.fEvents = cloneEvents(); - clone.fLastTraceRead = fLastTraceRead; - return clone; - } - - private ITmfContext[] cloneContexts() { - final ITmfContext[] contexts = new ITmfContext[fContexts.length]; - for (int i = 0; i < fContexts.length; i++) { - contexts[i] = (fContexts[i] != null) ? fContexts[i].clone() : null; - } - return contexts; - } - - private ITmfEvent[] cloneEvents() { - final ITmfEvent[] events = new ITmfEvent[fEvents.length]; - for (int i = 0; i < fEvents.length; i++) { - events[i] = fEvents[i]; - } - return events; - } - // ------------------------------------------------------------------------ // Accessors // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java index 68cbec14af..58b3518df9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for ranks in experiment location *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.core.trace; @@ -57,18 +58,6 @@ public final class TmfExperimentLocation implements ITmfLocation { this(location.getLocationInfo()); } - /** - * The "update" constructor. Copies the array of locations and updates - * a single entry. - * - * @param exp_location the experiment location - * @param index the entry to modify - * @param location the new entry - */ - public TmfExperimentLocation(TmfExperimentLocation exp_location, int index, ITmfLocation location) { - fLocation = new TmfLocationArray(exp_location.fLocation, index, location); - } - // ------------------------------------------------------------------------ // Object // ------------------------------------------------------------------------ @@ -79,13 +68,8 @@ public final class TmfExperimentLocation implements ITmfLocation { @Override @SuppressWarnings("nls") public String toString() { - StringBuilder result = new StringBuilder("[TmfExperimentLocation"); - int index = 0; - ITmfLocation location = getLocationInfo().getLocation(index); - while (location != null) { - result.append("[" + location + "]"); - location = getLocationInfo().getLocation(++index); - } + StringBuilder result = new StringBuilder("TmfExperimentLocation ["); + result.append(fLocation.toString()); result.append("]"); return result.toString(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java index 4d3c5fb616..371be097f8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Ericsson + * Copyright (c) 2011, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Patrick Tasse - Initial API and implementation * Francois Chouinard - Put in shape for 1.0 + * Patrick Tasse - Updated for ranks in experiment location *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.core.trace; @@ -20,7 +21,7 @@ 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. + * provide an immutable and Comparable implementation for TmfExperimentLocation. * * @version 1.0 * @author Patrick Tasse @@ -32,38 +33,70 @@ public final class TmfLocationArray implements Comparable { // ------------------------------------------------------------------------ private final ITmfLocation[] fLocations; + private final long [] fRanks; // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ /** - * The standard constructor + * The standard constructor. * * @param locations the locations + * @param ranks the ranks */ - public TmfLocationArray(ITmfLocation[] locations) { - fLocations = locations; + public TmfLocationArray(ITmfLocation[] locations, long[] ranks) { + fLocations = Arrays.copyOf(locations, locations.length); + fRanks = Arrays.copyOf(ranks, ranks.length); } /** - * The "update" constructor. Copies the array of locations and updates - * a single entry. + * The update constructor. Copies the arrays and updates a single entry. * - * @param locations the locations - * @param index the entry to modify - * @param location the new entry + * @param locationArray the location array + * @param index the updated index + * @param location the updated location + * @param rank the updated rank */ - public TmfLocationArray(TmfLocationArray locations, int index, ITmfLocation location) { - assert(locations != null && index >= 0 && index < locations.fLocations.length); - fLocations = Arrays.copyOf(locations.fLocations, locations.fLocations.length); + public TmfLocationArray(TmfLocationArray locationArray, int index, ITmfLocation location, long rank) { + fLocations = Arrays.copyOf(locationArray.fLocations, locationArray.fLocations.length); fLocations[index] = location; + fRanks = Arrays.copyOf(locationArray.fRanks, locationArray.fRanks.length); + fRanks[index] = rank; + } + + /** + * The empty constructor. + * + * @param size the number of elements in the array + */ + public TmfLocationArray(int size) { + fLocations = new ITmfLocation[size]; + fRanks = new long[size]; } // ------------------------------------------------------------------------ // Getters // ------------------------------------------------------------------------ + /** + * Returns the number of elements in this array. + * + * @return the number of elements in this array + */ + public int size() { + return fLocations.length; + } + + /** + * Get the locations inside this array. + * + * @return a copy of the locations array + */ + public ITmfLocation[] getLocations() { + return Arrays.copyOf(fLocations, fLocations.length); + } + /** * Get a specific location * @@ -72,23 +105,45 @@ public final class TmfLocationArray implements Comparable { * @return the specific location (possibly null) */ public ITmfLocation getLocation(int index) { - if (fLocations != null && index >= 0 && index < fLocations.length) { + if (index >= 0 && index < fLocations.length) { return fLocations[index]; } return null; } + /** + * Get the ranks inside this array. + * + * @return a copy of the ranks array + */ + public long[] getRanks() { + return Arrays.copyOf(fRanks, fRanks.length); + } + + /** + * Get a specific rank + * + * @param index the rank element + * + * @return the specific rank + */ + public long getRank(int index) { + if (index >= 0 && index < fRanks.length) { + return fRanks[index]; + } + return 0; + } + // ------------------------------------------------------------------------ // Comparable // ------------------------------------------------------------------------ @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) public int compareTo(TmfLocationArray o) { - for (int i = 0; i < fLocations.length; i++) { - Comparable l1 = fLocations[i].getLocationInfo(); - Comparable l2 = o.fLocations[i].getLocationInfo(); - int result = l1.compareTo(l2); + for (int i = 0; i < fRanks.length; i++) { + Long rank1 = fRanks[i]; + Long rank2 = o.fRanks[i]; + int result = rank1.compareTo(rank2); if (result != 0) { return result; } @@ -108,6 +163,7 @@ public final class TmfLocationArray implements Comparable { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(fLocations); + result = prime * result + Arrays.hashCode(fRanks); return result; } @@ -129,6 +185,9 @@ public final class TmfLocationArray implements Comparable { if (!Arrays.equals(fLocations, other.fLocations)) { return false; } + if (!Arrays.equals(fRanks, other.fRanks)) { + return false; + } return true; } @@ -138,7 +197,16 @@ public final class TmfLocationArray implements Comparable { @Override @SuppressWarnings("nls") public String toString() { - return "TmfLocationArray [locations=" + Arrays.toString(fLocations) + "]"; + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName() + " ["); + for (int i = 0; i < fLocations.length; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append("[location=" + fLocations[i] + ",rank=" + fRanks[i] + "]"); + } + sb.append("]"); + return sb.toString(); } } 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 13817cd8ca..cff663efa2 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 @@ -1,12 +1,14 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 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 + * Contributors: + * Matthew Khouzam - Initial API and implementation + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.ctfadaptor; @@ -311,9 +313,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { @Override public CtfTmfEvent parseEvent(ITmfContext context) { CtfTmfEvent event = null; - if( context instanceof CtfTmfContext ){ - CtfTmfContext itt = (CtfTmfContext) context.clone(); - event = itt.getCurrentEvent(); + if (context instanceof CtfTmfContext) { + final ITmfContext tmpContext = seekEvent(context.getLocation()); + event = getNext(tmpContext); } 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 eee80c1fb5..a510bec379 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 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 + * Patrick Tasse - Updated for location in checkpoint *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -31,17 +32,12 @@ public interface ITmfCheckpoint extends Comparable { // ------------------------------------------------------------------------ /** - * @return the timestamp of the event referred to by the context + * @return the timestamp of the event referred to by the checkpoint */ public ITmfTimestamp getTimestamp(); /** - * @return the location of the event referred to by the context - */ - public ITmfContext getContext(); - - /** - * @return the location of the event referred to by the context + * @return the location of the event referred to by the checkpoint */ public ITmfLocation getLocation(); 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 1c2cd13ba2..70dbe9bfa5 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -26,7 +27,7 @@ package org.eclipse.linuxtools.tmf.core.trace; * * @see ITmfLocation */ -public interface ITmfContext extends Cloneable { +public interface ITmfContext { // ------------------------------------------------------------------------ // Constants @@ -80,9 +81,4 @@ public interface ITmfContext extends Cloneable { */ public void dispose(); - /** - * @return a clone of the context - */ - public ITmfContext clone(); - } 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 0ff7084f7f..edc27cec86 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for location in checkpoint ******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -31,8 +32,8 @@ public class TmfCheckpoint implements ITmfCheckpoint { // Attributes // ------------------------------------------------------------------------ - // The checkpoint context - private final ITmfContext fContext; + // The checkpoint location + private final ITmfLocation fLocation; // The checkpoint timestamp private final ITmfTimestamp fTimestamp; @@ -45,11 +46,12 @@ public class TmfCheckpoint implements ITmfCheckpoint { * Full constructor * * @param timestamp the checkpoint timestamp - * @param context the corresponding trace location + * @param location the checkpoint location + * @since 2.0 */ - public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfContext context) { + public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) { fTimestamp = timestamp; - fContext = context; + fLocation = location; } /** @@ -62,7 +64,7 @@ public class TmfCheckpoint implements ITmfCheckpoint { throw new IllegalArgumentException(); } fTimestamp = other.fTimestamp; - fContext = other.fContext; + fLocation = other.fLocation; } // ------------------------------------------------------------------------ @@ -77,20 +79,12 @@ public class TmfCheckpoint implements ITmfCheckpoint { return fTimestamp; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation() - */ - @Override - public ITmfContext getContext() { - return fContext; - } - /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation() */ @Override public ITmfLocation getLocation() { - return fContext.getLocation(); + return fLocation; } // ------------------------------------------------------------------------ @@ -115,17 +109,17 @@ public class TmfCheckpoint implements ITmfCheckpoint { // compare locations if timestamps are the same } - if ((getContext() == null) && (other.getContext() == null)) { + if ((fLocation == null) && (other.getLocation() == null)) { return 0; } // treat location of other as null location which is before any location - if ((getContext() != null) && (other.getContext() == null)) { + if ((fLocation != null) && (other.getLocation() == null)) { return 1; } // treat this as null location which is before any other locations - if ((getContext() == null) && (other.getContext() != null)) { + if ((fLocation == null) && (other.getLocation() != null)) { return -1; } @@ -146,7 +140,7 @@ public class TmfCheckpoint implements ITmfCheckpoint { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((fContext == null) ? 0 : fContext.hashCode()); + result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode()); return result; } @@ -166,11 +160,11 @@ public class TmfCheckpoint implements ITmfCheckpoint { return false; } final TmfCheckpoint other = (TmfCheckpoint) obj; - if (fContext == null) { - if (other.fContext != null) { + if (fLocation == null) { + if (other.fLocation != null) { return false; } - } else if (!fContext.equals(other.fContext)) { + } else if (!fLocation.equals(other.fLocation)) { return false; } if (fTimestamp == null) { @@ -189,7 +183,7 @@ public class TmfCheckpoint implements ITmfCheckpoint { @Override @SuppressWarnings("nls") public String toString() { - return "TmfCheckpoint [fContext=" + fContext + ", fTimestamp=" + fTimestamp + "]"; + return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]"; } } 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 07acacf53c..3b0db1abdd 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 @@ -21,7 +21,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.linuxtools.internal.tmf.core.Messages; -import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; @@ -240,13 +239,12 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer { */ @Override public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) { - final long rank = context.getRank(); - if ((rank % fCheckpointInterval) == 0) { + if ((context.getRank() % fCheckpointInterval) == 0) { // Determine the table position - final long position = rank / fCheckpointInterval; + final long position = context.getRank() / fCheckpointInterval; // Add new entry at proper location (if empty) if (fTraceIndex.size() == position) { - fTraceIndex.add(new TmfCheckpoint(timestamp, saveContext(context))); + fTraceIndex.add(new TmfCheckpoint(timestamp, context.getLocation())); } } } @@ -316,7 +314,7 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer { if (index >= fTraceIndex.size()) { index = fTraceIndex.size() - 1; } - return restoreContext(fTraceIndex.get(index).getContext()); + location = fTraceIndex.get(index).getLocation(); } } final ITmfContext context = fTrace.seekEvent(location); @@ -335,65 +333,4 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer { return fTraceIndex; } - // ------------------------------------------------------------------------ - // Context conversion functions - // ------------------------------------------------------------------------ - - private static ITmfContext saveContext(ITmfContext context) { - if (context instanceof TmfExperimentContext) { - return saveExpContext(context); - } - TmfContext ctx = new TmfContext(context.getLocation(), context.getRank()); - return ctx; - } - - private static ITmfContext saveExpContext(ITmfContext context) { - TmfExperimentContext expContext = (TmfExperimentContext) context; - int size = expContext.getContexts().length; - ITmfContext[] trcCtxts = new TmfContext[size]; - for (int i = 0; i < size; i++) { - ITmfContext ctx = expContext.getContexts()[i]; - trcCtxts[i] = (ctx != null) ? new TmfContext(ctx.getLocation(), ctx.getRank()) : null; - } - TmfExperimentContext expCtx = new TmfExperimentContext(trcCtxts); - expCtx.setLocation(context.getLocation()); - expCtx.setRank(context.getRank()); - ITmfEvent[] trcEvts = expCtx.getEvents(); - for (int i = 0; i < size; i++) { - ITmfEvent event = expContext.getEvents()[i]; - trcEvts[i] = event; - } - return expCtx; - } - - private ITmfContext restoreContext(ITmfContext context) { - if (context instanceof TmfExperimentContext) { - return restoreExpContext(context); - } - ITmfContext ctx = fTrace.seekEvent(context.getLocation()); - ctx.setRank(context.getRank()); - return ctx; - } - - private ITmfContext restoreExpContext(ITmfContext context) { - TmfExperimentContext expContext = (TmfExperimentContext) context; - int size = expContext.getContexts().length; - ITmfContext[] trcCtxts = new ITmfContext[size]; - for (int i = 0; i < size; i++) { - ITmfTrace trace = ((TmfExperiment) fTrace).getTraces()[i]; - ITmfContext ctx = expContext.getContexts()[i]; - trcCtxts[i] = trace.seekEvent(ctx.getLocation()); - trcCtxts[i].setRank(ctx.getRank()); - } - TmfExperimentContext ctx = new TmfExperimentContext(trcCtxts); - ctx.setLocation(context.getLocation()); - ctx.setRank(context.getRank()); - ITmfEvent[] trcEvts = expContext.getEvents(); - for (int i = 0; i < size; i++) { - ITmfEvent event = trcEvts[i]; - ctx.getEvents()[i] = event; - } - return ctx; - } - } 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 2555e7a6d0..88f92358fc 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -80,25 +81,6 @@ public class TmfContext implements ITmfContext { fRank = context.fRank; } - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ - @Override - public TmfContext clone() { - TmfContext clone = null; - try { - clone = (TmfContext) super.clone(); - clone.fLocation = (fLocation != null) ? fLocation : null; - clone.fRank = fRank; - } catch (final CloneNotSupportedException e) { - } - 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 b6caaa80d1..674b3dc909 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,8 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for removal of context clone + * Patrick Tasse - Updated for ranks in experiment location *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -244,32 +246,33 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser { return null; } + // Initialize the location array if necessary + TmfLocationArray locationArray = ((location == null) ? + new TmfLocationArray(fTraces.length) : + ((TmfExperimentLocation) location).getLocationInfo()); + + ITmfLocation[] locations = locationArray.getLocations(); + long[] ranks = locationArray.getRanks(); + // Create and populate the context's traces contexts - final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]); - ITmfLocation[] expLocations = new ITmfLocation[fTraces.length]; - if (location != null) { - TmfExperimentLocation locations = (TmfExperimentLocation) location; - int index = 0; - ITmfLocation l = locations.getLocationInfo().getLocation(index); - while (index < expLocations.length && l != null) { - expLocations[index] = l; - l = locations.getLocationInfo().getLocation(++index); - } - } + final TmfExperimentContext context = new TmfExperimentContext(fTraces.length); // Position the traces + long rank = 0; for (int i = 0; i < fTraces.length; i++) { // Get the relevant trace attributes - final ITmfLocation trcLocation = expLocations[i]; - context.getContexts()[i] = fTraces[i].seekEvent(trcLocation); - expLocations[i] = context.getContexts()[i].getLocation(); - context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]); + final ITmfContext traceContext = fTraces[i].seekEvent(locations[i]); + context.getContexts()[i] = traceContext; + traceContext.setRank(ranks[i]); + locations[i] = traceContext.getLocation(); // update location after seek + context.getEvents()[i] = fTraces[i].getNext(traceContext); + rank += ranks[i]; } // Finalize context - context.setLocation(new TmfExperimentLocation(new TmfLocationArray(expLocations))); + context.setLocation(new TmfExperimentLocation(new TmfLocationArray(locations, ranks))); context.setLastTrace(TmfExperimentContext.NO_TRACE); - context.setRank((location == null) ? 0 : ITmfContext.UNKNOWN_RANK); + context.setRank(rank); return context; } @@ -293,7 +296,12 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser { @Override public double getLocationRatio(final ITmfLocation location) { if (location instanceof TmfExperimentLocation) { - return (double) seekEvent(location).getRank() / getNbEvents(); + long rank = 0; + TmfLocationArray locationArray = ((TmfExperimentLocation) location).getLocationInfo(); + for (int i = 0; i < locationArray.size(); i++) { + rank += locationArray.getRank(i); + } + return (double) rank / getNbEvents(); } return 0.0; } @@ -303,11 +311,8 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser { */ @Override public ITmfLocation getCurrentLocation() { - ITmfLocation[] locations = new ITmfLocation[fTraces.length]; - for (int i = 0; i < fTraces.length; i++) { - locations[i] = fTraces[i].getCurrentLocation(); - } - return new TmfExperimentLocation(new TmfLocationArray(locations)); + // never used + return null; } // ------------------------------------------------------------------------ @@ -319,8 +324,8 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser { */ @Override public synchronized ITmfEvent parseEvent(final ITmfContext context) { - final ITmfContext savedContext = context.clone(); - final ITmfEvent event = getNext(savedContext); + final ITmfContext tmpContext = seekEvent(context.getLocation()); + final ITmfEvent event = getNext(tmpContext); return event; } @@ -373,9 +378,11 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser { expContext.setLastTrace(trace); final ITmfContext traceContext = expContext.getContexts()[trace]; - expContext.setLocation(new TmfExperimentLocation( - (TmfExperimentLocation) expContext.getLocation(), - trace, traceContext.getLocation())); + // Update the experiment location + TmfLocationArray locationArray = new TmfLocationArray( + ((TmfExperimentLocation) expContext.getLocation()).getLocationInfo(), + trace, traceContext.getLocation(), traceContext.getRank()); + expContext.setLocation(new TmfExperimentLocation(locationArray)); processEvent(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 ecee99cd7c..4dd8ff33d6 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Patrick Tasse - Updated for removal of context clone *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -613,17 +614,21 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { 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); + ITmfLocation previousLocation = context.getLocation(); + long previousRank = context.getRank(); + ITmfEvent event = getNext(context); while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { - context.dispose(); - context = nextEventContext.clone(); - event = getNext(nextEventContext); + previousLocation = context.getLocation(); + previousRank = context.getRank(); + event = getNext(context); } - nextEventContext.dispose(); if (event == null) { context.setLocation(null); context.setRank(ITmfContext.UNKNOWN_RANK); + } else { + context.dispose(); + context = seekEvent(previousLocation); + context.setRank(previousRank); } return context; } -- 2.34.1