tmf: Move TmfExperiment to its own package
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 28 Oct 2014 23:16:47 +0000 (19:16 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 11 Nov 2014 21:58:38 +0000 (16:58 -0500)
With many experiment-specific concepts, and more on the way, it's
making more sense to put TmfExperiment in its own package.

Change-Id: I1ae03f693b075dd6e521fc20fb22d70b0c619551
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/36208
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
35 files changed:
org.eclipse.tracecompass.gdbtrace.core/src/org/eclipse/tracecompass/internal/gdbtrace/core/trace/DsfGdbAdaptor.java
org.eclipse.tracecompass.gdbtrace.ui/src/org/eclipse/tracecompass/internal/gdbtrace/ui/views/events/GdbEventsTable.java
org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/event/matchandsync/ExperimentSyncTest.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/trace/location/TmfLocationTest.java
org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/TmfExperimentStub.java
org.eclipse.tracecompass.tmf.core/META-INF/MANIFEST.MF
org.eclipse.tracecompass.tmf.core/plugin.xml
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentCheckpoint.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentContext.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentLocation.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfLocationArray.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentCheckpoint.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentContext.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentLocation.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfLocationArray.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfExperiment.java [deleted file]
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceManager.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/experiment/TmfExperiment.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/temp/headless/RequestBenchmark.java
org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/temp/tracemanager/TmfTraceManagerTest.java
org.eclipse.tracecompass.tmf.pcap.core/src/org/eclipse/tracecompass/internal/tmf/pcap/core/analysis/StreamListAnalysis.java
org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/project/model/TraceAndExperimentTypeTest.java
org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/views/uml2sd/loader/Uml2SDTestFacility.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/model/TmfEditorLinkHelper.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/editors/TmfEventsEditor.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfCommonProjectElement.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentElement.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfOpenTraceHelper.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/synchronization/TmfSynchronizationView.java

index 54e334e6925e2871938b673af5addfd5aa8928d0..f13192abf599def62f2cb915e3ff16eab1d71542 100644 (file)
@@ -88,7 +88,7 @@ import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.editors.ITmfTraceEditor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
index a73bbb6817657601a6d78b7ba9c9bd10cc57930a..5c3e5d0eaf6810e2215ef5dde6219e1b2e87009d 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable;
 
 /**
index aeaa6f4460ba8ba093a92000a3a90f079e29d6f2..d397e54fc70196eb6ef94cca2a465f27ae3ac429 100644 (file)
@@ -22,7 +22,7 @@ import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
 import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 import org.junit.BeforeClass;
index 82c772c88b042cbb5ab78cfbb6daf6cd8a5d684a..ff2540c0c212b1ab38d53b3aef96c578f4da7e22 100644 (file)
@@ -26,7 +26,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestExperimentAnalysis;
 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub;
 import org.junit.After;
index 633c8d9ac6e2e1023a780f98feb5359a8c0c4c2a..4b05e658d4662b0579d5340ced885bb346fae113 100644 (file)
@@ -29,14 +29,14 @@ import java.util.Vector;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentContext;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentLocation;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentContext;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
@@ -44,7 +44,7 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation;
 import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestExperimentAnalysis;
index 3476a3f7aae88d7ab15df7a26e8c072ad7930112..a2a5c224021377c72f766e4384e629726c71832c 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Vector;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentContext;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentContext;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
index 28ba7ea900517058cba729d3401bdc3e8f1c8829..79a5d4d93ee6078b88d1b0cdbf03dccb8c5dd584 100644 (file)
@@ -21,8 +21,8 @@ import static org.junit.Assert.assertTrue;
 
 import java.nio.ByteBuffer;
 
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentLocation;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfLocationArray;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfLocationArray;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.tracecompass.tmf.core.trace.location.TmfLocation;
index 5c645a5e5beb34ddaa4d13c937eb3ad19ef23ba3..3c3861933606d5cd46ffea17865d91570c2de8fb 100644 (file)
@@ -15,7 +15,7 @@ package org.eclipse.tracecompass.tmf.tests.stubs.trace;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
 
 /**
index eb450f58022d92f3b6bbac9ba79e149d80e7bb51..b9f2b17c45231b0fdeb1e44a6dab68f0f87fd8cf 100644 (file)
@@ -20,7 +20,7 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.core;x-friends:="org.eclip
  org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
  org.eclipse.tracecompass.internal.tmf.core.synchronization;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
  org.eclipse.tracecompass.internal.tmf.core.synchronization.graph;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
- org.eclipse.tracecompass.internal.tmf.core.trace;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
+ org.eclipse.tracecompass.internal.tmf.core.trace.experiment;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
  org.eclipse.tracecompass.internal.tmf.core.trace.indexer;x-friends:="org.eclipse.tracecompass.tmf.core.tests",
  org.eclipse.tracecompass.tmf.core,
  org.eclipse.tracecompass.tmf.core.analysis,
@@ -44,6 +44,7 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.core;x-friends:="org.eclip
  org.eclipse.tracecompass.tmf.core.synchronization,
  org.eclipse.tracecompass.tmf.core.timestamp,
  org.eclipse.tracecompass.tmf.core.trace,
+ org.eclipse.tracecompass.tmf.core.trace.experiment,
  org.eclipse.tracecompass.tmf.core.trace.indexer,
  org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint,
  org.eclipse.tracecompass.tmf.core.trace.location,
index 309a16277355e438b8ae37e9d5030cd77c13c37a..c526d566a3135d26bc24d0c1d0fb3e55da03696e 100644 (file)
@@ -26,7 +26,7 @@
          </tracetype>
          <tracetype
                applies="false"
-               class="org.eclipse.tracecompass.tmf.core.trace.TmfExperiment">
+               class="org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment">
          </tracetype>
       </module>
    </extension>
@@ -35,7 +35,7 @@
       <experiment
             id="org.eclipse.linuxtools.tmf.core.experiment.generic"
             name="%experimenttype.type.generic"
-            experiment_type="org.eclipse.tracecompass.tmf.core.trace.TmfExperiment">
+            experiment_type="org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment">
       </experiment>
    </extension>
 </plugin>
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentCheckpoint.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentCheckpoint.java
deleted file mode 100644 (file)
index 49c4fb4..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 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:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.internal.tmf.core.trace;
-
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-
-/**
- * <b><u>TmfExperimentCheckpoint</u></b>
- * <p>
- * TODO: Implement me. Please.
- */
-public class TmfExperimentCheckpoint implements Comparable<TmfExperimentCheckpoint> {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private final TmfTimestamp fTimestamp;
-    private final long[] fRanks;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * @param ts the checkpoint timestamp
-     * @param contexts the corresponding set of trace contexts
-     */
-    public TmfExperimentCheckpoint(final TmfTimestamp ts, final TmfContext[] contexts) {
-        fTimestamp = ts;
-        fRanks = new long[contexts.length];
-        for (int i = 0; i < fRanks.length; i++) {
-            fRanks[i] = contexts[i].getRank();
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Accessors
-    // ------------------------------------------------------------------------
-
-    /**
-     * @return the checkpoint event timestamp
-     */
-    public TmfTimestamp getTimestamp() {
-        return fTimestamp;
-    }
-
-    /**
-     * @return the checkpoint event rank
-     */
-    public long[] getRanks() {
-        return fRanks;
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int hashCode() {
-        int result = 37;
-        result = 17 * result + fTimestamp.hashCode();
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object other) {
-        if (!(other instanceof TmfExperimentCheckpoint)) {
-            return false;
-        }
-        final TmfExperimentCheckpoint o = (TmfExperimentCheckpoint) other;
-        return fTimestamp.equals(o.fTimestamp);
-    }
-
-    // ------------------------------------------------------------------------
-    // Comparable
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int compareTo(final TmfExperimentCheckpoint other) {
-        return fTimestamp.compareTo(other.fTimestamp);
-    }
-
-}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentContext.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentContext.java
deleted file mode 100644 (file)
index f86e75f..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 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:
- *   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.tracecompass.internal.tmf.core.trace;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-
-/**
- * The experiment context in TMF.
- * <p>
- * The experiment keeps track of the next event from each of its traces so it
- * can pick the next one in chronological order.
- * <p>
- * This implies that the "next" event from each trace has already been
- * read and that we at least know its timestamp.
- * <p>
- * The last trace refers to the trace from which the last event was "consumed"
- * at the experiment level.
- */
-public final class TmfExperimentContext extends TmfContext {
-
-    // ------------------------------------------------------------------------
-    // Constants
-    // ------------------------------------------------------------------------
-
-    /**
-     * No last trace read indicator
-     */
-    public static final int NO_TRACE = -1;
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private final List<ITmfContext> fContexts;
-    private final List<ITmfEvent> fEvents;
-    private int fLastTraceRead;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Standard constructor
-     *
-     * @param nbTraces
-     *            The number of traces in the experiment
-     */
-    public TmfExperimentContext(final int nbTraces) {
-        super();
-        fLastTraceRead = NO_TRACE;
-        fContexts = new ArrayList<>(nbTraces);
-        fEvents = new ArrayList<>(nbTraces);
-
-
-        /* Initialize the arrays to the requested size */
-        for (int i = 0; i < nbTraces; i++) {
-            fContexts.add(null);
-            fEvents.add(null);
-        }
-    }
-
-    @Override
-    public void dispose() {
-        for (ITmfContext context : fContexts) {
-            context.dispose();
-        }
-        super.dispose();
-    }
-
-    // ------------------------------------------------------------------------
-    // Accessors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Return how many traces this experiment context tracks the contexts of
-     * (a.k.a., the number of traces in the experiment).
-     *
-     * @return The number of traces in the experiment
-     */
-    public int getNbTraces() {
-        return fContexts.size();
-    }
-
-    /**
-     * Get the current context of a specific trace
-     *
-     * @param traceIndex
-     *            The index of the trace in the experiment
-     * @return The matching context object for that trace
-     */
-    @Nullable
-    public ITmfContext getContext(int traceIndex) {
-        return fContexts.get(traceIndex);
-    }
-
-    /**
-     * Set the context of a trace
-     *
-     * @param traceIndex
-     *            The index of the trace in the experiment
-     * @param ctx
-     *            The new context object for that trace
-     */
-    public void setContext(int traceIndex, ITmfContext ctx) {
-        fContexts.set(traceIndex, ctx);
-    }
-
-    /**
-     * Get the current event for a specific trace in the experiment.
-     *
-     * @param traceIndex
-     *            The index of the trace in the experiment
-     * @return The event matching the trace/context
-     *
-     */
-    @Nullable
-    public ITmfEvent getEvent(int traceIndex) {
-        return fEvents.get(traceIndex);
-    }
-
-    /**
-     * Set the context's event for a specific trace
-     *
-     * @param traceIndex
-     *            The index of the trace in the experiment
-     * @param event
-     *            The event at the context in the trace
-     */
-    public void setEvent(int traceIndex, ITmfEvent event) {
-        fEvents.set(traceIndex, event);
-    }
-
-    /**
-     * Get the index of the trace that was last read (so the trace whose
-     * current context will match this experiment's).
-     *
-     * @return The index of the trace
-     */
-    public int getLastTrace() {
-        return fLastTraceRead;
-    }
-
-    /**
-     * Set the last trace read index
-     *
-     * @param newIndex
-     *            The new value to assign
-     */
-    public void setLastTrace(final int newIndex) {
-        fLastTraceRead = newIndex;
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int hashCode() {
-        int result = 17;
-        for (int i = 0; i < fContexts.size(); i++) {
-            result = 37 * result + fContexts.get(i).hashCode();
-        }
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object other) {
-        if (this == other) {
-            return true;
-        }
-        if (!super.equals(other)) {
-            return false;
-        }
-        if (!(other instanceof TmfExperimentContext)) {
-            return false;
-        }
-        final TmfExperimentContext o = (TmfExperimentContext) other;
-        boolean isEqual = true;
-        int i = 0;
-        while (isEqual && (i < fContexts.size())) {
-            isEqual &= fContexts.get(i).equals(o.fContexts.get(i));
-            i++;
-        }
-        return isEqual;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-        StringBuilder sb = new StringBuilder("TmfExperimentContext [\n");
-        sb.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n");
-        sb.append("\tfContexts=[");
-        for (int i = 0; i < fContexts.size(); i++) {
-            sb.append("(" + fContexts.get(i).getLocation() + "," + fContexts.get(i).getRank() + ((i < fContexts.size() - 1) ? ")," : ")]\n"));
-        }
-        sb.append("\tfEvents=[");
-        for (int i = 0; i < fEvents.size(); i++) {
-            ITmfEvent event = fEvents.get(i);
-            sb.append(((event != null) ? fEvents.get(i).getTimestamp() : "(null)")  + ((i < fEvents.size() - 1) ? "," : "]\n"));
-        }
-        sb.append("\tfLastTraceRead=" + fLastTraceRead + "\n");
-        sb.append("]");
-        return sb.toString();
-    }
-
-}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentLocation.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfExperimentLocation.java
deleted file mode 100644 (file)
index 1eb150b..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 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:
- * 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.tracecompass.internal.tmf.core.trace;
-
-import java.nio.ByteBuffer;
-
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-
-/**
- * The experiment location in TMF.
- * <p>
- * An experiment location is actually the set of locations of the traces it
- * contains. By setting the individual traces to their corresponding locations,
- * the experiment can be positioned to read the next chronological event.
- * <p>
- * It is the responsibility of the user the individual trace locations are valid
- * and that they are matched to the correct trace.
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see TmfLocationArray
- */
-public final class TmfExperimentLocation implements ITmfLocation {
-
-    private final TmfLocationArray fLocation;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * The standard constructor
-     *
-     * @param locations the set of trace locations
-     */
-    public TmfExperimentLocation(TmfLocationArray locations) {
-        fLocation = locations;
-    }
-
-    /**
-     * The copy constructor
-     *
-     * @param location the other experiment location
-     */
-    public TmfExperimentLocation(TmfExperimentLocation location) {
-        this(location.getLocationInfo());
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-        StringBuilder result = new StringBuilder("TmfExperimentLocation [");
-        result.append(fLocation.toString());
-        result.append("]");
-        return result.toString();
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0);
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final TmfExperimentLocation other = (TmfExperimentLocation) obj;
-        if (fLocation == null) {
-            if (other.fLocation != null) {
-                return false;
-            }
-        } else if (!fLocation.equals(other.fLocation)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public TmfLocationArray getLocationInfo() {
-        return fLocation;
-    }
-
-    @Override
-    public void serialize(ByteBuffer bufferOut) {
-        ITmfLocation[] locations = fLocation.getLocations();
-        long[] ranks = fLocation.getRanks();
-        for (int i = 0; i < locations.length; ++i) {
-            locations[i].serialize(bufferOut);
-            bufferOut.putLong(ranks[i]);
-        }
-    }
-}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfLocationArray.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/TmfLocationArray.java
deleted file mode 100644 (file)
index f67ea9e..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 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:
- * 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.tracecompass.internal.tmf.core.trace;
-
-import java.util.Arrays;
-
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-
-/**
- * A convenience class to store trace location arrays. The main purpose is to
- * provide an immutable and Comparable implementation for TmfExperimentLocation.
- *
- * @version 1.0
- * @author Patrick Tasse
- */
-public final class TmfLocationArray implements Comparable<TmfLocationArray> {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private final ITmfLocation[] fLocations;
-    private final long [] fRanks;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * The standard constructor.
-     *
-     * @param locations the locations
-     * @param ranks the ranks
-     */
-    public TmfLocationArray(ITmfLocation[] locations, long[] ranks) {
-        fLocations = Arrays.copyOf(locations, locations.length);
-        fRanks = Arrays.copyOf(ranks, ranks.length);
-    }
-
-    /**
-     * The update constructor. Copies the arrays and updates a single entry.
-     *
-     * @param locationArray the location array
-     * @param index the updated index
-     * @param location the updated location
-     * @param rank the updated rank
-     */
-    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
-     *
-     * @param index the location element
-     *
-     * @return the specific location (possibly null)
-     */
-    public ITmfLocation getLocation(int index) {
-        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
-    public int compareTo(TmfLocationArray o) {
-        for (int i = 0; i < fRanks.length; i++) {
-            long rank1 = fRanks[i];
-            long rank2 = o.fRanks[i];
-            if (rank1 < rank2) {
-                return -1;
-            } else if (rank1 > rank2) {
-                return 1;
-            }
-        }
-        return 0;
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + Arrays.hashCode(fLocations);
-        result = prime * result + Arrays.hashCode(fRanks);
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        TmfLocationArray other = (TmfLocationArray) obj;
-        if (!Arrays.equals(fLocations, other.fLocations)) {
-            return false;
-        }
-        if (!Arrays.equals(fRanks, other.fRanks)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-        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.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentCheckpoint.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentCheckpoint.java
new file mode 100644 (file)
index 0000000..568cbb2
--- /dev/null
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.core.trace.experiment;
+
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
+
+/**
+ * <b><u>TmfExperimentCheckpoint</u></b>
+ * <p>
+ * TODO: Implement me. Please.
+ */
+public class TmfExperimentCheckpoint implements Comparable<TmfExperimentCheckpoint> {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final TmfTimestamp fTimestamp;
+    private final long[] fRanks;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @param ts the checkpoint timestamp
+     * @param contexts the corresponding set of trace contexts
+     */
+    public TmfExperimentCheckpoint(final TmfTimestamp ts, final TmfContext[] contexts) {
+        fTimestamp = ts;
+        fRanks = new long[contexts.length];
+        for (int i = 0; i < fRanks.length; i++) {
+            fRanks[i] = contexts[i].getRank();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the checkpoint event timestamp
+     */
+    public TmfTimestamp getTimestamp() {
+        return fTimestamp;
+    }
+
+    /**
+     * @return the checkpoint event rank
+     */
+    public long[] getRanks() {
+        return fRanks;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        int result = 37;
+        result = 17 * result + fTimestamp.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object other) {
+        if (!(other instanceof TmfExperimentCheckpoint)) {
+            return false;
+        }
+        final TmfExperimentCheckpoint o = (TmfExperimentCheckpoint) other;
+        return fTimestamp.equals(o.fTimestamp);
+    }
+
+    // ------------------------------------------------------------------------
+    // Comparable
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int compareTo(final TmfExperimentCheckpoint other) {
+        return fTimestamp.compareTo(other.fTimestamp);
+    }
+
+}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentContext.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentContext.java
new file mode 100644 (file)
index 0000000..ed941a3
--- /dev/null
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ *   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.tracecompass.internal.tmf.core.trace.experiment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
+
+/**
+ * The experiment context in TMF.
+ * <p>
+ * The experiment keeps track of the next event from each of its traces so it
+ * can pick the next one in chronological order.
+ * <p>
+ * This implies that the "next" event from each trace has already been
+ * read and that we at least know its timestamp.
+ * <p>
+ * The last trace refers to the trace from which the last event was "consumed"
+ * at the experiment level.
+ */
+public final class TmfExperimentContext extends TmfContext {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * No last trace read indicator
+     */
+    public static final int NO_TRACE = -1;
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final List<ITmfContext> fContexts;
+    private final List<ITmfEvent> fEvents;
+    private int fLastTraceRead;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Standard constructor
+     *
+     * @param nbTraces
+     *            The number of traces in the experiment
+     */
+    public TmfExperimentContext(final int nbTraces) {
+        super();
+        fLastTraceRead = NO_TRACE;
+        fContexts = new ArrayList<>(nbTraces);
+        fEvents = new ArrayList<>(nbTraces);
+
+
+        /* Initialize the arrays to the requested size */
+        for (int i = 0; i < nbTraces; i++) {
+            fContexts.add(null);
+            fEvents.add(null);
+        }
+    }
+
+    @Override
+    public void dispose() {
+        for (ITmfContext context : fContexts) {
+            context.dispose();
+        }
+        super.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Return how many traces this experiment context tracks the contexts of
+     * (a.k.a., the number of traces in the experiment).
+     *
+     * @return The number of traces in the experiment
+     */
+    public int getNbTraces() {
+        return fContexts.size();
+    }
+
+    /**
+     * Get the current context of a specific trace
+     *
+     * @param traceIndex
+     *            The index of the trace in the experiment
+     * @return The matching context object for that trace
+     */
+    @Nullable
+    public ITmfContext getContext(int traceIndex) {
+        return fContexts.get(traceIndex);
+    }
+
+    /**
+     * Set the context of a trace
+     *
+     * @param traceIndex
+     *            The index of the trace in the experiment
+     * @param ctx
+     *            The new context object for that trace
+     */
+    public void setContext(int traceIndex, ITmfContext ctx) {
+        fContexts.set(traceIndex, ctx);
+    }
+
+    /**
+     * Get the current event for a specific trace in the experiment.
+     *
+     * @param traceIndex
+     *            The index of the trace in the experiment
+     * @return The event matching the trace/context
+     *
+     */
+    @Nullable
+    public ITmfEvent getEvent(int traceIndex) {
+        return fEvents.get(traceIndex);
+    }
+
+    /**
+     * Set the context's event for a specific trace
+     *
+     * @param traceIndex
+     *            The index of the trace in the experiment
+     * @param event
+     *            The event at the context in the trace
+     */
+    public void setEvent(int traceIndex, ITmfEvent event) {
+        fEvents.set(traceIndex, event);
+    }
+
+    /**
+     * Get the index of the trace that was last read (so the trace whose
+     * current context will match this experiment's).
+     *
+     * @return The index of the trace
+     */
+    public int getLastTrace() {
+        return fLastTraceRead;
+    }
+
+    /**
+     * Set the last trace read index
+     *
+     * @param newIndex
+     *            The new value to assign
+     */
+    public void setLastTrace(final int newIndex) {
+        fLastTraceRead = newIndex;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        int result = 17;
+        for (int i = 0; i < fContexts.size(); i++) {
+            result = 37 * result + fContexts.get(i).hashCode();
+        }
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object other) {
+        if (this == other) {
+            return true;
+        }
+        if (!super.equals(other)) {
+            return false;
+        }
+        if (!(other instanceof TmfExperimentContext)) {
+            return false;
+        }
+        final TmfExperimentContext o = (TmfExperimentContext) other;
+        boolean isEqual = true;
+        int i = 0;
+        while (isEqual && (i < fContexts.size())) {
+            isEqual &= fContexts.get(i).equals(o.fContexts.get(i));
+            i++;
+        }
+        return isEqual;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        StringBuilder sb = new StringBuilder("TmfExperimentContext [\n");
+        sb.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n");
+        sb.append("\tfContexts=[");
+        for (int i = 0; i < fContexts.size(); i++) {
+            sb.append("(" + fContexts.get(i).getLocation() + "," + fContexts.get(i).getRank() + ((i < fContexts.size() - 1) ? ")," : ")]\n"));
+        }
+        sb.append("\tfEvents=[");
+        for (int i = 0; i < fEvents.size(); i++) {
+            ITmfEvent event = fEvents.get(i);
+            sb.append(((event != null) ? fEvents.get(i).getTimestamp() : "(null)")  + ((i < fEvents.size() - 1) ? "," : "]\n"));
+        }
+        sb.append("\tfLastTraceRead=" + fLastTraceRead + "\n");
+        sb.append("]");
+        return sb.toString();
+    }
+
+}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentLocation.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfExperimentLocation.java
new file mode 100644 (file)
index 0000000..fdaf8cf
--- /dev/null
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 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:
+ * 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.tracecompass.internal.tmf.core.trace.experiment;
+
+import java.nio.ByteBuffer;
+
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+
+
+/**
+ * The experiment location in TMF.
+ * <p>
+ * An experiment location is actually the set of locations of the traces it
+ * contains. By setting the individual traces to their corresponding locations,
+ * the experiment can be positioned to read the next chronological event.
+ * <p>
+ * It is the responsibility of the user the individual trace locations are valid
+ * and that they are matched to the correct trace.
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ *
+ * @see TmfLocationArray
+ */
+public final class TmfExperimentLocation implements ITmfLocation {
+
+    private final TmfLocationArray fLocation;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * The standard constructor
+     *
+     * @param locations the set of trace locations
+     */
+    public TmfExperimentLocation(TmfLocationArray locations) {
+        fLocation = locations;
+    }
+
+    /**
+     * The copy constructor
+     *
+     * @param location the other experiment location
+     */
+    public TmfExperimentLocation(TmfExperimentLocation location) {
+        this(location.getLocationInfo());
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        StringBuilder result = new StringBuilder("TmfExperimentLocation [");
+        result.append(fLocation.toString());
+        result.append("]");
+        return result.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final TmfExperimentLocation other = (TmfExperimentLocation) obj;
+        if (fLocation == null) {
+            if (other.fLocation != null) {
+                return false;
+            }
+        } else if (!fLocation.equals(other.fLocation)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public TmfLocationArray getLocationInfo() {
+        return fLocation;
+    }
+
+    @Override
+    public void serialize(ByteBuffer bufferOut) {
+        ITmfLocation[] locations = fLocation.getLocations();
+        long[] ranks = fLocation.getRanks();
+        for (int i = 0; i < locations.length; ++i) {
+            locations[i].serialize(bufferOut);
+            bufferOut.putLong(ranks[i]);
+        }
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfLocationArray.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/experiment/TmfLocationArray.java
new file mode 100644 (file)
index 0000000..fa5428e
--- /dev/null
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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:
+ * 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.tracecompass.internal.tmf.core.trace.experiment;
+
+import java.util.Arrays;
+
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+
+
+/**
+ * A convenience class to store trace location arrays. The main purpose is to
+ * provide an immutable and Comparable implementation for TmfExperimentLocation.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public final class TmfLocationArray implements Comparable<TmfLocationArray> {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final ITmfLocation[] fLocations;
+    private final long [] fRanks;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * The standard constructor.
+     *
+     * @param locations the locations
+     * @param ranks the ranks
+     */
+    public TmfLocationArray(ITmfLocation[] locations, long[] ranks) {
+        fLocations = Arrays.copyOf(locations, locations.length);
+        fRanks = Arrays.copyOf(ranks, ranks.length);
+    }
+
+    /**
+     * The update constructor. Copies the arrays and updates a single entry.
+     *
+     * @param locationArray the location array
+     * @param index the updated index
+     * @param location the updated location
+     * @param rank the updated rank
+     */
+    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
+     *
+     * @param index the location element
+     *
+     * @return the specific location (possibly null)
+     */
+    public ITmfLocation getLocation(int index) {
+        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
+    public int compareTo(TmfLocationArray o) {
+        for (int i = 0; i < fRanks.length; i++) {
+            long rank1 = fRanks[i];
+            long rank2 = o.fRanks[i];
+            if (rank1 < rank2) {
+                return -1;
+            } else if (rank1 > rank2) {
+                return 1;
+            }
+        }
+        return 0;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Arrays.hashCode(fLocations);
+        result = prime * result + Arrays.hashCode(fRanks);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfLocationArray other = (TmfLocationArray) obj;
+        if (!Arrays.equals(fLocations, other.fLocations)) {
+            return false;
+        }
+        if (!Arrays.equals(fRanks, other.fRanks)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        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();
+    }
+
+}
index 8ce4dcc447324462b43c70a61a71f705c74e273e..28f04a13060ae2aa378fb1d054f33f1f3d3f623d 100644 (file)
@@ -44,8 +44,8 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceCompleteness;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 
 /**
  * Abstract analysis module to generate a state system. It is a base class that
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfExperiment.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfExperiment.java
deleted file mode 100644 (file)
index 3b4423c..0000000
+++ /dev/null
@@ -1,709 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 Ericsson, Ã‰cole Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Updated as per TMF Trace Model 1.0
- *   Patrick Tasse - Updated for removal of context clone
- *   Patrick Tasse - Updated for ranks in experiment location
- *   Geneviève Bastien - Added support of experiment synchronization
- *                       Added the initExperiment method and default constructor
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.trace;
-
-import java.io.File;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.internal.tmf.core.Activator;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentContext;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfExperimentLocation;
-import org.eclipse.tracecompass.internal.tmf.core.trace.TmfLocationArray;
-import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSynchronizedSignal;
-import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
-import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
-import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
-import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
-
-/**
- * TmfExperiment presents a time-ordered, unified view of a set of ITmfTrace:s
- * that are part of a tracing experiment.
- *
- * @version 1.0
- * @author Francois Chouinard
- */
-public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPersistentlyIndexable {
-
-    // ------------------------------------------------------------------------
-    // Constants
-    // ------------------------------------------------------------------------
-
-    /**
-     * The file name of the Synchronization
-     *
-     * @since 3.0
-     * @deprecated This file name shouldn't be used directly anymore. All
-     *             synchronization files have been moved to a folder and you
-     *             should use the {@link #getSynchronizationFolder(boolean)}
-     *             method to return the path to this folder.
-     */
-    @Deprecated
-    public static final String SYNCHRONIZATION_FILE_NAME = "synchronization.bin"; //$NON-NLS-1$
-
-    /**
-     * The name of the directory containing trace synchronization data. This
-     * directory typically will be preserved when traces are synchronized.
-     * Analysis involved in synchronization can put their supplementary files in
-     * there so they are not deleted when synchronized traces are copied.
-     */
-    private static final String SYNCHRONIZATION_DIRECTORY = "sync_data"; //$NON-NLS-1$
-
-    /**
-     * The default index page size
-     */
-    public static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /**
-     * The set of traces that constitute the experiment
-     */
-    protected ITmfTrace[] fTraces;
-
-    /**
-     * The set of traces that constitute the experiment
-     */
-    private boolean fInitialized = false;
-
-
-    // ------------------------------------------------------------------------
-    // Construction
-    // ------------------------------------------------------------------------
-
-    /**
-     * Default constructor. Should not be used directly, but is needed for
-     * extension points.
-     *
-     * @deprecated Do not call this directly (but do not remove it either!)
-     */
-    @Deprecated
-    public TmfExperiment() {
-        super();
-    }
-
-    /**
-     * Constructor of an experiment, taking the type, path, traces,
-     * indexPageSize and resource
-     *
-     * @param type
-     *            The event type
-     * @param path
-     *            The experiment path
-     * @param traces
-     *            The experiment set of traces
-     * @param indexPageSize
-     *            The experiment index page size. You can use
-     *            {@link TmfExperiment#DEFAULT_INDEX_PAGE_SIZE} for a default
-     *            value.
-     * @param resource
-     *            The resource associated to the experiment. You can use 'null'
-     *            for no resources (tests, etc.)
-     */
-    public TmfExperiment(final Class<? extends ITmfEvent> type,
-            final String path,
-            final ITmfTrace[] traces,
-            final int indexPageSize,
-            final @Nullable IResource resource) {
-        initExperiment(type, path, traces, indexPageSize, resource);
-    }
-
-    @Override
-    protected ITmfTraceIndexer createIndexer(int interval) {
-        if (getCheckpointSize() > 0) {
-            return new TmfBTreeTraceIndexer(this, interval);
-        }
-        return super.createIndexer(interval);
-    }
-
-    /**
-     * Clears the experiment
-     */
-    @Override
-    public synchronized void dispose() {
-
-        // Clean up the index if applicable
-        if (getIndexer() != null) {
-            getIndexer().dispose();
-        }
-
-        if (fTraces != null) {
-            for (final ITmfTrace trace : fTraces) {
-                trace.dispose();
-            }
-            fTraces = null;
-        }
-        super.dispose();
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTrace - Initializers
-    // ------------------------------------------------------------------------
-
-    @Override
-    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) {
-        /* Do nothing for experiments */
-    }
-
-    /**
-     * Initialization of an experiment, taking the type, path, traces,
-     * indexPageSize and resource
-     *
-     * @param type
-     *            the event type
-     * @param path
-     *            the experiment path
-     * @param traces
-     *            the experiment set of traces
-     * @param indexPageSize
-     *            the experiment index page size
-     * @param resource
-     *            the resource associated to the experiment
-     * @since 3.0
-     */
-    public void initExperiment(final Class<? extends ITmfEvent> type,
-            final String path,
-            final ITmfTrace[] traces,
-            final int indexPageSize,
-            final @Nullable IResource resource) {
-
-        setCacheSize(indexPageSize);
-        setStreamingInterval(0);
-        setParser(this);
-        // traces have to be set before super.initialize()
-        fTraces = traces;
-        try {
-            super.initialize(resource, path, type);
-        } catch (TmfTraceException e) {
-            Activator.logError("Error initializing experiment", e); //$NON-NLS-1$
-        }
-
-        if (resource != null) {
-            this.synchronizeTraces();
-        }
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public IStatus validate(final IProject project, final String path) {
-        return Status.OK_STATUS;
-    }
-
-    // ------------------------------------------------------------------------
-    // Accessors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Get the traces contained in this experiment.
-     *
-     * @return The array of contained traces
-     */
-    public ITmfTrace[] getTraces() {
-        return fTraces;
-    }
-
-    /**
-     * Returns the timestamp of the event at the requested index. If none,
-     * returns null.
-     *
-     * @param index
-     *            the event index (rank)
-     * @return the corresponding event timestamp
-     * @since 2.0
-     */
-    public ITmfTimestamp getTimestamp(final int index) {
-        final ITmfContext context = seekEvent(index);
-        final ITmfEvent event = getNext(context);
-        context.dispose();
-        return (event != null) ? event.getTimestamp() : null;
-    }
-
-    // ------------------------------------------------------------------------
-    // Request management
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public synchronized ITmfContext armRequest(final ITmfEventRequest request) {
-
-        // Make sure we have something to read from
-        if (fTraces == null) {
-            return null;
-        }
-
-        if (!TmfTimestamp.BIG_BANG.equals(request.getRange().getStartTime())
-                && request.getIndex() == 0) {
-            final ITmfContext context = seekEvent(request.getRange().getStartTime());
-            request.setStartIndex((int) context.getRank());
-            return context;
-
-        }
-
-        return seekEvent(request.getIndex());
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTrace trace positioning
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public synchronized ITmfContext seekEvent(final ITmfLocation location) {
-        // Validate the location
-        if (location != null && !(location instanceof TmfExperimentLocation)) {
-            return null; // Throw an exception?
-        }
-        // Make sure we have something to read from
-        if (fTraces == null) {
-            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(fTraces.length);
-
-        // Position the traces
-        long rank = 0;
-        for (int i = 0; i < fTraces.length; i++) {
-            // Get the relevant trace attributes
-            final ITmfContext traceContext = fTraces[i].seekEvent(locations[i]);
-            context.setContext(i, traceContext);
-            traceContext.setRank(ranks[i]);
-            // update location after seek
-            locations[i] = traceContext.getLocation();
-            context.setEvent(i, fTraces[i].getNext(traceContext));
-            rank += ranks[i];
-        }
-
-        // Finalize context
-        context.setLocation(new TmfExperimentLocation(new TmfLocationArray(locations, ranks)));
-        context.setLastTrace(TmfExperimentContext.NO_TRACE);
-        context.setRank(rank);
-
-        return context;
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTrace - SeekEvent operations (returning a trace context)
-    // ------------------------------------------------------------------------
-
-    @Override
-    public ITmfContext seekEvent(final double ratio) {
-        final ITmfContext context = seekEvent(Math.round(ratio * getNbEvents()));
-        return context;
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public double getLocationRatio(final ITmfLocation location) {
-        if (location instanceof TmfExperimentLocation) {
-            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;
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public ITmfLocation getCurrentLocation() {
-        // never used
-        return null;
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTrace trace positioning
-    // ------------------------------------------------------------------------
-
-    @Override
-    public synchronized ITmfEvent parseEvent(final ITmfContext context) {
-        final ITmfContext tmpContext = seekEvent(context.getLocation());
-        final ITmfEvent event = getNext(tmpContext);
-        return event;
-    }
-
-    @Override
-    public synchronized ITmfEvent getNext(ITmfContext context) {
-
-        // Validate the context
-        if (!(context instanceof TmfExperimentContext)) {
-            return null; // Throw an exception?
-        }
-
-        // Make sure that we have something to read from
-        if (fTraces == null) {
-            return null;
-        }
-
-        TmfExperimentContext expContext = (TmfExperimentContext) context;
-
-        // If an event was consumed previously, first get the next one from that
-        // trace
-        final int lastTrace = expContext.getLastTrace();
-        if (lastTrace != TmfExperimentContext.NO_TRACE) {
-            final ITmfContext traceContext = expContext.getContext(lastTrace);
-            expContext.setEvent(lastTrace, fTraces[lastTrace].getNext(traceContext));
-            expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
-        }
-
-        // Scan the candidate events and identify the "next" trace to read from
-        int trace = TmfExperimentContext.NO_TRACE;
-        ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
-        for (int i = 0; i < fTraces.length; i++) {
-            final ITmfEvent event = expContext.getEvent(i);
-            if (event != null && event.getTimestamp() != null) {
-                final ITmfTimestamp otherTS = event.getTimestamp();
-                if (otherTS.compareTo(timestamp) < 0) {
-                    trace = i;
-                    timestamp = otherTS;
-                }
-            }
-        }
-
-        ITmfEvent event = null;
-        if (trace != TmfExperimentContext.NO_TRACE) {
-            event = expContext.getEvent(trace);
-            if (event != null) {
-                updateAttributes(expContext, event.getTimestamp());
-                expContext.increaseRank();
-                expContext.setLastTrace(trace);
-                final ITmfContext traceContext = expContext.getContext(trace);
-                if (traceContext == null) {
-                    throw new IllegalStateException();
-                }
-
-                // Update the experiment location
-                TmfLocationArray locationArray = new TmfLocationArray(
-                        ((TmfExperimentLocation) expContext.getLocation()).getLocationInfo(),
-                        trace, traceContext.getLocation(), traceContext.getRank());
-                expContext.setLocation(new TmfExperimentLocation(locationArray));
-
-                processEvent(event);
-            }
-        }
-
-        return event;
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public ITmfTimestamp getInitialRangeOffset() {
-        if ((fTraces == null) || (fTraces.length == 0)) {
-            return super.getInitialRangeOffset();
-        }
-
-        ITmfTimestamp initTs = TmfTimestamp.BIG_CRUNCH;
-        for (int i = 0; i < fTraces.length; i++) {
-            ITmfTimestamp ts = fTraces[i].getInitialRangeOffset();
-            if (ts.compareTo(initTs) < 0) {
-                initTs = ts;
-            }
-        }
-        return initTs;
-    }
-
-    /**
-     * Get the path to the folder in the supplementary file where
-     * synchronization-related data can be kept so they are not deleted when the
-     * experiment is synchronized. Analysis involved in synchronization can put
-     * their supplementary files in there so they are preserved after
-     * synchronization.
-     *
-     * If the directory does not exist, it will be created. A return value of
-     * <code>null</code> means either the trace resource does not exist or
-     * supplementary resources cannot be kept.
-     *
-     * @param absolute
-     *            If <code>true</code>, it returns the absolute path in the file
-     *            system, including the supplementary file path. Otherwise, it
-     *            returns only the directory name.
-     * @return The path to the folder where synchronization-related
-     *         supplementary files can be kept or <code>null</code> if not
-     *         available.
-     * @since 3.2
-     */
-    public String getSynchronizationFolder(boolean absolute) {
-        /* Set up the path to the synchronization file we'll use */
-        IResource resource = this.getResource();
-        String syncDirectory = null;
-
-        try {
-            /* get the directory where the file will be stored. */
-            if (resource != null) {
-                String fullDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
-                /* Create the synchronization data directory if not present */
-                if (fullDirectory != null) {
-                    fullDirectory = fullDirectory + File.separator + SYNCHRONIZATION_DIRECTORY;
-                    File syncDir = new File(fullDirectory);
-                    syncDir.mkdirs();
-                }
-                if (absolute) {
-                    syncDirectory = fullDirectory;
-                } else {
-                    syncDirectory = SYNCHRONIZATION_DIRECTORY;
-                }
-            }
-        } catch (CoreException e) {
-            return null;
-        }
-
-        return syncDirectory;
-    }
-
-    /**
-     * Synchronizes the traces of an experiment. By default it only tries to
-     * read a synchronization file if it exists
-     *
-     * @return The synchronization object
-     * @since 3.0
-     */
-    public synchronized SynchronizationAlgorithm synchronizeTraces() {
-        return synchronizeTraces(false);
-    }
-
-    /**
-     * Synchronizes the traces of an experiment.
-     *
-     * @param doSync
-     *            Whether to actually synchronize or just try opening a sync
-     *            file
-     * @return The synchronization object
-     * @since 3.0
-     */
-    public synchronized SynchronizationAlgorithm synchronizeTraces(boolean doSync) {
-
-        String syncDirectory = getSynchronizationFolder(true);
-
-        final File syncFile = (syncDirectory != null) ? new File(syncDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
-
-        final SynchronizationAlgorithm syncAlgo = SynchronizationManager.synchronizeTraces(syncFile, Arrays.asList(fTraces), doSync);
-
-        final TmfTraceSynchronizedSignal signal = new TmfTraceSynchronizedSignal(this, syncAlgo);
-
-        /* Broadcast in separate thread to prevent deadlock */
-        new Thread() {
-            @Override
-            public void run() {
-                broadcast(signal);
-            }
-        }.start();
-
-        return syncAlgo;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public synchronized String toString() {
-        return "[TmfExperiment (" + getName() + ")]";
-    }
-
-    // ------------------------------------------------------------------------
-    // Streaming support
-    // ------------------------------------------------------------------------
-
-    private synchronized void initializeStreamingMonitor() {
-
-        if (fInitialized) {
-            return;
-        }
-        fInitialized = true;
-
-        if (getStreamingInterval() == 0) {
-            final ITmfContext context = seekEvent(0);
-            final ITmfEvent event = getNext(context);
-            context.dispose();
-            if (event == null) {
-                return;
-            }
-            final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp(), TmfTimestamp.BIG_CRUNCH);
-            final TmfTraceRangeUpdatedSignal signal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
-
-            // Broadcast in separate thread to prevent deadlock
-            new Thread() {
-                @Override
-                public void run() {
-                    broadcast(signal);
-                }
-            }.start();
-            return;
-        }
-
-        final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$
-            private ITmfTimestamp safeTimestamp = null;
-            private ITmfTimestamp lastSafeTimestamp = null;
-            private TmfTimeRange timeRange = null;
-
-            @Override
-            public void run() {
-                while (!executorIsShutdown()) {
-                    if (!getIndexer().isIndexing()) {
-                        ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
-                        ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
-                        for (final ITmfTrace trace : fTraces) {
-                            if (trace.getStartTime().compareTo(startTimestamp) < 0) {
-                                startTimestamp = trace.getStartTime();
-                            }
-                            if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) {
-                                endTimestamp = trace.getEndTime();
-                            }
-                        }
-                        if (safeTimestamp != null && (lastSafeTimestamp == null || safeTimestamp.compareTo(lastSafeTimestamp) > 0)) {
-                            timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
-                            lastSafeTimestamp = safeTimestamp;
-                        } else {
-                            timeRange = null;
-                        }
-                        safeTimestamp = endTimestamp;
-                        if (timeRange != null) {
-                            final TmfTraceRangeUpdatedSignal signal =
-                                    new TmfTraceRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange);
-                            broadcast(signal);
-                        }
-                    }
-                    try {
-                        Thread.sleep(getStreamingInterval());
-                    } catch (final InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                }
-            }
-        };
-        thread.start();
-    }
-
-    @Override
-    public long getStreamingInterval() {
-        long interval = 0;
-        for (final ITmfTrace trace : fTraces) {
-            interval = Math.max(interval, trace.getStreamingInterval());
-        }
-        return interval;
-    }
-
-    // ------------------------------------------------------------------------
-    // Signal handlers
-    // ------------------------------------------------------------------------
-
-    @Override
-    @TmfSignalHandler
-    public void traceOpened(TmfTraceOpenedSignal signal) {
-        if (signal.getTrace() == this) {
-            initializeStreamingMonitor();
-
-            /* Initialize the analysis */
-            MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
-            status.add(executeAnalysis());
-            if (!status.isOK()) {
-                Activator.log(status);
-            }
-            TmfTraceManager.refreshSupplementaryFiles(this);
-        }
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public synchronized int getCheckpointSize() {
-        int totalCheckpointSize = 0;
-        try {
-            if (fTraces != null) {
-                for (final ITmfTrace trace : fTraces) {
-                    if (!(trace instanceof ITmfPersistentlyIndexable)) {
-                        return 0;
-                    }
-
-                    ITmfPersistentlyIndexable persistableIndexTrace = (ITmfPersistentlyIndexable) trace;
-                    int currentTraceCheckpointSize = persistableIndexTrace.getCheckpointSize();
-                    if (currentTraceCheckpointSize <= 0) {
-                        return 0;
-                    }
-                    totalCheckpointSize += currentTraceCheckpointSize;
-                    // each entry in the TmfLocationArray has a rank in addition
-                    // of the location
-                    totalCheckpointSize += 8;
-                }
-            }
-        } catch (UnsupportedOperationException e) {
-            return 0;
-        }
-
-        return totalCheckpointSize;
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
-        ITmfLocation[] locations = new ITmfLocation[fTraces.length];
-        long[] ranks = new long[fTraces.length];
-        for (int i = 0; i < fTraces.length; ++i) {
-            final ITmfTrace trace = fTraces[i];
-            locations[i] = ((ITmfPersistentlyIndexable) trace).restoreLocation(bufferIn);
-            ranks[i] = bufferIn.getLong();
-        }
-        TmfLocationArray arr = new TmfLocationArray(locations, ranks);
-        TmfExperimentLocation l = new TmfExperimentLocation(arr);
-        return l;
-    }
-
-}
index da3d90589df88ba450fcdc5ad1f24fe03b86de7a..e342b80661f95ed6b7319e9865b37028167629d6 100644 (file)
@@ -44,6 +44,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 
 /**
  * Central trace manager for TMF. It tracks the currently opened traces and
diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/experiment/TmfExperiment.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/experiment/TmfExperiment.java
new file mode 100644 (file)
index 0000000..29bbe6d
--- /dev/null
@@ -0,0 +1,714 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2014 Ericsson, Ã‰cole Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
+ *   Patrick Tasse - Updated for removal of context clone
+ *   Patrick Tasse - Updated for ranks in experiment location
+ *   Geneviève Bastien - Added support of experiment synchronization
+ *                       Added the initExperiment method and default constructor
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.trace.experiment;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentContext;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation;
+import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfLocationArray;
+import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSynchronizedSignal;
+import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
+import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
+import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+
+/**
+ * TmfExperiment presents a time-ordered, unified view of a set of ITmfTrace:s
+ * that are part of a tracing experiment.
+ *
+ * @version 1.0
+ * @author Francois Chouinard
+ */
+public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPersistentlyIndexable {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * The file name of the Synchronization
+     *
+     * @since 3.0
+     * @deprecated This file name shouldn't be used directly anymore. All
+     *             synchronization files have been moved to a folder and you
+     *             should use the {@link #getSynchronizationFolder(boolean)}
+     *             method to return the path to this folder.
+     */
+    @Deprecated
+    public static final String SYNCHRONIZATION_FILE_NAME = "synchronization.bin"; //$NON-NLS-1$
+
+    /**
+     * The name of the directory containing trace synchronization data. This
+     * directory typically will be preserved when traces are synchronized.
+     * Analysis involved in synchronization can put their supplementary files in
+     * there so they are not deleted when synchronized traces are copied.
+     */
+    private static final String SYNCHRONIZATION_DIRECTORY = "sync_data"; //$NON-NLS-1$
+
+    /**
+     * The default index page size
+     */
+    public static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The set of traces that constitute the experiment
+     */
+    protected ITmfTrace[] fTraces;
+
+    /**
+     * The set of traces that constitute the experiment
+     */
+    private boolean fInitialized = false;
+
+
+    // ------------------------------------------------------------------------
+    // Construction
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor. Should not be used directly, but is needed for
+     * extension points.
+     *
+     * @deprecated Do not call this directly (but do not remove it either!)
+     */
+    @Deprecated
+    public TmfExperiment() {
+        super();
+    }
+
+    /**
+     * Constructor of an experiment, taking the type, path, traces,
+     * indexPageSize and resource
+     *
+     * @param type
+     *            The event type
+     * @param path
+     *            The experiment path
+     * @param traces
+     *            The experiment set of traces
+     * @param indexPageSize
+     *            The experiment index page size. You can use
+     *            {@link TmfExperiment#DEFAULT_INDEX_PAGE_SIZE} for a default
+     *            value.
+     * @param resource
+     *            The resource associated to the experiment. You can use 'null'
+     *            for no resources (tests, etc.)
+     */
+    public TmfExperiment(final Class<? extends ITmfEvent> type,
+            final String path,
+            final ITmfTrace[] traces,
+            final int indexPageSize,
+            final @Nullable IResource resource) {
+        initExperiment(type, path, traces, indexPageSize, resource);
+    }
+
+    @Override
+    protected ITmfTraceIndexer createIndexer(int interval) {
+        if (getCheckpointSize() > 0) {
+            return new TmfBTreeTraceIndexer(this, interval);
+        }
+        return super.createIndexer(interval);
+    }
+
+    /**
+     * Clears the experiment
+     */
+    @Override
+    public synchronized void dispose() {
+
+        // Clean up the index if applicable
+        if (getIndexer() != null) {
+            getIndexer().dispose();
+        }
+
+        if (fTraces != null) {
+            for (final ITmfTrace trace : fTraces) {
+                trace.dispose();
+            }
+            fTraces = null;
+        }
+        super.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTrace - Initializers
+    // ------------------------------------------------------------------------
+
+    @Override
+    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) {
+        /* Do nothing for experiments */
+    }
+
+    /**
+     * Initialization of an experiment, taking the type, path, traces,
+     * indexPageSize and resource
+     *
+     * @param type
+     *            the event type
+     * @param path
+     *            the experiment path
+     * @param traces
+     *            the experiment set of traces
+     * @param indexPageSize
+     *            the experiment index page size
+     * @param resource
+     *            the resource associated to the experiment
+     * @since 3.0
+     */
+    public void initExperiment(final Class<? extends ITmfEvent> type,
+            final String path,
+            final ITmfTrace[] traces,
+            final int indexPageSize,
+            final @Nullable IResource resource) {
+
+        setCacheSize(indexPageSize);
+        setStreamingInterval(0);
+        setParser(this);
+        // traces have to be set before super.initialize()
+        fTraces = traces;
+        try {
+            super.initialize(resource, path, type);
+        } catch (TmfTraceException e) {
+            Activator.logError("Error initializing experiment", e); //$NON-NLS-1$
+        }
+
+        if (resource != null) {
+            this.synchronizeTraces();
+        }
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public IStatus validate(final IProject project, final String path) {
+        return Status.OK_STATUS;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Get the traces contained in this experiment.
+     *
+     * @return The array of contained traces
+     */
+    public ITmfTrace[] getTraces() {
+        return fTraces;
+    }
+
+    /**
+     * Returns the timestamp of the event at the requested index. If none,
+     * returns null.
+     *
+     * @param index
+     *            the event index (rank)
+     * @return the corresponding event timestamp
+     * @since 2.0
+     */
+    public ITmfTimestamp getTimestamp(final int index) {
+        final ITmfContext context = seekEvent(index);
+        final ITmfEvent event = getNext(context);
+        context.dispose();
+        return (event != null) ? event.getTimestamp() : null;
+    }
+
+    // ------------------------------------------------------------------------
+    // Request management
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public synchronized ITmfContext armRequest(final ITmfEventRequest request) {
+
+        // Make sure we have something to read from
+        if (fTraces == null) {
+            return null;
+        }
+
+        if (!TmfTimestamp.BIG_BANG.equals(request.getRange().getStartTime())
+                && request.getIndex() == 0) {
+            final ITmfContext context = seekEvent(request.getRange().getStartTime());
+            request.setStartIndex((int) context.getRank());
+            return context;
+
+        }
+
+        return seekEvent(request.getIndex());
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTrace trace positioning
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public synchronized ITmfContext seekEvent(final ITmfLocation location) {
+        // Validate the location
+        if (location != null && !(location instanceof TmfExperimentLocation)) {
+            return null; // Throw an exception?
+        }
+        // Make sure we have something to read from
+        if (fTraces == null) {
+            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(fTraces.length);
+
+        // Position the traces
+        long rank = 0;
+        for (int i = 0; i < fTraces.length; i++) {
+            // Get the relevant trace attributes
+            final ITmfContext traceContext = fTraces[i].seekEvent(locations[i]);
+            context.setContext(i, traceContext);
+            traceContext.setRank(ranks[i]);
+            // update location after seek
+            locations[i] = traceContext.getLocation();
+            context.setEvent(i, fTraces[i].getNext(traceContext));
+            rank += ranks[i];
+        }
+
+        // Finalize context
+        context.setLocation(new TmfExperimentLocation(new TmfLocationArray(locations, ranks)));
+        context.setLastTrace(TmfExperimentContext.NO_TRACE);
+        context.setRank(rank);
+
+        return context;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTrace - SeekEvent operations (returning a trace context)
+    // ------------------------------------------------------------------------
+
+    @Override
+    public ITmfContext seekEvent(final double ratio) {
+        final ITmfContext context = seekEvent(Math.round(ratio * getNbEvents()));
+        return context;
+    }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public double getLocationRatio(final ITmfLocation location) {
+        if (location instanceof TmfExperimentLocation) {
+            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;
+    }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public ITmfLocation getCurrentLocation() {
+        // never used
+        return null;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTrace trace positioning
+    // ------------------------------------------------------------------------
+
+    @Override
+    public synchronized ITmfEvent parseEvent(final ITmfContext context) {
+        final ITmfContext tmpContext = seekEvent(context.getLocation());
+        final ITmfEvent event = getNext(tmpContext);
+        return event;
+    }
+
+    @Override
+    public synchronized ITmfEvent getNext(ITmfContext context) {
+
+        // Validate the context
+        if (!(context instanceof TmfExperimentContext)) {
+            return null; // Throw an exception?
+        }
+
+        // Make sure that we have something to read from
+        if (fTraces == null) {
+            return null;
+        }
+
+        TmfExperimentContext expContext = (TmfExperimentContext) context;
+
+        // If an event was consumed previously, first get the next one from that
+        // trace
+        final int lastTrace = expContext.getLastTrace();
+        if (lastTrace != TmfExperimentContext.NO_TRACE) {
+            final ITmfContext traceContext = expContext.getContext(lastTrace);
+            expContext.setEvent(lastTrace, fTraces[lastTrace].getNext(traceContext));
+            expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+        }
+
+        // Scan the candidate events and identify the "next" trace to read from
+        int trace = TmfExperimentContext.NO_TRACE;
+        ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+        for (int i = 0; i < fTraces.length; i++) {
+            final ITmfEvent event = expContext.getEvent(i);
+            if (event != null && event.getTimestamp() != null) {
+                final ITmfTimestamp otherTS = event.getTimestamp();
+                if (otherTS.compareTo(timestamp) < 0) {
+                    trace = i;
+                    timestamp = otherTS;
+                }
+            }
+        }
+
+        ITmfEvent event = null;
+        if (trace != TmfExperimentContext.NO_TRACE) {
+            event = expContext.getEvent(trace);
+            if (event != null) {
+                updateAttributes(expContext, event.getTimestamp());
+                expContext.increaseRank();
+                expContext.setLastTrace(trace);
+                final ITmfContext traceContext = expContext.getContext(trace);
+                if (traceContext == null) {
+                    throw new IllegalStateException();
+                }
+
+                // Update the experiment location
+                TmfLocationArray locationArray = new TmfLocationArray(
+                        ((TmfExperimentLocation) expContext.getLocation()).getLocationInfo(),
+                        trace, traceContext.getLocation(), traceContext.getRank());
+                expContext.setLocation(new TmfExperimentLocation(locationArray));
+
+                processEvent(event);
+            }
+        }
+
+        return event;
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public ITmfTimestamp getInitialRangeOffset() {
+        if ((fTraces == null) || (fTraces.length == 0)) {
+            return super.getInitialRangeOffset();
+        }
+
+        ITmfTimestamp initTs = TmfTimestamp.BIG_CRUNCH;
+        for (int i = 0; i < fTraces.length; i++) {
+            ITmfTimestamp ts = fTraces[i].getInitialRangeOffset();
+            if (ts.compareTo(initTs) < 0) {
+                initTs = ts;
+            }
+        }
+        return initTs;
+    }
+
+    /**
+     * Get the path to the folder in the supplementary file where
+     * synchronization-related data can be kept so they are not deleted when the
+     * experiment is synchronized. Analysis involved in synchronization can put
+     * their supplementary files in there so they are preserved after
+     * synchronization.
+     *
+     * If the directory does not exist, it will be created. A return value of
+     * <code>null</code> means either the trace resource does not exist or
+     * supplementary resources cannot be kept.
+     *
+     * @param absolute
+     *            If <code>true</code>, it returns the absolute path in the file
+     *            system, including the supplementary file path. Otherwise, it
+     *            returns only the directory name.
+     * @return The path to the folder where synchronization-related
+     *         supplementary files can be kept or <code>null</code> if not
+     *         available.
+     * @since 3.2
+     */
+    public String getSynchronizationFolder(boolean absolute) {
+        /* Set up the path to the synchronization file we'll use */
+        IResource resource = this.getResource();
+        String syncDirectory = null;
+
+        try {
+            /* get the directory where the file will be stored. */
+            if (resource != null) {
+                String fullDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
+                /* Create the synchronization data directory if not present */
+                if (fullDirectory != null) {
+                    fullDirectory = fullDirectory + File.separator + SYNCHRONIZATION_DIRECTORY;
+                    File syncDir = new File(fullDirectory);
+                    syncDir.mkdirs();
+                }
+                if (absolute) {
+                    syncDirectory = fullDirectory;
+                } else {
+                    syncDirectory = SYNCHRONIZATION_DIRECTORY;
+                }
+            }
+        } catch (CoreException e) {
+            return null;
+        }
+
+        return syncDirectory;
+    }
+
+    /**
+     * Synchronizes the traces of an experiment. By default it only tries to
+     * read a synchronization file if it exists
+     *
+     * @return The synchronization object
+     * @since 3.0
+     */
+    public synchronized SynchronizationAlgorithm synchronizeTraces() {
+        return synchronizeTraces(false);
+    }
+
+    /**
+     * Synchronizes the traces of an experiment.
+     *
+     * @param doSync
+     *            Whether to actually synchronize or just try opening a sync
+     *            file
+     * @return The synchronization object
+     * @since 3.0
+     */
+    public synchronized SynchronizationAlgorithm synchronizeTraces(boolean doSync) {
+
+        String syncDirectory = getSynchronizationFolder(true);
+
+        final File syncFile = (syncDirectory != null) ? new File(syncDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
+
+        final SynchronizationAlgorithm syncAlgo = SynchronizationManager.synchronizeTraces(syncFile, Arrays.asList(fTraces), doSync);
+
+        final TmfTraceSynchronizedSignal signal = new TmfTraceSynchronizedSignal(this, syncAlgo);
+
+        /* Broadcast in separate thread to prevent deadlock */
+        new Thread() {
+            @Override
+            public void run() {
+                broadcast(signal);
+            }
+        }.start();
+
+        return syncAlgo;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public synchronized String toString() {
+        return "[TmfExperiment (" + getName() + ")]";
+    }
+
+    // ------------------------------------------------------------------------
+    // Streaming support
+    // ------------------------------------------------------------------------
+
+    private synchronized void initializeStreamingMonitor() {
+
+        if (fInitialized) {
+            return;
+        }
+        fInitialized = true;
+
+        if (getStreamingInterval() == 0) {
+            final ITmfContext context = seekEvent(0);
+            final ITmfEvent event = getNext(context);
+            context.dispose();
+            if (event == null) {
+                return;
+            }
+            final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp(), TmfTimestamp.BIG_CRUNCH);
+            final TmfTraceRangeUpdatedSignal signal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
+
+            // Broadcast in separate thread to prevent deadlock
+            new Thread() {
+                @Override
+                public void run() {
+                    broadcast(signal);
+                }
+            }.start();
+            return;
+        }
+
+        final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$
+            private ITmfTimestamp safeTimestamp = null;
+            private ITmfTimestamp lastSafeTimestamp = null;
+            private TmfTimeRange timeRange = null;
+
+            @Override
+            public void run() {
+                while (!executorIsShutdown()) {
+                    if (!getIndexer().isIndexing()) {
+                        ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
+                        ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
+                        for (final ITmfTrace trace : fTraces) {
+                            if (trace.getStartTime().compareTo(startTimestamp) < 0) {
+                                startTimestamp = trace.getStartTime();
+                            }
+                            if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) {
+                                endTimestamp = trace.getEndTime();
+                            }
+                        }
+                        if (safeTimestamp != null && (lastSafeTimestamp == null || safeTimestamp.compareTo(lastSafeTimestamp) > 0)) {
+                            timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
+                            lastSafeTimestamp = safeTimestamp;
+                        } else {
+                            timeRange = null;
+                        }
+                        safeTimestamp = endTimestamp;
+                        if (timeRange != null) {
+                            final TmfTraceRangeUpdatedSignal signal =
+                                    new TmfTraceRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange);
+                            broadcast(signal);
+                        }
+                    }
+                    try {
+                        Thread.sleep(getStreamingInterval());
+                    } catch (final InterruptedException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        };
+        thread.start();
+    }
+
+    @Override
+    public long getStreamingInterval() {
+        long interval = 0;
+        for (final ITmfTrace trace : fTraces) {
+            interval = Math.max(interval, trace.getStreamingInterval());
+        }
+        return interval;
+    }
+
+    // ------------------------------------------------------------------------
+    // Signal handlers
+    // ------------------------------------------------------------------------
+
+    @Override
+    @TmfSignalHandler
+    public void traceOpened(TmfTraceOpenedSignal signal) {
+        if (signal.getTrace() == this) {
+            initializeStreamingMonitor();
+
+            /* Initialize the analysis */
+            MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
+            status.add(executeAnalysis());
+            if (!status.isOK()) {
+                Activator.log(status);
+            }
+            TmfTraceManager.refreshSupplementaryFiles(this);
+        }
+    }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public synchronized int getCheckpointSize() {
+        int totalCheckpointSize = 0;
+        try {
+            if (fTraces != null) {
+                for (final ITmfTrace trace : fTraces) {
+                    if (!(trace instanceof ITmfPersistentlyIndexable)) {
+                        return 0;
+                    }
+
+                    ITmfPersistentlyIndexable persistableIndexTrace = (ITmfPersistentlyIndexable) trace;
+                    int currentTraceCheckpointSize = persistableIndexTrace.getCheckpointSize();
+                    if (currentTraceCheckpointSize <= 0) {
+                        return 0;
+                    }
+                    totalCheckpointSize += currentTraceCheckpointSize;
+                    // each entry in the TmfLocationArray has a rank in addition
+                    // of the location
+                    totalCheckpointSize += 8;
+                }
+            }
+        } catch (UnsupportedOperationException e) {
+            return 0;
+        }
+
+        return totalCheckpointSize;
+    }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
+        ITmfLocation[] locations = new ITmfLocation[fTraces.length];
+        long[] ranks = new long[fTraces.length];
+        for (int i = 0; i < fTraces.length; ++i) {
+            final ITmfTrace trace = fTraces[i];
+            locations[i] = ((ITmfPersistentlyIndexable) trace).restoreLocation(bufferIn);
+            ranks[i] = bufferIn.getLong();
+        }
+        TmfLocationArray arr = new TmfLocationArray(locations, ranks);
+        TmfExperimentLocation l = new TmfExperimentLocation(arr);
+        return l;
+    }
+
+}
index 7703bac081cff3db9f2516fae8d8fa2ac7f345cf..758f3e3dc05f49baae6e89d628843e75c42d0bc8 100644 (file)
@@ -19,7 +19,7 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 
index 752e24107b8fba903aa152e72931a8d96ad3d467..8859b4ef61baf4f55071c51c04d5a0593178edf9 100644 (file)
@@ -33,8 +33,8 @@ import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.junit.After;
 import org.junit.AfterClass;
index a0c3fa7c360b399fbed059813df1a5668a16d8b9..3dac79ada9185e0c9abc06f9cd9e72bcc448cdea 100644 (file)
@@ -29,7 +29,7 @@ import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 
 /**
  * A pcap-specific analysis that parse an entire trace to find all the streams.
index 20a6020a1036b14b597678061aa335e56d31cb87..183879349f3a6d50dd30c793e5fc31244cb3ecca 100644 (file)
@@ -25,7 +25,7 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
index 4bd2b83f2e67faaeb3eaf9860514b7acb00258db..261ff2bcacc5ff22dcb2a9ee788fe4535e0a1b1b 100644 (file)
@@ -29,7 +29,7 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
 import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
index 013e43eb2aacf2a9c0190a715a5569bb36dbb8c0..13706e7243636509bde47e604e32a7f6916f7db1 100644 (file)
@@ -32,8 +32,8 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TraceUtils;
index 94a517403c3e8ba9ef6c6a933d74e2db7fd8c703..03fd15f392d3b501d7d7b71c57b3c7d8dcf241df 100644 (file)
@@ -16,8 +16,8 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
index 75300b2576f81d865cc3f5b4f98f482dbe587fdb..3f8e289fc122c082d5e47c8dd3bda5bcf91dab50 100644 (file)
@@ -49,8 +49,8 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.project.model.Messages;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
index d13039780f5ee46d22d77cd439a85fd668727e12..1b797a5412c6669c2561378a0b9770c6cf543f44 100644 (file)
@@ -43,9 +43,9 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
index 4944a8040ee971ca649d007a634b384c3219792c..a744202c08cd0a9d4b73ae8650314ca266e2975e 100644 (file)
@@ -41,7 +41,7 @@ import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
 import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
 import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
index 1e78fab27d226661498a2ab15d36bf8e181200ed..992c297d0bbee4f9dd631b0af0e22a4d602b536a 100644 (file)
@@ -41,7 +41,7 @@ import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
 import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEditorInput;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
 import org.eclipse.ui.IEditorInput;
index daba98bc417438e4df04349827a29b5a20fd700c..75f07721405abff56e96980ee79299527e189b90 100644 (file)
@@ -48,8 +48,8 @@ import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler;
 import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
index 8021e1dabb87f16d524730e0b881a55b40836f80..324908432b9d483054ec54cb6d82ee6fc447cf21 100644 (file)
@@ -25,8 +25,8 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSynchronizedSignal;
 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 import org.eclipse.tracecompass.tmf.ui.views.TmfView;
 
 /**
This page took 0.063991 seconds and 5 git commands to generate.