Refactor TmfTrace and TmfExperiment
authorFrancois Chouinard <fchouinard@gmail.com>
Tue, 8 May 2012 21:40:57 +0000 (17:40 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Tue, 8 May 2012 21:40:57 +0000 (17:40 -0400)
13 files changed:
org.eclipse.linuxtools.lttng.core.tests/META-INF/MANIFEST.MF
org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java
org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngTraceTest.java
org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentCheckpointIndexTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimeRange.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java

index df97ffa2d9a161f894dbef3f146763e38aad641f..b867c78bbfd7250b47013eeec85e869626883ce0 100644 (file)
@@ -7,7 +7,6 @@ Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.linuxtools.lttng.core.tests
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: org.eclipse.linuxtools.lttng.jni
 Fragment-Host: org.eclipse.linuxtools.lttng.core
 Require-Bundle: org.junit;bundle-version="3.8.2",
  org.eclipse.core.runtime;bundle-version="3.7.0",
index b1d9dbbdd4e3535760c276544722484d671cd4fe..4707fdf945dfb02e25798fe2f490fd055cab7c91 100644 (file)
@@ -60,7 +60,7 @@ public class LTTngExperimentTest extends TestCase {
             try {
                 final URL location = FileLocator.find(FrameworkUtil.getBundle(LTTngExperimentTest.class), new Path(path), null);
                 final File testfile = new File(FileLocator.toFileURL(location).toURI());
-                final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), false);
+                final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), true);
                 fTraces[0] = trace;
             } catch (final URISyntaxException e) {
                 e.printStackTrace();
index 83f4dbb39845834efa43324fc965b3b88dc97ee5..b585237196d9125fb8c2e87936636efe69b4101e 100644 (file)
@@ -11,6 +11,7 @@ import org.eclipse.linuxtools.internal.lttng.core.event.LttngLocation;
 import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 import org.osgi.framework.FrameworkUtil;
 
@@ -144,7 +145,7 @@ public class LTTngTraceTest extends TestCase {
 
     public void testSeekEventTimestamp() {
         TmfEvent tmpEvent = null;
-        TmfContext tmpContext = new TmfContext(null, 0);
+        ITmfContext tmpContext = new TmfContext(null, 0);
         final LTTngTrace testStream1 = prepareStreamToTest();
 
         // We should be at the beginning of the trace, we will seek at a certain timestamp
@@ -174,7 +175,7 @@ public class LTTngTraceTest extends TestCase {
 
     public void testSeekEventIndex() {
         TmfEvent tmpEvent = null;
-        TmfContext tmpContext = new TmfContext(null, 0);
+        ITmfContext tmpContext = new TmfContext(null, 0);
         final LTTngTrace testStream1 = prepareStreamToTest();
 
         // We should be at the beginning of the trace, we will seek at a certain timestamp
@@ -204,7 +205,7 @@ public class LTTngTraceTest extends TestCase {
 
     public void testSeekLocation() {
         TmfEvent tmpEvent = null;
-        TmfContext tmpContext = new TmfContext(null, 0);
+        ITmfContext tmpContext = new TmfContext(null, 0);
         final LTTngTrace testStream1 = prepareStreamToTest();
 
         // We should be at the beginning of the trace, we will seek at a certain timestamp
@@ -234,7 +235,7 @@ public class LTTngTraceTest extends TestCase {
 
     public void testLocationOperations() {
         TmfEvent tmpEvent = null;
-        TmfContext tmpContext = new TmfContext(null, 0);
+        ITmfContext tmpContext = new TmfContext(null, 0);
         final LTTngTrace testStream1 = prepareStreamToTest();
 
         // Test LttngLocation after a seek
index 0f5fe8d1e1424212276144c01e24c7a8c9b4451b..5a750e3e9df76912f40f1b5fd27e366c514e9f0c 100644 (file)
@@ -172,7 +172,7 @@ public class LTTngTrace extends TmfTrace<LttngEvent> implements ITmfEventParser<
         if (jniTrace == null
                 || (!jniTrace.isLiveTraceSupported() || !LiveTraceManager.isLiveTrace(jniTrace.getTracepath()))) {
             // Set the time range of the trace
-            final TmfContext context = seekEvent(0);
+            final ITmfContext context = seekEvent(0);
             final LttngEvent event = readNextEvent(context);
             final LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp());
             final LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime());
@@ -183,7 +183,7 @@ public class LTTngTrace extends TmfTrace<LttngEvent> implements ITmfEventParser<
         }
 
         // Set the time range of the trace
-        final TmfContext context = seekEvent(0);
+        final ITmfContext context = seekEvent(0);
         final LttngEvent event = readNextEvent(context);
         setEndTime(TmfTimestamp.BIG_BANG);
         final long startTime = event != null ? event.getTimestamp().getValue() : TmfTimestamp.BIG_BANG.getValue();
@@ -444,30 +444,23 @@ public class LTTngTrace extends TmfTrace<LttngEvent> implements ITmfEventParser<
      * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext
      */
     @Override
-    public synchronized TmfContext seekEvent(final ITmfLocation<?> location) {
-
-        // // [lmcfrch]
-        // lastTime = 0;
+    public synchronized ITmfContext seekEvent(final ITmfLocation<?> location) {
 
         if (PRINT_DEBUG)
             System.out.println("seekLocation(location) location -> " + location); //$NON-NLS-1$
 
         // If the location in context is null, create a new one
-        LttngLocation curLocation = null;
         if (location == null) {
-            curLocation = new LttngLocation();
-            final TmfContext context = seekEvent(curLocation.getOperationTime());
+            LttngLocation curLocation = new LttngLocation();
+            final ITmfContext context = seekEvent(curLocation.getOperationTime());
             context.setRank(0);
             return context;
-        } else
-            curLocation = (LttngLocation) location;
-
-        // *** NOTE :
-        // Update to location should (and will) be done in SeekEvent.
-
+        }
+        
         // The only seek valid in LTTng is with the time, we call
         // seekEvent(timestamp)
-        final TmfContext context = seekEvent(curLocation.getOperationTime());
+        LttngLocation curLocation = (LttngLocation) location;
+        final ITmfContext context = seekEvent(curLocation.getOperationTime());
 
         // If the location is marked with the read next flag
         // then it is pointing to the next event following the operation time
index 4b9c581773309663585e5336df8442ba34f3ff55..1192d6a14ff7d803c6f45bb8a64ed33c6d3312e4 100644 (file)
@@ -27,7 +27,8 @@ public class AllTests {
        public static Test suite() {
                TestSuite suite = new TestSuite("Test suite for " + TmfCorePlugin.PLUGIN_ID + ".experiment"); //$NON-NLS-1$);
                //$JUnit-BEGIN$
-               suite.addTestSuite(TmfExperimentTest.class);
+               suite.addTestSuite(TmfExperimentCheckpointIndexTest.class);
+        suite.addTestSuite(TmfExperimentTest.class);
                suite.addTestSuite(TmfMultiTraceExperimentTest.class);
                //$JUnit-END$
                return suite;
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentCheckpointIndexTest.java
new file mode 100644 (file)
index 0000000..8abf5da
--- /dev/null
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.experiment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentContext;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperimentLocation;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfLocationArray;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("nls")
+public class TmfExperimentCheckpointIndexTest extends TestCase {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private static final String DIRECTORY    = "testfiles";
+    private static final String TEST_STREAM1 = "O-Test-10K";
+    private static final String TEST_STREAM2 = "E-Test-10K";
+    private static final String EXPERIMENT   = "MyExperiment";
+    private static int          NB_EVENTS    = 20000;
+    private static int          BLOCK_SIZE   = 1000;
+
+    private static ITmfTrace<?>[] fTraces;
+    private static TestExperiment fExperiment;
+
+    // ------------------------------------------------------------------------
+    // Helper classes
+    // ------------------------------------------------------------------------
+
+    private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        public TestIndexer(TestExperiment testExperiment) {
+            super((ITmfTrace) testExperiment, BLOCK_SIZE);
+        }
+        public List<TmfCheckpoint> getCheckpoints() {
+            return getTraceIndex();
+        }
+    }
+
+    private class TestExperiment extends TmfExperiment<ITmfEvent> {
+        @SuppressWarnings("unchecked")
+        public TestExperiment() {
+            super(ITmfEvent.class, EXPERIMENT, (ITmfTrace<ITmfEvent>[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, false);
+            setIndexer(new TestIndexer(this));
+            getIndexer().buildIndex(true);
+        }
+        @Override
+        public TestIndexer getIndexer() {
+            return (TestIndexer) super.getIndexer();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Housekeeping
+    // ------------------------------------------------------------------------
+
+    public TmfExperimentCheckpointIndexTest(final String name) throws Exception {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
+        if (fExperiment == null) {
+            fExperiment = new TestExperiment();
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        fExperiment.dispose();
+        fExperiment = null;
+    }
+
+    private static ITmfTrace<?>[] setupTrace(final String path1, final String path2) {
+        if (fTraces == null) {
+            fTraces = new ITmfTrace[2];
+            try {
+                URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
+                File test = new File(FileLocator.toFileURL(location).toURI());
+                final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
+                fTraces[0] = trace1;
+                location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
+                test = new File(FileLocator.toFileURL(location).toURI());
+                final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
+                fTraces[1] = trace2;
+            } catch (final TmfTraceException e) {
+                e.printStackTrace();
+            } catch (final URISyntaxException e) {
+                e.printStackTrace();
+            } catch (final IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return fTraces;
+    }
+
+    // ------------------------------------------------------------------------
+    // Verify checkpoints
+    // ------------------------------------------------------------------------
+
+    public void testTmfTraceIndexing() throws Exception {
+        assertEquals("getCacheSize",   BLOCK_SIZE, fExperiment.getCacheSize());
+        assertEquals("getTraceSize",   NB_EVENTS,  fExperiment.getNbEvents());
+        assertEquals("getRange-start", 1,          fExperiment.getTimeRange().getStartTime().getValue());
+        assertEquals("getRange-end",   NB_EVENTS,  fExperiment.getTimeRange().getEndTime().getValue());
+        assertEquals("getStartTime",   1,          fExperiment.getStartTime().getValue());
+        assertEquals("getEndTime",     NB_EVENTS,  fExperiment.getEndTime().getValue());
+
+        List<TmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
+        int pageSize = fExperiment.getCacheSize();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+        // Validate that each checkpoint points to the right event
+        for (int i = 0; i < checkpoints.size(); i++) {
+            TmfCheckpoint checkpoint = checkpoints.get(i);
+            TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
+            TmfLocationArray locations = expLocation.getLocation();
+            ITmfContext[] trcContexts = new ITmfContext[2];
+            trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
+            trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
+            TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
+            expContext.getEvents()[0] = fTraces[0].readNextEvent(fTraces[0].seekEvent((i * pageSize) / 2));
+            expContext.getEvents()[1] = fTraces[1].readNextEvent(fTraces[1].seekEvent((i * pageSize) / 2));
+            ITmfEvent event = fExperiment.parseEvent(expContext);
+            assertTrue(expContext.getRank() == i * pageSize);
+            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+        }
+    }
+
+}
\ No newline at end of file
index d70c1cff9a76c2b838d4371b1afb7cdcdd6a675e..6d4666ccbc75c0acb8927603299e4bf7bb219b6c 100644 (file)
@@ -112,6 +112,9 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("GetId", EXPERIMENT, fExperiment.getName());
         assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
 
+        final long nbExperimentEvents = fExperiment.getNbEvents();
+        assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents);
+
         final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
         assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
 
@@ -120,28 +123,6 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue());
     }
 
-    // ------------------------------------------------------------------------
-    // Verify checkpoints
-    // ------------------------------------------------------------------------
-
-//    public void testValidateCheckpoints() throws Exception {
-//
-//        final Vector<TmfCheckpoint> checkpoints = fExperiment.getCheckpoints();
-//        final int pageSize = fExperiment.getCacheSize();
-//        assertTrue("Checkpoints exist", checkpoints != null);
-//
-//        // Validate that each checkpoint points to the right event
-//        long expectedTS = 1;
-//        for (TmfCheckpoint checkpoint : checkpoints) {
-//            final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation());
-//            final ITmfEvent event = fExperiment.readNextEvent(context);
-//            assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-//            assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-//            assertEquals("Timestamp", expectedTS, checkpoint.getTimestamp().getValue());
-//            expectedTS += pageSize;
-//        }
-//    }
-
     // ------------------------------------------------------------------------
     // seekEvent on rank
     // ------------------------------------------------------------------------
index f4b12dc0d3d3445371d91b433ca51c5d3fe6ff23..116872c50a21b6b2b159cfeed6fb003d3e7c2ace 100644 (file)
@@ -85,24 +85,18 @@ public class TmfMultiTraceExperimentTest extends TestCase {
         return fTraces;
     }
 
-    @SuppressWarnings("unchecked")
-    private synchronized static void setupExperiment() {
-        synchronized (TmfMultiTraceExperimentTest.class) {
-            if (fExperiment == null) {
-                fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, (ITmfTrace<TmfEvent>[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, true);
-            }
-        }
-    }
-
     public TmfMultiTraceExperimentTest(final String name) throws Exception {
         super(name);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
-        setupExperiment();
+        if (fExperiment == null) {
+            fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, (ITmfTrace<TmfEvent>[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, true);
+        }
     }
 
     @Override
@@ -124,28 +118,6 @@ public class TmfMultiTraceExperimentTest extends TestCase {
         assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue());
     }
 
-    // ------------------------------------------------------------------------
-    // Verify checkpoints
-    // ------------------------------------------------------------------------
-
-//    public void testValidateCheckpoints() throws Exception {
-//
-//        final Vector<TmfCheckpoint> checkpoints = fExperiment.getCheckpoints();
-//        final int pageSize = fExperiment.getCacheSize();
-//        assertTrue("Checkpoints exist", checkpoints != null);
-//
-//        // Validate that each checkpoint points to the right event
-//        long expectedTS = 1;
-//        for (TmfCheckpoint checkpoint : checkpoints) {
-//            final TmfExperimentContext context = fExperiment.seekEvent(checkpoint.getLocation());
-//            final ITmfEvent event = fExperiment.readNextEvent(context);
-//            assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-//            assertTrue("Timestamp", (checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-//            assertEquals("Timestamp", expectedTS, checkpoint.getTimestamp().getValue());
-//            expectedTS += pageSize;
-//        }
-//    }
-
     // ------------------------------------------------------------------------
     // seekEvent on rank
     // ------------------------------------------------------------------------
index 2371d8261265de9e115440b4a32da1ee1fb7cde0..3255dc29df6f0c60446b0d89cfb3f567c896ae38 100644 (file)
@@ -44,7 +44,7 @@ public class TmfCheckpointIndexTest extends TestCase {
 
     private static final String DIRECTORY   = "testfiles";
     private static final String TEST_STREAM = "A-Test-10K";
-    private static final int    BLOCK_SIZE  = 500;
+    private static final int    BLOCK_SIZE  = 100;
     private static final int    NB_EVENTS   = 10000;
     private static TestTrace    fTrace      = null;
 
@@ -76,7 +76,7 @@ public class TmfCheckpointIndexTest extends TestCase {
     private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
         @SuppressWarnings({ "unchecked", "rawtypes" })
         public TestIndexer(TestTrace testTrace) {
-            super((ITmfTrace) testTrace);
+            super((ITmfTrace) testTrace, BLOCK_SIZE);
         }
         public List<TmfCheckpoint> getCheckpoints() {
             return getTraceIndex();
@@ -131,6 +131,7 @@ public class TmfCheckpointIndexTest extends TestCase {
         List<TmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
         int pageSize = fTrace.getCacheSize();
         assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
 
         // Validate that each checkpoint points to the right event
         for (int i = 0; i < checkpoints.size(); i++) {
index f038420de1c6d564d50d5010b0f64357140b20fe..203530747967e5fc9b779a72ab3798b6db900d53 100644 (file)
@@ -130,6 +130,9 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> implements ITmfEventParser<
             throw new TmfTraceException(e.getMessage());
         }
         setParser(new TmfEventParserStub(this));
+        if (waitForCompletion) {
+            indexTrace();
+        }
     }
 
     /**
index 71886dbbd2c8247ae160d76fa48e7e6d91baff37..47a5f9dffc705617a37916ad3c21b439b27ba3a4 100644 (file)
@@ -37,7 +37,7 @@ public final class TmfTimeRange implements Cloneable {
      * The null time range
      */
     public static final TmfTimeRange NULL_RANGE =
-            new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_BANG);
+            new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_BANG);
 
     // ------------------------------------------------------------------------
     // Attributes
index 0ac6fa0dd04eaf3e1b4f44f1538ef0d4dee83517..4f2f06929195e35471c8c7825dfe519ecdb10ba5 100644 (file)
@@ -52,26 +52,14 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
     // The set of traces that constitute the experiment
     private ITmfTrace<T>[] fTraces;
 
-//    // The experiment time range
-//    private TmfTimeRange fTimeRange;
-
-//    // The total number of events
-//    private long fNbEvents;
-
-//    // The experiment index
-//    private Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
-
-//    // The current experiment context
-//    private TmfExperimentContext fExperimentContext;
-
     // Flag to initialize only once
     private boolean fInitialized = false;
 
     // The experiment bookmarks file
     private IFile fBookmarksFile;
 
-    // The properties resource
-    private IResource fResource;
+//    // The properties resource
+//    private IResource fResource;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -83,8 +71,14 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
     }
 
     @Override
-    public void initTrace(final IResource resource, final String path, final Class<T> eventType) {
-        fResource = resource;
+    public void initTrace(final IResource resource, final String path, final Class<T> type) {
+//        fResource = resource;
+        try {
+            super.initTrace(resource, path, type);
+        } catch (TmfTraceException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -107,7 +101,7 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
     {
         setCacheSize(indexPageSize);
         setStreamingInterval(0);
-        setIndexer(new TmfCheckpointIndexer(this));
+        setIndexer(new TmfCheckpointIndexer(this, indexPageSize));
         setParser(this);
         try {
             super.initialize(null, path, type);
@@ -120,30 +114,9 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
 
         if (preIndexExperiment) {
             getIndexer().buildIndex(true);
-//            updateTimeRange();
         }
     }
 
-//    /**
-//     * Initialize the trace common attributes and the base component.
-//     * 
-//     * @param resource the Eclipse resource (trace) 
-//     * @param path the trace path
-//     * @param type the trace event type
-//     * 
-//     * @throws TmfTraceException
-//     */
-//    @Override
-//    @SuppressWarnings("unchecked")
-//    protected void initialize(final IResource resource, final String path, final Class<T> type) {
-//        setParser(this);
-//        super.initialize(resource, path, type);
-//    }
-
-//    protected TmfExperiment(final String id, final Class<T> type) {
-//        super(id, type);
-//    }
-
     /**
      * @param type
      * @param id
@@ -182,49 +155,9 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
                 trace.dispose();
             fTraces = null;
         }
-//        if (fCheckpoints != null)
-//            fCheckpoints.clear();
         super.dispose();
     }
 
-    // ------------------------------------------------------------------------
-    // ITmfTrace
-    // ------------------------------------------------------------------------
-
-//    @Override
-//    public Class<T> getEventType() {
-//        return fType;
-//    }
-
-//    @Override
-//    public long getNbEvents() {
-//        return fNbEvents;
-//    }
-
-//    @Override
-//    public int getCacheSize() {
-//        return fIndexPageSize;
-//    }
-
-//    @Override
-//    public TmfTimeRange getTimeRange() {
-//        return fTimeRange;
-//    }
-
-//    @Override
-//    public ITmfTimestamp getStartTime() {
-//        return fTimeRange.getStartTime();
-//    }
-
-//    @Override
-//    public ITmfTimestamp getEndTime() {
-//        return fTimeRange.getEndTime();
-//    }
-
-//    public Vector<TmfCheckpoint> getCheckpoints() {
-//        return fCheckpoints;
-//    }
-
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
@@ -251,69 +184,33 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
      * @return the corresponding event timestamp
      */
     public ITmfTimestamp getTimestamp(final int index) {
-//        final TmfExperimentContext context = seekEvent(index);
         final ITmfContext context = seekEvent(index);
         final ITmfEvent event = readNextEvent(context);
         return (event != null) ? event.getTimestamp() : null;
     }
 
-    // ------------------------------------------------------------------------
-    // Operators
-    // ------------------------------------------------------------------------
-
-    /**
-     * Update the global time range
-     */
-    protected void updateTimeRange() {
-        TmfTimeRange timeRange = getTimeRange();
-        ITmfTimestamp startTime = timeRange.equals(TmfTimeRange.NULL_RANGE) ? TmfTimestamp.BIG_CRUNCH : timeRange.getStartTime();
-        ITmfTimestamp endTime = timeRange.equals(TmfTimeRange.NULL_RANGE) ? TmfTimestamp.BIG_BANG : timeRange.getEndTime();
-
-        for (final ITmfTrace<T> trace : fTraces) {
-            final ITmfTimestamp traceStartTime = trace.getStartTime();
-            if (traceStartTime.compareTo(startTime, true) < 0)
-                startTime = traceStartTime;
-            final ITmfTimestamp traceEndTime = trace.getEndTime();
-            if (traceEndTime.compareTo(endTime, true) > 0)
-                endTime = traceEndTime;
-        }
-        setTimeRange(new TmfTimeRange(startTime, endTime));
-    }
-
     // ------------------------------------------------------------------------
     // TmfProvider
     // ------------------------------------------------------------------------
 
     @Override
     public ITmfContext armRequest(final ITmfDataRequest<T> request) {
-        //             Tracer.trace("Ctx: Arming request - start");
         ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
-        if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0)
-            timestamp = null; // use request index
-//        TmfExperimentContext context = null;
+        if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0) {
+            timestamp = null;
+        }
+
         ITmfContext context = null;
-        if (timestamp != null) {
-            // seek by timestamp
+        if (timestamp != null) { // Seek by timestamp
             context = seekEvent(timestamp);
             ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
-        } else // Seek by rank
-//            if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex())
-//                // We are already at the right context -> no need to seek
-//                context = fExperimentContext;
-//            else
-                context = seekEvent(request.getIndex());
-        // Tracer.trace("Ctx: Arming request - done");
+        } else { // Seek by rank
+            context = seekEvent(request.getIndex());
+        }
+
         return context;
     }
 
-//    @Override
-//    @SuppressWarnings("unchecked")
-//    public T getNext(final ITmfContext context) {
-//        if (context instanceof TmfExperimentContext)
-//            return (T) readNextEvent(context);
-//        return null;
-//    }
-
     // ------------------------------------------------------------------------
     // ITmfTrace trace positioning
     // ------------------------------------------------------------------------
@@ -335,161 +232,22 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
 
         // Create and populate the context's traces contexts
         final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]);
-        // Tracer.trace("Ctx: SeekLocation - start");
 
-//        long rank = 0;
         for (int i = 0; i < fTraces.length; i++) {
             // Get the relevant trace attributes
             final ITmfLocation<?> traceLocation = expLocation.getLocation().getLocations()[i];
-//            final long traceRank = expLocation.getRanks()[i];
-
-            // Set the corresponding sub-context
             context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
-//            context.getContexts()[i].setRank(traceRank);
-//            rank += traceRank;
-
-            // Set the trace location and read the corresponding event
-            /*
-             * The (TmfContext) cast should be safe since we created 'context'
-             * ourselves higher up.
-             */
             expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone();
             context.getEvents()[i] = fTraces[i].readNextEvent(context.getContexts()[i]);
         }
 
-        // Tracer.trace("Ctx: SeekLocation - done");
-
         // Finalize context
         context.setLocation(expLocation);
         context.setLastTrace(TmfExperimentContext.NO_TRACE);
-//        context.setRank(rank);
         context.setRank(ITmfContext.UNKNOWN_RANK);
-
-//        fExperimentContext = context;
-
         return context;
     }
 
-//    /* (non-Javadoc)
-//     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
-//     */
-//    @Override
-//    public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) {
-//
-//        //           Tracer.trace("Ctx: seekEvent(TS) - start");
-//
-//        if (timestamp == null)
-//            timestamp = TmfTimestamp.BIG_BANG;
-//
-//        // First, find the right checkpoint
-//        int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
-//
-//        // In the very likely case that the checkpoint was not found, bsearch
-//        // returns its negated would-be location (not an offset...). From that
-//        // index, we can then position the stream and get the event.
-//        if (index < 0)
-//            index = Math.max(0, -(index + 2));
-//
-//        // Position the experiment at the checkpoint
-//        ITmfLocation<?> location;
-//        synchronized (fCheckpoints) {
-//            if (fCheckpoints.size() > 0) {
-//                if (index >= fCheckpoints.size())
-//                    index = fCheckpoints.size() - 1;
-//                location = fCheckpoints.elementAt(index).getLocation();
-//            } else
-//                location = null;
-//        }
-//
-//        final TmfExperimentContext context = seekEvent(location);
-//        context.setRank((long) index * fIndexPageSize);
-//
-//        // And locate the requested event context
-//        final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
-//        ITmfEvent event = readNextEvent(nextEventContext);
-//        while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
-//            context.setLocation(nextEventContext.getLocation().clone());
-//            context.increaseRank();
-//            event = readNextEvent(nextEventContext);
-//        }
-//        if (event == null) {
-//            context.setLocation(null);
-//            context.setRank(ITmfContext.UNKNOWN_RANK);
-//        }
-//        return context;
-//
-////        // And locate the event
-////        ITmfEvent event = parseEvent(context);
-////        while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) {
-////            readNextEvent(context);
-////            event = parseEvent(context);
-////        }
-//
-////        if (event == null) {
-////            context.setLocation(null);
-////            context.setRank(ITmfContext.UNKNOWN_RANK);
-////        }
-////
-////        return context;
-//    }
-
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
-     */
-//    @Override
-//    public synchronized TmfExperimentContext seekEvent(final long rank) {
-//
-//        //           Tracer.trace("Ctx: seekEvent(rank) - start");
-//
-//        // Position the stream at the previous checkpoint
-//        int index = (int) rank / fIndexPageSize;
-//        ITmfLocation<?> location;
-//        synchronized (fCheckpoints) {
-//            if (fCheckpoints.size() == 0)
-//                location = null;
-//            else {
-//                if (index >= fCheckpoints.size())
-//                    index = fCheckpoints.size() - 1;
-//                location = fCheckpoints.elementAt(index).getLocation();
-//            }
-//        }
-//
-//        final TmfExperimentContext context = seekEvent(location);
-//        context.setRank((long) index * fIndexPageSize);
-//
-////        // Position the trace at the checkpoint
-////        final ITmfContext context = fIndexer.seekIndex(rank);
-//
-//        // And locate the requested event context
-//        long pos = context.getRank();
-//        if (pos < rank) {
-//            ITmfEvent event = readNextEvent(context);
-//            while (event != null && ++pos < rank) {
-//                event = readNextEvent(context);
-//            }
-//            if (event == null) {
-//                context.setLocation(null);
-//                context.setRank(ITmfContext.UNKNOWN_RANK);
-//            }
-//        }
-//        return context;
-//
-////        // And locate the event
-////        ITmfEvent event = parseEvent(context);
-////        long pos = context.getRank();
-////        while ((event != null) && (pos++ < rank)) {
-////            readNextEvent(context);
-////            event = parseEvent(context);
-////        }
-////
-////        if (event == null) {
-////            context.setLocation(null);
-////            context.setRank(ITmfContext.UNKNOWN_RANK);
-////        }
-////
-////        return context;
-//    }
-
     @Override
     public ITmfContext seekEvent(final double ratio) {
         final ITmfContext context = seekEvent((long) (ratio * getNbEvents()));
@@ -505,9 +263,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
 
     @Override
     public ITmfLocation<?> getCurrentLocation() {
-//        if (fExperimentContext != null)
-//            return fExperimentContext.getLocation();
-//        return null;
         ITmfLocation<?>[] locations = new ITmfLocation<?>[fTraces.length];
         for (int i = 0; i < fTraces.length; i++) {
             locations[i] = fTraces[i].getCurrentLocation();
@@ -515,116 +270,28 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
         return new TmfExperimentLocation(new TmfLocationArray(locations));
     }
 
-    // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
-    //         TmfContext context0 = context.getContexts()[0];
-    //         TmfEvent   event0   = context.getEvents()[0];
-    //         TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
-    //         long       rank0    = context.getRank();
-    //         int        trace    = context.getLastTrace();
-    //
-    //         StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
-    //
-    //         result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
-    //         result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
-    //         result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
-    //         result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
-    //         Tracer.trace(result.toString());
-    // }
-
-//    /**
-//     * Scan the next events from all traces and return the next one in
-//     * chronological order.
-//     * 
-//     * @param context the trace context
-//     * @return the next event
-//     */
-//    @Override
-//    public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
-//
-//        // Validate the context
-//        if (!(context instanceof TmfExperimentContext))
-//            return null; // Throw an exception?
-//
-//        if (!context.equals(fExperimentContext))
-//            // Tracer.trace("Ctx: Restoring context");
-//            fExperimentContext = seekEvent(context.getLocation());
-//
-//        final TmfExperimentContext expContext = (TmfExperimentContext) context;
-//
-//        //           dumpContext(expContext, true);
-//        // If an event was consumed previously, get the next one from that trace
-//        final int lastTrace = expContext.getLastTrace();
-//        if (lastTrace != TmfExperimentContext.NO_TRACE) {
-//            final ITmfContext traceContext = expContext.getContexts()[lastTrace];
-//            expContext.getEvents()[lastTrace] = fTraces[lastTrace].readNextEvent(traceContext);
-//            expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
-//        }
-//
-//        // Scan the candidate events and identify the "next" trace to read from
-//        final ITmfEvent eventArray[] = expContext.getEvents();
-//        if (eventArray == null)
-//            return null;
-//        int trace = TmfExperimentContext.NO_TRACE;
-//        ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
-//        if (eventArray.length == 1) {
-//            if (eventArray[0] != null) {
-//                timestamp = eventArray[0].getTimestamp();
-//                trace = 0;
-//            }
-//        } else
-//            for (int i = 0; i < eventArray.length; i++) {
-//                final ITmfEvent event = eventArray[i];
-//                if (event != null && event.getTimestamp() != null) {
-//                    final ITmfTimestamp otherTS = event.getTimestamp();
-//                    if (otherTS.compareTo(timestamp, true) < 0) {
-//                        trace = i;
-//                        timestamp = otherTS;
-//                    }
-//                }
-//            }
-//
-//        // Update the experiment context and set the "next" event
-//        ITmfEvent event = null;
-//        if (trace != TmfExperimentContext.NO_TRACE) {
-//            updateIndex(expContext, timestamp);
-//
-//            final ITmfContext traceContext = expContext.getContexts()[trace];
-//            final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
-//            //               expLocation.getLocation()[trace] = traceContext.getLocation().clone();
-//            expLocation.getLocation().getLocations()[trace] = traceContext.getLocation().clone();
-//
-//            //               updateIndex(expContext, timestamp);
-//
-////            expLocation.getRanks()[trace] = traceContext.getRank();
-//            expContext.setLastTrace(trace);
-//            expContext.increaseRank();
-//            event = expContext.getEvents()[trace];
-//            fExperimentContext = expContext;
-//        }
-//
-//        //           if (event != null) {
-//        //                   Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
-//        //                   dumpContext(expContext, false);
-//        //                   Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
-//        //           }
-//
-//        return event;
-//    }
-
-//    public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
-//        // Build the index as we go along
-//        final long rank = context.getRank();
-//        if (context.hasValidRank() && (rank % fIndexPageSize) == 0) {
-//            // Determine the table position
-//            final long position = rank / fIndexPageSize;
-//            // Add new entry at proper location (if empty)
-//            if (fCheckpoints.size() == position) {
-//                final ITmfLocation<?> location = context.getLocation().clone();
-//                fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
-////                System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "  + location.toString());
-//            }
-//        }
-//    }
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
+     */
+    @Override
+    public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
+        // parseEvent() does not update the context
+        final ITmfEvent event = parseEvent(context);
+        if (event != null) {
+            updateAttributes(context, event.getTimestamp());
+
+            TmfExperimentContext expContext = (TmfExperimentContext) context;
+            int trace = expContext.getLastTrace();
+            if (trace != TmfExperimentContext.NO_TRACE) {
+                TmfExperimentLocation location = (TmfExperimentLocation) expContext.getLocation();
+                location.getLocation().getLocations()[trace] = expContext.getContexts()[trace].getLocation();
+            }
+            
+            context.increaseRank();
+            processEvent(event);
+        }
+        return event;
+    }
 
     /* (non-Javadoc)
      * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
@@ -637,10 +304,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
         if (!(context instanceof TmfExperimentContext))
             return null; // Throw an exception?
 
-//        if (!context.equals(fExperimentContext))
-//            // Tracer.trace("Ctx: Restoring context");
-//            fExperimentContext = seekEvent(context.getLocation());
-
         TmfExperimentContext expContext = (TmfExperimentContext) context;
 
         // If an event was consumed previously, first get the next one from that trace
@@ -649,7 +312,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
             final ITmfContext traceContext = expContext.getContexts()[lastTrace];
             expContext.getEvents()[lastTrace] = fTraces[lastTrace].readNextEvent(traceContext);
             expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
-//            fExperimentContext = (TmfExperimentContext) context;
         }
 
         // Scan the candidate events and identify the "next" trace to read from
@@ -667,64 +329,12 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
         }
 
         T event = null;
-        if (trace != TmfExperimentContext.NO_TRACE)
+        if (trace != TmfExperimentContext.NO_TRACE) {
             event = (T) expContext.getEvents()[trace];
+        }
 
-//        TmfExperimentLocation location = (TmfExperimentLocation) fExperimentContext.getLocation();
-//        location.getLocation().getLocations()[trace] = fTraces[trace].getCurrentLocation();
         expContext.setLastTrace(trace);
         return event;
-
-//      // Scan the candidate events and identify the "next" trace to read from
-//      final ITmfEvent eventArray[] = expContext.getEvents();
-//      if (eventArray == null)
-//          return null;
-//      int trace = TmfExperimentContext.NO_TRACE;
-//      ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
-//      if (eventArray.length == 1) {
-//          if (eventArray[0] != null) {
-//              timestamp = eventArray[0].getTimestamp();
-//              trace = 0;
-//          }
-//      } else
-//          for (int i = 0; i < eventArray.length; i++) {
-//              final ITmfEvent event = eventArray[i];
-//              if (event != null && event.getTimestamp() != null) {
-//                  final ITmfTimestamp otherTS = event.getTimestamp();
-//                  if (otherTS.compareTo(timestamp, true) < 0) {
-//                      trace = i;
-//                      timestamp = otherTS;
-//                  }
-//              }
-//          }
-//
-//      // Update the experiment context and set the "next" event
-//      ITmfEvent event = null;
-//      if (trace != TmfExperimentContext.NO_TRACE) {
-//          updateIndex(expContext, timestamp);
-//
-//          final ITmfContext traceContext = expContext.getContexts()[trace];
-//          final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
-//          //            expLocation.getLocation()[trace] = traceContext.getLocation().clone();
-//          expLocation.getLocation().getLocations()[trace] = traceContext.getLocation().clone();
-//
-//          //            updateIndex(expContext, timestamp);
-//
-////          expLocation.getRanks()[trace] = traceContext.getRank();
-//          expContext.setLastTrace(trace);
-//          expContext.increaseRank();
-//          event = expContext.getEvents()[trace];
-//          fExperimentContext = expContext;
-//      }
-//
-//      //        if (event != null) {
-//      //            Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
-//      //            dumpContext(expContext, false);
-//      //            Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
-//      //        }
-//
-//      return event;
-
     }
 
     /* (non-Javadoc)
@@ -832,142 +442,13 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
 
     private Integer fEndSynchReference;
 
-    // private static BufferedWriter fEventLog = null;
-    // private static BufferedWriter openLogFile(String filename) {
-    //         BufferedWriter outfile = null;
-    //         try {
-    //                 outfile = new BufferedWriter(new FileWriter(filename));
-    //         } catch (IOException e) {
-    //                 e.printStackTrace();
-    //         }
-    //         return outfile;
-    // }
-
     protected boolean isIndexingBusy() {
-//        synchronized (fCheckpoints) {
-            return fIndexing;
-//        }
+        return fIndexing;
     }
 
-//    @SuppressWarnings("unchecked")
-//    private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
-//
-//        synchronized (fCheckpoints) {
-//            if (fIndexing)
-//                return;
-//            fIndexing = true;
-//        }
-//
-//        final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
-//
-//            @Override
-//            protected IStatus run(final IProgressMonitor monitor) {
-//                while (!monitor.isCanceled())
-//                    try {
-//                        Thread.sleep(100);
-//                    } catch (final InterruptedException e) {
-//                        return Status.OK_STATUS;
-//                    }
-//                monitor.done();
-//                return Status.OK_STATUS;
-//            }
-//        };
-//        job.schedule();
-//
-//        //           fEventLog = openLogFile("TraceEvent.log");
-//        //        System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
-//
-//        final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index,
-//                TmfDataRequest.ALL_DATA,
-//                fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA
-//            // FOREGROUND
-//
-////            long indexingStart = System.nanoTime();
-//
-//            ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime();
-//            ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime();
-//            long initialNbEvents = fNbEvents;
-//
-//            @Override
-//            public void handleStarted() {
-//                super.handleStarted();
-//            }
-//
-//            @Override
-//            public void handleData(final ITmfEvent event) {
-//                super.handleData(event);
-//                if (event != null) {
-//                    final ITmfTimestamp ts = event.getTimestamp();
-//                    if (startTime == null)
-//                        startTime = ts.clone();
-//                    lastTime = ts.clone();
-//                }
-//                if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1) {
-//                    updateExperiment();
-//                }
-//            }
-//
-//            @Override
-//            public void handleSuccess() {
-////                long indexingEnd = System.nanoTime();
-//
-//                // if the end time is a real value then it is the streaming safe
-//                // time stamp
-//                // set the last time to the safe time stamp to prevent
-//                // unnecessary indexing requests
-//                if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH)
-//                    lastTime = getRange().getEndTime();
-//                updateExperiment();
-//                ///////////////////////////////////////////////////////////////////
-////                System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
-////                long average = (indexingEnd - indexingStart) / fNbEvents;
-////                System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
-////                        + (indexingEnd * 1.0 - indexingStart) / 1000000000);
-////                System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
-////                        + (average % 1000) + " us/evt)");
-//                ///////////////////////////////////////////////////////////////////
-//                super.handleSuccess();
-//            }
-//
-//            @Override
-//            public void handleCompleted() {
-//                job.cancel();
-//                super.handleCompleted();
-//                synchronized (fCheckpoints) {
-//                    fIndexing = false;
-//                    if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) {
-//                        indexExperiment(false, (int) fNbEvents, fIndexingPendingRange);
-//                        fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
-//                    }
-//                }
-//            }
-//
-//            private void updateExperiment() {
-//                final int nbRead = getNbRead();
-//                if (startTime != null)
-//                    fTimeRange = new TmfTimeRange(startTime, lastTime.clone());
-//                if (nbRead != 0) {
-//                    //                                       updateTimeRange();
-//                    //                                       updateNbEvents();
-//                    fNbEvents = initialNbEvents + nbRead;
-//                    notifyListeners();
-//                }
-//            }
-//        };
-//
-//        sendRequest((ITmfDataRequest<T>) request);
-//        if (waitForCompletion)
-//            try {
-//                request.waitForCompletion();
-//            } catch (final InterruptedException e) {
-//                e.printStackTrace();
-//            }
-//    }
 
     protected void notifyListeners() {
         broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
-        // broadcast(new TmfExperimentRangeUpdatedSignal(this, this,
-        // fTimeRange)); // , null));
     }
 
     // ------------------------------------------------------------------------
@@ -980,8 +461,6 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
         if (experiment == this) {
             setCurrentExperiment(experiment);
             fEndSynchReference = Integer.valueOf(signal.getReference());
-//            fCheckpoints.clear();
-//            fNbEvents = 0;
         }
     }
 
@@ -1000,36 +479,10 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
     @TmfSignalHandler
     public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) {
         if (signal.getExperiment() == this) {
-//            indexExperiment(false, (int) fNbEvents, signal.getRange());
             getIndexer().buildIndex(false);
         }
     }
 
-//    @TmfSignalHandler
-//    public void traceUpdated(final TmfTraceUpdatedSignal signal) {
-//        for (final ITmfTrace<T> trace : fTraces)
-//            if (trace == signal.getTrace()) {
-//                synchronized (fCheckpoints) {
-//                    if (fIndexing) {
-//                        if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE)
-//                            fIndexingPendingRange = signal.getRange();
-//                        else {
-//                            ITmfTimestamp startTime = fIndexingPendingRange.getStartTime();
-//                            ITmfTimestamp endTime = fIndexingPendingRange.getEndTime();
-//                            if (signal.getRange().getStartTime().compareTo(startTime) < 0)
-//                                startTime = signal.getRange().getStartTime();
-//                            if (signal.getRange().getEndTime().compareTo(endTime) > 0)
-//                                endTime = signal.getRange().getEndTime();
-//                            fIndexingPendingRange = new TmfTimeRange(startTime, endTime);
-//                        }
-//                        return;
-//                    }
-//                }
-//                indexExperiment(false, (int) fNbEvents, signal.getRange());
-//                return;
-//            }
-//    }
-
     @Override
     public String getPath() {
         // TODO Auto-generated method stub
@@ -1054,13 +507,976 @@ public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements I
         return fBookmarksFile;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
-     */
-    @Override
-    public IResource getResource() {
-        return fResource;
-    }
+//    /*
+//     * (non-Javadoc)
+//     * 
+//     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+//     */
+//    @Override
+//    public IResource getResource() {
+//        return fResource;
+//    }
 }
+
+
+///*******************************************************************************
+// * Copyright (c) 2009, 2010 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.linuxtools.tmf.core.experiment;
+//
+//import java.util.Collections;
+//import java.util.Vector;
+//
+//import org.eclipse.core.resources.IFile;
+//import org.eclipse.core.resources.IProject;
+//import org.eclipse.core.resources.IResource;
+//import org.eclipse.core.runtime.IProgressMonitor;
+//import org.eclipse.core.runtime.IStatus;
+//import org.eclipse.core.runtime.Status;
+//import org.eclipse.core.runtime.jobs.Job;
+//import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
+//import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+//import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+//import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+//import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+//import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+//import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+//import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+//import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+//import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+//import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+//import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+//import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+//
+///**
+// * <b><u>TmfExperiment</u></b>
+// * <p>
+// * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
+// * that are part of a tracing experiment.
+// * <p>
+// */
+//public class TmfExperiment<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
+//
+//    // ------------------------------------------------------------------------
+//    // Attributes
+//    // ------------------------------------------------------------------------
+//
+//    // The currently selected experiment
+//    protected static TmfExperiment<?> fCurrentExperiment = null;
+//
+//    // The set of traces that constitute the experiment
+//    protected ITmfTrace<T>[] fTraces;
+//
+//    // The total number of events
+//    protected long fNbEvents;
+//
+//    // The experiment time range
+//    protected TmfTimeRange fTimeRange;
+//
+//    // The experiment reference timestamp (default: ZERO)
+//    protected ITmfTimestamp fEpoch;
+//
+//    // The experiment index
+//    protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
+//
+//    // The current experiment context
+//    protected TmfExperimentContext fExperimentContext;
+//
+//    // Flag to initialize only once
+//    private boolean fInitialized = false;
+//
+//    // The experiment bookmarks file
+//    private IFile fBookmarksFile;
+//
+//    // The properties resource
+//    private IResource fResource;
+//
+//    // ------------------------------------------------------------------------
+//    // Constructors
+//    // ------------------------------------------------------------------------
+//
+//    @Override
+//    public TmfExperiment<T> clone() throws CloneNotSupportedException {
+//        throw new CloneNotSupportedException();
+//    }
+//
+//    @Override
+//    public boolean validate(final IProject project, final String path) {
+//        return true;
+//    }
+//
+//    @Override
+//    public void initTrace(final IResource resource, final String path, final Class<T> eventType) {
+//        fResource = resource;
+//    }
+//
+//    /**
+//     * @param type
+//     * @param id
+//     * @param traces
+//     * @param epoch
+//     * @param indexPageSize
+//     */
+//    public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+//            final int indexPageSize) {
+//        this(type, id, traces, TmfTimestamp.ZERO, indexPageSize, false);
+//    }
+//
+//    public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final ITmfTimestamp epoch,
+//            final int indexPageSize, final boolean preIndexExperiment) {
+//        super(id, type);
+//
+//        fTraces = traces;
+//        fEpoch = epoch;
+//        fIndexPageSize = indexPageSize;
+//        fTimeRange = TmfTimeRange.NULL_RANGE;
+//
+//        if (preIndexExperiment) {
+//            indexExperiment(true, 0, TmfTimeRange.ETERNITY);
+//            updateTimeRange();
+//        }
+//    }
+//
+//    protected TmfExperiment(final String id, final Class<T> type) {
+//        super(id, type);
+//    }
+//
+//    /**
+//     * @param type
+//     * @param id
+//     * @param traces
+//     */
+//    public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) {
+//        this(type, id, traces, TmfTimestamp.ZERO, DEFAULT_INDEX_PAGE_SIZE);
+//    }
+//
+//    /**
+//     * @param type
+//     * @param id
+//     * @param traces
+//     * @param indexPageSize
+//     */
+//    public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces, final int indexPageSize) {
+//        this(type, id, traces, TmfTimestamp.ZERO, indexPageSize);
+//    }
+//
+//    /**
+//     * Clears the experiment
+//     */
+//    @Override
+//    @SuppressWarnings("rawtypes")
+//    public synchronized void dispose() {
+//
+//        final TmfExperimentDisposedSignal<T> signal = new TmfExperimentDisposedSignal<T>(this, this);
+//        broadcast(signal);
+//        if (fCurrentExperiment == this)
+//            fCurrentExperiment = null;
+//
+//        if (fTraces != null) {
+//            for (final ITmfTrace trace : fTraces)
+//                trace.dispose();
+//            fTraces = null;
+//        }
+//        if (fCheckpoints != null)
+//            fCheckpoints.clear();
+//        super.dispose();
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // ITmfTrace
+//    // ------------------------------------------------------------------------
+//
+//    @Override
+//    public Class<T> getEventType() {
+//        return fType;
+//    }
+//
+//    @Override
+//    public long getNbEvents() {
+//        return fNbEvents;
+//    }
+//
+//    @Override
+//    public int getCacheSize() {
+//        return fIndexPageSize;
+//    }
+//
+//    @Override
+//    public TmfTimeRange getTimeRange() {
+//        return fTimeRange;
+//    }
+//
+//    @Override
+//    public ITmfTimestamp getStartTime() {
+//        return fTimeRange.getStartTime();
+//    }
+//
+//    @Override
+//    public ITmfTimestamp getEndTime() {
+//        return fTimeRange.getEndTime();
+//    }
+//
+//    public Vector<TmfCheckpoint> getCheckpoints() {
+//        return fCheckpoints;
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // Accessors
+//    // ------------------------------------------------------------------------
+//
+//    public static void setCurrentExperiment(final TmfExperiment<?> experiment) {
+//        if (fCurrentExperiment != null && fCurrentExperiment != experiment)
+//            fCurrentExperiment.dispose();
+//        fCurrentExperiment = experiment;
+//    }
+//
+//    public static TmfExperiment<?> getCurrentExperiment() {
+//        return fCurrentExperiment;
+//    }
+//
+//    public ITmfTimestamp getEpoch() {
+//        return fEpoch;
+//    }
+//
+//    public ITmfTrace<T>[] 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
+//     */
+//    public ITmfTimestamp getTimestamp(final int index) {
+//        final TmfExperimentContext context = seekEvent(index);
+//        final ITmfEvent event = readNextEvent(context);
+//        return (event != null) ? event.getTimestamp() : null;
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // Operators
+//    // ------------------------------------------------------------------------
+//
+//    /**
+//     * Update the global time range
+//     */
+//    protected void updateTimeRange() {
+//        ITmfTimestamp startTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getStartTime() : TmfTimestamp.BIG_CRUNCH;
+//        ITmfTimestamp endTime = fTimeRange != TmfTimeRange.NULL_RANGE ? fTimeRange.getEndTime() : TmfTimestamp.BIG_BANG;
+//
+//        for (final ITmfTrace<T> trace : fTraces) {
+//            final ITmfTimestamp traceStartTime = trace.getStartTime();
+//            if (traceStartTime.compareTo(startTime, true) < 0)
+//                startTime = traceStartTime;
+//            final ITmfTimestamp traceEndTime = trace.getEndTime();
+//            if (traceEndTime.compareTo(endTime, true) > 0)
+//                endTime = traceEndTime;
+//        }
+//        fTimeRange = new TmfTimeRange(startTime, endTime);
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // TmfProvider
+//    // ------------------------------------------------------------------------
+//
+//    @Override
+//    public ITmfContext armRequest(final ITmfDataRequest<T> request) {
+//        //      Tracer.trace("Ctx: Arming request - start");
+//        ITmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ? ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
+//        if (TmfTimestamp.BIG_BANG.equals(timestamp) || request.getIndex() > 0)
+//            timestamp = null; // use request index
+//        TmfExperimentContext context = null;
+//        if (timestamp != null) {
+//            // seek by timestamp
+//            context = seekEvent(timestamp);
+//            ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank());
+//        } else // Seek by rank
+//            if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex())
+//                // We are already at the right context -> no need to seek
+//                context = fExperimentContext;
+//            else
+//                context = seekEvent(request.getIndex());
+//        // Tracer.trace("Ctx: Arming request - done");
+//        return context;
+//    }
+//
+//    @Override
+//    @SuppressWarnings("unchecked")
+//    public T getNext(final ITmfContext context) {
+//        if (context instanceof TmfExperimentContext)
+//            return (T) readNextEvent(context);
+//        return null;
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // ITmfTrace trace positioning
+//    // ------------------------------------------------------------------------
+//
+//    // Returns a brand new context based on the location provided
+//    // and initializes the event queues
+//    @Override
+//    public synchronized TmfExperimentContext seekEvent(final ITmfLocation<?> location) {
+//        // Validate the location
+//        if (location != null && !(location instanceof TmfExperimentLocation))
+//            return null; // Throw an exception?
+//
+//        if (fTraces == null)
+//            return null;
+//
+//        // Instantiate the location
+//        final TmfExperimentLocation expLocation = (location == null) ? new TmfExperimentLocation(new TmfLocationArray(
+//                new ITmfLocation<?>[fTraces.length]), new long[fTraces.length]) : (TmfExperimentLocation) location.clone();
+//
+//        // Create and populate the context's traces contexts
+//        final TmfExperimentContext context = new TmfExperimentContext(fTraces, new ITmfContext[fTraces.length]);
+//        // Tracer.trace("Ctx: SeekLocation - start");
+//
+//        long rank = 0;
+//        for (int i = 0; i < fTraces.length; i++) {
+//            // Get the relevant trace attributes
+//            final ITmfLocation<?> traceLocation = expLocation.getLocation().locations[i];
+//            final long traceRank = expLocation.getRanks()[i];
+//
+//            // Set the corresponding sub-context
+//            context.getContexts()[i] = fTraces[i].seekEvent(traceLocation);
+//            context.getContexts()[i].setRank(traceRank);
+//            rank += traceRank;
+//
+//            // Set the trace location and read the corresponding event
+//            /*
+//             * The (TmfContext) cast should be safe since we created 'context'
+//             * ourselves higher up.
+//             */
+//            expLocation.getLocation().locations[i] = context.getContexts()[i].getLocation().clone();
+//            context.getEvents()[i] = fTraces[i].readNextEvent(context.getContexts()[i]);
+//        }
+//
+//        // Tracer.trace("Ctx: SeekLocation - done");
+//
+//        // Finalize context
+//        context.setLocation(expLocation);
+//        context.setLastTrace(TmfExperimentContext.NO_TRACE);
+//        context.setRank(rank);
+//
+//        fExperimentContext = context;
+//
+//        return context;
+//    }
+//
+//    /* (non-Javadoc)
+//     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
+//     */
+//    @Override
+//    public synchronized TmfExperimentContext seekEvent(ITmfTimestamp timestamp) {
+//
+//        //      Tracer.trace("Ctx: seekEvent(TS) - start");
+//
+//        if (timestamp == null)
+//            timestamp = TmfTimestamp.BIG_BANG;
+//
+//        // First, find the right checkpoint
+//        int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
+//
+//        // In the very likely case that the checkpoint was not found, bsearch
+//        // returns its negated would-be location (not an offset...). From that
+//        // index, we can then position the stream and get the event.
+//        if (index < 0)
+//            index = Math.max(0, -(index + 2));
+//
+//        // Position the experiment at the checkpoint
+//        ITmfLocation<?> location;
+//        synchronized (fCheckpoints) {
+//            if (fCheckpoints.size() > 0) {
+//                if (index >= fCheckpoints.size())
+//                    index = fCheckpoints.size() - 1;
+//                location = fCheckpoints.elementAt(index).getLocation();
+//            } else
+//                location = null;
+//        }
+//
+//        final TmfExperimentContext context = seekEvent(location);
+//        context.setRank((long) index * fIndexPageSize);
+//
+//        // And locate the event
+//        ITmfEvent event = parseEvent(context);
+//        while ((event != null) && (event.getTimestamp().compareTo(timestamp, false) < 0)) {
+//            readNextEvent(context);
+//            event = parseEvent(context);
+//        }
+//
+//        if (event == null) {
+//            context.setLocation(null);
+//            context.setRank(ITmfContext.UNKNOWN_RANK);
+//        }
+//
+//        return context;
+//    }
+//
+//    /* (non-Javadoc)
+//     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
+//     */
+//    @Override
+//    public synchronized TmfExperimentContext seekEvent(final long rank) {
+//
+//        //      Tracer.trace("Ctx: seekEvent(rank) - start");
+//
+//        // Position the stream at the previous checkpoint
+//        int index = (int) rank / fIndexPageSize;
+//        ITmfLocation<?> location;
+//        synchronized (fCheckpoints) {
+//            if (fCheckpoints.size() == 0)
+//                location = null;
+//            else {
+//                if (index >= fCheckpoints.size())
+//                    index = fCheckpoints.size() - 1;
+//                location = fCheckpoints.elementAt(index).getLocation();
+//            }
+//        }
+//
+//        final TmfExperimentContext context = seekEvent(location);
+//        context.setRank((long) index * fIndexPageSize);
+//
+//        // And locate the event
+//        ITmfEvent event = parseEvent(context);
+//        long pos = context.getRank();
+//        while ((event != null) && (pos++ < rank)) {
+//            readNextEvent(context);
+//            event = parseEvent(context);
+//        }
+//
+//        if (event == null) {
+//            context.setLocation(null);
+//            context.setRank(ITmfContext.UNKNOWN_RANK);
+//        }
+//
+//        return context;
+//    }
+//
+//    @Override
+//    public TmfContext seekEvent(final double ratio) {
+//        final TmfContext context = seekEvent((long) (ratio * getNbEvents()));
+//        return context;
+//    }
+//
+//    @Override
+//    public double getLocationRatio(final ITmfLocation<?> location) {
+//        if (location instanceof TmfExperimentLocation)
+//            return (double) seekEvent(location).getRank() / getNbEvents();
+//        return 0;
+//    }
+//
+//    @Override
+//    public ITmfLocation<?> getCurrentLocation() {
+//        if (fExperimentContext != null)
+//            return fExperimentContext.getLocation();
+//        return null;
+//    }
+//
+//    //  private void dumpContext(TmfExperimentContext context, boolean isBefore) {
+//    //      TmfContext context0 = context.getContexts()[0];
+//    //      TmfEvent   event0   = context.getEvents()[0];
+//    //      TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
+//    //      long       rank0    = context.getRank();
+//    //      int        trace    = context.getLastTrace();
+//    //
+//    //      StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
+//    //
+//    //      result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
+//    //      result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
+//    //      result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
+//    //      result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
+//    //      Tracer.trace(result.toString());
+//    //  }
+//
+//    /**
+//     * Scan the next events from all traces and return the next one in
+//     * chronological order.
+//     * 
+//     * @param context the trace context
+//     * @return the next event
+//     */
+//    @Override
+//    public synchronized ITmfEvent readNextEvent(final ITmfContext context) {
+//
+//        // Validate the context
+//        if (!(context instanceof TmfExperimentContext))
+//            return null; // Throw an exception?
+//
+//        if (!context.equals(fExperimentContext))
+//            // Tracer.trace("Ctx: Restoring context");
+//            fExperimentContext = seekEvent(context.getLocation());
+//
+//        final TmfExperimentContext expContext = (TmfExperimentContext) context;
+//
+//        //      dumpContext(expContext, true);
+//
+//        // If an event was consumed previously, get the next one from that trace
+//        final int lastTrace = expContext.getLastTrace();
+//        if (lastTrace != TmfExperimentContext.NO_TRACE) {
+//            final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+//            expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
+//            expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+//        }
+//
+//        // Scan the candidate events and identify the "next" trace to read from
+//        final ITmfEvent eventArray[] = expContext.getEvents();
+//        if (eventArray == null)
+//            return null;
+//        int trace = TmfExperimentContext.NO_TRACE;
+//        ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
+//        if (eventArray.length == 1) {
+//            if (eventArray[0] != null) {
+//                timestamp = eventArray[0].getTimestamp();
+//                trace = 0;
+//            }
+//        } else
+//            for (int i = 0; i < eventArray.length; i++) {
+//                final ITmfEvent event = eventArray[i];
+//                if (event != null && event.getTimestamp() != null) {
+//                    final ITmfTimestamp otherTS = event.getTimestamp();
+//                    if (otherTS.compareTo(timestamp, true) < 0) {
+//                        trace = i;
+//                        timestamp = otherTS;
+//                    }
+//                }
+//            }
+//        // Update the experiment context and set the "next" event
+//        ITmfEvent event = null;
+//        if (trace != TmfExperimentContext.NO_TRACE) {
+//            updateIndex(expContext, timestamp);
+//
+//            final ITmfContext traceContext = expContext.getContexts()[trace];
+//            final TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
+//            //          expLocation.getLocation()[trace] = traceContext.getLocation().clone();
+//            expLocation.getLocation().locations[trace] = traceContext.getLocation().clone();
+//
+//            //          updateIndex(expContext, timestamp);
+//
+//            expLocation.getRanks()[trace] = traceContext.getRank();
+//            expContext.setLastTrace(trace);
+//            expContext.increaseRank();
+//            event = expContext.getEvents()[trace];
+//            fExperimentContext = expContext;
+//        }
+//
+//        //      if (event != null) {
+//        //          Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
+//        //          dumpContext(expContext, false);
+//        //          Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
+//        //      }
+//
+//        return event;
+//    }
+//
+//    public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
+//        // Build the index as we go along
+//        final long rank = context.getRank();
+//        if (context.hasValidRank() && (rank % fIndexPageSize) == 0) {
+//            // Determine the table position
+//            final long position = rank / fIndexPageSize;
+//            // Add new entry at proper location (if empty)
+//            if (fCheckpoints.size() == position) {
+//                final ITmfLocation<?> location = context.getLocation().clone();
+//                fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
+//                //                System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "
+//                //                        + location.toString());
+//            }
+//        }
+//    }
+//
+//    /* (non-Javadoc)
+//     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
+//     */
+////    @Override
+//    public ITmfEvent parseEvent(final ITmfContext context) {
+//
+//        // Validate the context
+//        if (!(context instanceof TmfExperimentContext))
+//            return null; // Throw an exception?
+//
+//        if (!context.equals(fExperimentContext))
+//            // Tracer.trace("Ctx: Restoring context");
+//            seekEvent(context.getLocation());
+//
+//        final TmfExperimentContext expContext = (TmfExperimentContext) context;
+//
+//        // If an event was consumed previously, get the next one from that trace
+//        final int lastTrace = expContext.getLastTrace();
+//        if (lastTrace != TmfExperimentContext.NO_TRACE) {
+//            final ITmfContext traceContext = expContext.getContexts()[lastTrace];
+//            expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].readNextEvent(traceContext);
+//            expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
+//            fExperimentContext = (TmfExperimentContext) context;
+//        }
+//
+//        // 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 < expContext.getTraces().length; i++) {
+//            final ITmfEvent event = expContext.getEvents()[i];
+//            if (event != null && event.getTimestamp() != null) {
+//                final ITmfTimestamp otherTS = event.getTimestamp();
+//                if (otherTS.compareTo(timestamp, true) < 0) {
+//                    trace = i;
+//                    timestamp = otherTS;
+//                }
+//            }
+//        }
+//
+//        ITmfEvent event = null;
+//        if (trace != TmfExperimentContext.NO_TRACE)
+//            event = expContext.getEvents()[trace];
+//
+//        return event;
+//    }
+//
+//    /* (non-Javadoc)
+//     * @see java.lang.Object#toString()
+//     */
+//    @Override
+//    @SuppressWarnings("nls")
+//    public String toString() {
+//        return "[TmfExperiment (" + getName() + ")]";
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // Indexing
+//    // ------------------------------------------------------------------------
+//
+//    private synchronized void initializeStreamingMonitor() {
+//        if (fInitialized)
+//            return;
+//        fInitialized = true;
+//
+//        if (getStreamingInterval() == 0) {
+//            final TmfContext context = seekEvent(0);
+//            final ITmfEvent event = getNext(context);
+//            if (event == null)
+//                return;
+//            final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH);
+//            final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(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 TmfTimeRange timeRange = null;
+//
+//            @Override
+//            public void run() {
+//                while (!fExecutor.isShutdown()) {
+//                    if (!isIndexingBusy()) {
+//                        ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
+//                        ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
+//                        for (final ITmfTrace<T> 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 && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0)
+//                            timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
+//                        else
+//                            timeRange = null;
+//                        safeTimestamp = endTimestamp;
+//                        if (timeRange != null) {
+//                            final TmfExperimentRangeUpdatedSignal signal =
+//                                    new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange);
+//                            broadcast(signal);
+//                        }
+//                    }
+//                    try {
+//                        Thread.sleep(getStreamingInterval());
+//                    } catch (final InterruptedException e) {
+//                        e.printStackTrace();
+//                    }
+//                }
+//            }
+//        };
+//        thread.start();
+//    }
+//
+//    /*
+//     * (non-Javadoc)
+//     * 
+//     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval()
+//     */
+//    @Override
+//    public long getStreamingInterval() {
+//        long interval = 0;
+//        for (final ITmfTrace<T> trace : fTraces)
+//            interval = Math.max(interval, trace.getStreamingInterval());
+//        return interval;
+//    }
+//
+//    /*
+//     * The experiment holds the globally ordered events of its set of traces. It
+//     * is expected to provide access to each individual event by index i.e. it
+//     * must be possible to request the Nth event of the experiment.
+//     * 
+//     * The purpose of the index is to keep the information needed to rapidly
+//     * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
+//     * event).
+//     */
+//
+//    // The index page size
+//    private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
+//    protected int fIndexPageSize;
+//    protected boolean fIndexing = false;
+//    protected TmfTimeRange fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+//
+//    private Integer fEndSynchReference;
+//
+//    //  private static BufferedWriter fEventLog = null;
+//    //  private static BufferedWriter openLogFile(String filename) {
+//    //      BufferedWriter outfile = null;
+//    //      try {
+//    //          outfile = new BufferedWriter(new FileWriter(filename));
+//    //      } catch (IOException e) {
+//    //          e.printStackTrace();
+//    //      }
+//    //      return outfile;
+//    //  }
+//
+//    protected boolean isIndexingBusy() {
+//        synchronized (fCheckpoints) {
+//            return fIndexing;
+//        }
+//    }
+//
+//    @SuppressWarnings("unchecked")
+//    private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
+//
+//        synchronized (fCheckpoints) {
+//            if (fIndexing)
+//                return;
+//            fIndexing = true;
+//        }
+//
+//        final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
+//
+//            @Override
+//            protected IStatus run(final IProgressMonitor monitor) {
+//                while (!monitor.isCanceled())
+//                    try {
+//                        Thread.sleep(100);
+//                    } catch (final InterruptedException e) {
+//                        return Status.OK_STATUS;
+//                    }
+//                monitor.done();
+//                return Status.OK_STATUS;
+//            }
+//        };
+//        job.schedule();
+//
+//        //      fEventLog = openLogFile("TraceEvent.log");
+//        //        System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
+//
+//        final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, timeRange, index,
+//                TmfDataRequest.ALL_DATA,
+//                fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) { // PATA
+//            // FOREGROUND
+//
+//            //            long indexingStart = System.nanoTime();
+//
+//            ITmfTimestamp startTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getStartTime();
+//            ITmfTimestamp lastTime = (fTimeRange == TmfTimeRange.NULL_RANGE) ? null : fTimeRange.getEndTime();
+//            long initialNbEvents = fNbEvents;
+//
+//            @Override
+//            public void handleStarted() {
+//                super.handleStarted();
+//            }
+//
+//            @Override
+//            public void handleData(final ITmfEvent event) {
+//                super.handleData(event);
+//                if (event != null) {
+//                    final ITmfTimestamp ts = event.getTimestamp();
+//                    if (startTime == null)
+//                        startTime = ts.clone();
+//                    lastTime = ts.clone();
+//                }
+//                if ((getNbRead() % fIndexPageSize) == 1 && getNbRead() != 1)
+//                    updateExperiment();
+//            }
+//
+//            @Override
+//            public void handleSuccess() {
+//                //                long indexingEnd = System.nanoTime();
+//
+//                // if the end time is a real value then it is the streaming safe
+//                // time stamp
+//                // set the last time to the safe time stamp to prevent
+//                // unnecessary indexing requests
+//                if (getRange().getEndTime() != TmfTimestamp.BIG_CRUNCH)
+//                    lastTime = getRange().getEndTime();
+//                updateExperiment();
+//                //                System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
+//
+//                //                long average = (indexingEnd - indexingStart) / fNbEvents;
+//                //                System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
+//                //                        + (indexingEnd * 1.0 - indexingStart) / 1000000000);
+//                //                System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
+//                //                        + (average % 1000) + " us/evt)");
+//                super.handleSuccess();
+//            }
+//
+//            @Override
+//            public void handleCompleted() {
+//                job.cancel();
+//                super.handleCompleted();
+//                synchronized (fCheckpoints) {
+//                    fIndexing = false;
+//                    if (fIndexingPendingRange != TmfTimeRange.NULL_RANGE) {
+//                        indexExperiment(false, (int) fNbEvents, fIndexingPendingRange);
+//                        fIndexingPendingRange = TmfTimeRange.NULL_RANGE;
+//                    }
+//                }
+//            }
+//
+//            private void updateExperiment() {
+//                final int nbRead = getNbRead();
+//                if (startTime != null)
+//                    fTimeRange = new TmfTimeRange(startTime, lastTime.clone());
+//                if (nbRead != 0) {
+//                    //                  updateTimeRange();
+//                    //                  updateNbEvents();
+//                    fNbEvents = initialNbEvents + nbRead;
+//                    notifyListeners();
+//                }
+//            }
+//        };
+//
+//        sendRequest((ITmfDataRequest<T>) request);
+//        if (waitForCompletion)
+//            try {
+//                request.waitForCompletion();
+//            } catch (final InterruptedException e) {
+//                e.printStackTrace();
+//            }
+//    }
+//
+//    protected void notifyListeners() {
+//        broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
+//        // broadcast(new TmfExperimentRangeUpdatedSignal(this, this,
+//        // fTimeRange)); // , null));
+//    }
+//
+//    // ------------------------------------------------------------------------
+//    // Signal handlers
+//    // ------------------------------------------------------------------------
+//
+//    @TmfSignalHandler
+//    public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) {
+//        final TmfExperiment<?> experiment = signal.getExperiment();
+//        if (experiment == this) {
+//            setCurrentExperiment(experiment);
+//            fEndSynchReference = Integer.valueOf(signal.getReference());
+//        }
+//    }
+//
+//    @TmfSignalHandler
+//    public void endSync(final TmfEndSynchSignal signal) {
+//        if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) {
+//            fEndSynchReference = null;
+//            initializeStreamingMonitor();
+//        }
+//    }
+//
+//    @TmfSignalHandler
+//    public void experimentUpdated(final TmfExperimentUpdatedSignal signal) {
+//    }
+//
+//    @TmfSignalHandler
+//    public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) {
+//        if (signal.getExperiment() == this)
+//            indexExperiment(false, (int) fNbEvents, signal.getRange());
+//    }
+//
+//    @TmfSignalHandler
+//    public void traceUpdated(final TmfTraceUpdatedSignal signal) {
+//        for (final ITmfTrace<T> trace : fTraces)
+//            if (trace == signal.getTrace()) {
+//                synchronized (fCheckpoints) {
+//                    if (fIndexing) {
+//                        if (fIndexingPendingRange == TmfTimeRange.NULL_RANGE)
+//                            fIndexingPendingRange = signal.getRange();
+//                        else {
+//                            ITmfTimestamp startTime = fIndexingPendingRange.getStartTime();
+//                            ITmfTimestamp endTime = fIndexingPendingRange.getEndTime();
+//                            if (signal.getRange().getStartTime().compareTo(startTime) < 0)
+//                                startTime = signal.getRange().getStartTime();
+//                            if (signal.getRange().getEndTime().compareTo(endTime) > 0)
+//                                endTime = signal.getRange().getEndTime();
+//                            fIndexingPendingRange = new TmfTimeRange(startTime, endTime);
+//                        }
+//                        return;
+//                    }
+//                }
+//                indexExperiment(false, (int) fNbEvents, signal.getRange());
+//                return;
+//            }
+//    }
+//
+//    @Override
+//    public String getPath() {
+//        // TODO Auto-generated method stub
+//        return null;
+//    }
+//
+//    /**
+//     * Set the file to be used for bookmarks on this experiment
+//     * 
+//     * @param file the bookmarks file
+//     */
+//    public void setBookmarksFile(final IFile file) {
+//        fBookmarksFile = file;
+//    }
+//
+//    /**
+//     * Get the file used for bookmarks on this experiment
+//     * 
+//     * @return the bookmarks file or null if none is set
+//     */
+//    public IFile getBookmarksFile() {
+//        return fBookmarksFile;
+//    }
+//
+//    /*
+//     * (non-Javadoc)
+//     * 
+//     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+//     */
+//    @Override
+//    public IResource getResource() {
+//        return fResource;
+//    }
+//}
index 49b2bf9e81f31f770af8bdef137660774b58ba20..6df55ddab814e8144e657feccbee8ae6d8c2f2a0 100644 (file)
@@ -129,7 +129,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
         fTraceIndex.clear();
 
         // Build a background request for all the trace data. The index is
-        // updated as we go by getNextEvent().
+        // updated as we go by readNextEvent().
         final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY,
                 TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
         {
@@ -265,7 +265,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
      * @return the corresponding context
      */
     private ITmfContext seekCheckpoint(final int checkpoint) {
-        ITmfLocation<?> location;
+        ITmfLocation<?> location = null;
         int index = checkpoint;
         synchronized (fTraceIndex) {
             if (!fTraceIndex.isEmpty()) {
@@ -273,8 +273,6 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
                     index = fTraceIndex.size() - 1;
                 }
                 location = fTraceIndex.get(index).getLocation();
-            } else {
-                location = null;
             }
         }
         final ITmfContext context = fTrace.seekEvent(location);
This page took 0.054081 seconds and 5 git commands to generate.