From 2065894741f9e2ad30265d0ffe7ccf00fe40e67d Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Thu, 19 Apr 2012 18:14:00 -0400 Subject: [PATCH] Refactor TmfTrace and dependencies - introduce ITmfTraceIndexer --- .../lttng/core/trace/LTTngTextTrace.java | 2 +- .../internal/lttng/core/trace/LTTngTrace.java | 10 +- .../internal/lttng/stubs/LTTngTraceStub.java | 7 +- .../tests/experiment/TmfExperimentTest.java | 22 +- .../TmfMultiTraceExperimentTest.java | 24 +- .../tmf/core/tests/trace/TmfTraceTest.java | 735 +++++++++++------- .../stubs/component/TmfDataProviderStub.java | 2 +- .../stubs/component/TmfEventProviderStub.java | 2 +- .../tmf/tests/stubs/trace/TmfTraceStub.java | 79 +- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 2 +- .../tmf/core/experiment/TmfExperiment.java | 2 +- .../linuxtools/tmf/core/trace/ITmfTrace.java | 10 +- .../tmf/core/trace/ITmfTraceIndexer.java | 60 ++ .../linuxtools/tmf/core/trace/TmfTrace.java | 408 +++++----- .../tmf/core/trace/TmfTraceIndexer.java | 265 +++++++ .../META-INF/MANIFEST.MF | 1 + .../views/uml2sd/impl/Uml2SDTestFacility.java | 102 +-- .../handlers/OpenExperimentHandler.java | 2 +- .../ui/project/handlers/OpenTraceHandler.java | 2 +- .../tmf/ui/editors/EventsViewEditor.java | 6 +- .../tmf/ui/editors/TmfEventsEditor.java | 8 +- .../tmf/ui/viewers/events/TmfEventsTable.java | 6 +- .../tmf/ui/views/events/TmfEventsView.java | 2 +- .../ui/views/histogram/HistogramRequest.java | 2 +- .../ui/views/timechart/TimeChartEvent.java | 2 +- .../tmf/ui/views/timechart/TimeChartView.java | 4 +- 26 files changed, 1181 insertions(+), 586 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceIndexer.java diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java index 12ee63d012..13166d72dc 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java @@ -75,7 +75,7 @@ public class LTTngTextTrace extends TmfTrace { if ( positionToFirstEvent() == false ) throw new IOException("Fail to position to the beginning of the trace"); //$NON-NLS-1$ else { - fIndexPageSize = 1000; + fCacheSize = 1000; // Skip indexing if asked // if ( skipIndexing == true ) { diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java index 83d48c5589..d14f7c2b21 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java @@ -297,8 +297,8 @@ public class LTTngTrace extends TmfTrace { // super(resource, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE, false); super(resource, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE); initialize(resource, path, LttngEvent.class); - if (!bypassIndexing) - indexTrace(false); +// if (!bypassIndexing) +// indexTrace(false); this.traceLibPath = traceLibPath; } @@ -527,7 +527,7 @@ public class LTTngTrace extends TmfTrace { System.out.println("seekEvent(rank) rank -> " + rank); //$NON-NLS-1$ ITmfTimestamp timestamp = null; - long index = rank / getIndexPageSize(); + long index = rank / getCacheSize(); // Get the timestamp of the closest check point to the given position if (fCheckpoints.size() > 0) { @@ -539,11 +539,11 @@ public class LTTngTrace extends TmfTrace { // Seek to the found time final TmfContext tmpContext = seekEvent(timestamp); - tmpContext.setRank((index + 1) * fIndexPageSize); + tmpContext.setRank((index + 1) * fCacheSize); previousLocation = (LttngLocation) tmpContext.getLocation(); // Ajust the index of the event we found at this check point position - Long currentPosition = index * getIndexPageSize(); + Long currentPosition = index * getCacheSize(); Long lastTimeValueRead = 0L; diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java index be33a23094..e88fa9d96f 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java @@ -54,7 +54,7 @@ public class LTTngTraceStub extends TmfTrace { * @throws FileNotFoundException */ public LTTngTraceStub(final IResource resource) throws FileNotFoundException { - this(resource, DEFAULT_INDEX_PAGE_SIZE); + this(resource, DEFAULT_TRACE_CACHE_SIZE); } /** @@ -68,7 +68,10 @@ public class LTTngTraceStub extends TmfTrace { super(resource, LttngEvent.class, resource.getName(), cacheSize); fTrace = new RandomAccessFile(resource.getName(), "r"); fParser = new LTTngEventParserStub(); - indexTrace(true); + } + + public void indexTrace() { + fIndexer.buildIndex(true); } // ======================================================================== diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java index 7a3e0dbfcd..f80d2c704e 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfExperimentTest.java @@ -65,7 +65,7 @@ public class TmfExperimentTest extends TestCase { try { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); final File test = new File(FileLocator.toFileURL(location).toURI()); - final TmfTraceStub trace = new TmfTraceStub(test.getPath(), true); + final TmfTraceStub trace = new TmfTraceStub(test.getPath(), 0, true); fTraces[0] = trace; } catch (final URISyntaxException e) { e.printStackTrace(); @@ -78,8 +78,9 @@ public class TmfExperimentTest extends TestCase { @SuppressWarnings("unchecked") private synchronized static void setupExperiment() { - if (fExperiment == null) + if (fExperiment == null) { fExperiment = new TmfExperiment(TmfEvent.class, EXPERIMENT, (ITmfTrace[]) fTraces, TmfTimestamp.ZERO, 1000, true); + } } public TmfExperimentTest(final String name) throws Exception { @@ -123,7 +124,7 @@ public class TmfExperimentTest extends TestCase { public void testValidateCheckpoints() throws Exception { final Vector checkpoints = fExperiment.getCheckpoints(); - final int pageSize = fExperiment.getIndexPageSize(); + final int pageSize = fExperiment.getCacheSize(); assertTrue("Checkpoints exist", checkpoints != null); // Validate that each checkpoint points to the right event @@ -579,8 +580,9 @@ public class TmfExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbEvents; i++) + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } public void testProcessRequestForNbEvents2() throws Exception { @@ -606,8 +608,9 @@ public class TmfExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbEvents; i++) + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } public void testProcessRequestForAllEvents() throws Exception { @@ -634,8 +637,9 @@ public class TmfExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbExpectedEvents; i++) + for (int i = 0; i < nbExpectedEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } // ------------------------------------------------------------------------ @@ -655,13 +659,15 @@ public class TmfExperimentTest extends TestCase { public void handleData(final TmfEvent event) { super.handleData(event); requestedEvents.add(event); - if (++nbRead == blockSize) + if (++nbRead == blockSize) { cancel(); + } } @Override public void handleCancel() { - if (requestedEvents.size() < blockSize) + if (requestedEvents.size() < blockSize) { System.out.println("aie"); + } } }; fExperiment.sendRequest(request); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java index f665a4fdd0..a51241131b 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/experiment/TmfMultiTraceExperimentTest.java @@ -66,11 +66,11 @@ public class TmfMultiTraceExperimentTest extends TestCase { 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(), true); + 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(), true); + final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true); fTraces[1] = trace2; } catch (final URISyntaxException e) { e.printStackTrace(); @@ -84,8 +84,9 @@ public class TmfMultiTraceExperimentTest extends TestCase { @SuppressWarnings("unchecked") private synchronized static void setupExperiment() { synchronized (TmfMultiTraceExperimentTest.class) { - if (fExperiment == null) + if (fExperiment == null) { fExperiment = new TmfExperiment(TmfEvent.class, EXPERIMENT, (ITmfTrace[]) fTraces, TmfTimestamp.ZERO, BLOCK_SIZE, true); + } } } @@ -127,7 +128,7 @@ public class TmfMultiTraceExperimentTest extends TestCase { public void testValidateCheckpoints() throws Exception { final Vector checkpoints = fExperiment.getCheckpoints(); - final int pageSize = fExperiment.getIndexPageSize(); + final int pageSize = fExperiment.getCacheSize(); assertTrue("Checkpoints exist", checkpoints != null); // Validate that each checkpoint points to the right event @@ -583,8 +584,9 @@ public class TmfMultiTraceExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbEvents; i++) + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } public void testProcessRequestForNbEvents2() throws Exception { @@ -610,8 +612,9 @@ public class TmfMultiTraceExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbEvents; i++) + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } public void testProcessRequestForAllEvents() throws Exception { @@ -638,8 +641,9 @@ public class TmfMultiTraceExperimentTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < nbExpectedEvents; i++) + for (int i = 0; i < nbExpectedEvents; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } // ------------------------------------------------------------------------ @@ -659,13 +663,15 @@ public class TmfMultiTraceExperimentTest extends TestCase { public void handleData(final TmfEvent event) { super.handleData(event); requestedEvents.add(event); - if (++nbRead == blockSize) + if (++nbRead == blockSize) { cancel(); + } } @Override public void handleCancel() { - if (requestedEvents.size() < blockSize) + if (requestedEvents.size() < blockSize) { System.out.println("aie"); + } } }; fExperiment.sendRequest(request); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index 5a54ace863..d79f02d214 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson - * + * Copyright (c) 2009, 2010, 20112 Ericsson + * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adapted for TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; @@ -31,9 +32,9 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; -import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; +import org.eclipse.linuxtools.tmf.core.trace.TmfTraceIndexer; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; /** @@ -54,7 +55,7 @@ public class TmfTraceTest extends TestCase { private static final int NB_EVENTS = 10000; private static TmfTraceStub fTrace = null; - private static byte SCALE = (byte) -3; + private static int SCALE = -3; // ------------------------------------------------------------------------ // Housekeeping @@ -68,15 +69,6 @@ public class TmfTraceTest extends TestCase { protected void setUp() throws Exception { super.setUp(); fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); - // Dummy request to force the trace indexing - final TmfEventRequest request = new TmfEventRequest(TmfEvent.class) { - @Override - public void handleData(final TmfEvent event) { - super.handleData(event); - } - }; - fTrace.sendRequest(request); - request.waitForCompletion(); } @Override @@ -91,16 +83,18 @@ public class TmfTraceTest extends TestCase { // ------------------------------------------------------------------------ private TmfTraceStub setupTrace(final String path) { - if (fTrace == null) + if (fTrace == null) { try { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); final File test = new File(FileLocator.toFileURL(location).toURI()); - fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE, false); + fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE); + fTrace.indexTrace(); } catch (final URISyntaxException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } + } return fTrace; } @@ -108,58 +102,236 @@ public class TmfTraceTest extends TestCase { // Constructors // ------------------------------------------------------------------------ - public void testTmfTraceDefault() throws Exception { + public void testStandardConstructor() throws Exception { TmfTraceStub trace = null; File testfile = null; try { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); testfile = new File(FileLocator.toFileURL(location).toURI()); trace = new TmfTraceStub(testfile.toURI().getPath()); + trace.indexTrace(); } catch (final URISyntaxException e) { fail("URISyntaxException"); } catch (final IOException e) { fail("IOException"); } - assertTrue ("Open trace", trace != null); - assertEquals("getType", TmfEvent.class, trace.getType()); - assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); - assertEquals("getName", TEST_STREAM, trace.getName()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getIndexPageSize()); + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } - public void testTmfTraceDefaultCacheSize() throws Exception { + public void testStandardConstructorCacheSize() throws Exception { TmfTraceStub trace = null; File testfile = null; try { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); testfile = new File(FileLocator.toFileURL(location).toURI()); trace = new TmfTraceStub(testfile.toURI().getPath(), 0); + trace.indexTrace(); + } catch (final URISyntaxException e) { + fail("URISyntaxException"); + } catch (final IOException e) { + fail("IOException"); + } + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); + + try { + final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); + testfile = new File(FileLocator.toFileURL(location).toURI()); + trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE); + trace.indexTrace(); + } catch (final URISyntaxException e) { + fail("URISyntaxException"); + } catch (final IOException e) { + fail("IOException"); + } + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); + assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); + } + + public void testFullConstructor() throws Exception { + TmfTraceStub trace = null; + File testfile = null; + try { + final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); + testfile = new File(FileLocator.toFileURL(location).toURI()); + trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null); + trace.indexTrace(); + } catch (final URISyntaxException e) { + fail("URISyntaxException"); + } catch (final IOException e) { + fail("IOException"); + } + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); + assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void testCopyConstructor() throws Exception { + TmfTraceStub original = null; + TmfTraceStub trace = null; + File testfile = null; + try { + final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); + testfile = new File(FileLocator.toFileURL(location).toURI()); + original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfTraceIndexer(null)); + trace = new TmfTraceStub(original); + trace.indexTrace(); } catch (final URISyntaxException e) { fail("URISyntaxException"); } catch (final IOException e) { fail("IOException"); } - assertTrue ("Open trace", trace != null); - assertEquals("getType", TmfEvent.class, trace.getType()); - assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); - assertEquals("getName", TEST_STREAM, trace.getName()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getIndexPageSize()); + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); + assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); + + // Test the copy of a null trace + try { + new TmfTraceStub((TmfTraceStub) null); + fail("Missing exception"); + } catch (final IllegalArgumentException e) { + // test passed + } catch (final Exception e) { + fail("Unexpected exception"); + } } - public void testTmfTrace() throws Exception { - assertEquals("getType", TmfEvent.class, fTrace.getType()); - assertEquals("getName", TEST_STREAM, fTrace.getName()); - assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize()); + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ + + public void testDefaultTmfTraceStub() throws Exception { + assertFalse ("Open trace", fTrace == null); + assertEquals("getType", TmfEvent.class, fTrace.getType()); + assertNull ("getResource", fTrace.getResource()); + assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); + assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, fTrace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents()); + assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); + + String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() + + ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() + + ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() + + "]"; + assertEquals("toString", expected, fTrace.toString()); } - // public void testClone() throws Exception { - // TmfTraceStub trace = fTrace.clone(); - // assertEquals("getType", TmfEvent.class, trace.getType()); - // assertEquals("getPath", fTrace.getPath(), trace.getPath()); - // assertEquals("getName", TEST_STREAM, trace.getName()); - // assertEquals("getCacheSize", BLOCK_SIZE, trace.getIndexPageSize()); - // assertEquals("getTimeRange", fTrace.getTimeRange(), trace.getTimeRange()); - // } + // ------------------------------------------------------------------------ + // Trace initialization + // ------------------------------------------------------------------------ + + public void testInitTrace() throws Exception { + + // Instantiate an "empty" trace + final TmfTraceStub trace = new TmfTraceStub(); + + assertFalse ("Open trace", trace == null); + assertNull ("getType", trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", "", trace.getName()); + + assertEquals("getNbEvents", 0, trace.getNbEvents()); + assertEquals("getRange-start", Long.MAX_VALUE, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", Long.MAX_VALUE, trace.getStartTime().getValue()); + assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); + + // Validate + final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); + final File testfile = new File(FileLocator.toFileURL(location).toURI()); + assertTrue("validate", trace.validate(null, testfile.getPath())); + + // InitTrace and wait for indexing completion... + trace.initTrace(null, testfile.getPath(), TmfEvent.class); + int nbSecs = 0; + while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) { + Thread.sleep(1000); + nbSecs++; + } + if (trace.getNbEvents() < NB_EVENTS) { + fail("indexing"); + } + + assertFalse ("Open trace", trace == null); + assertEquals("getType", TmfEvent.class, trace.getType()); + assertNull ("getResource", trace.getResource()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); + assertEquals("getName", TEST_STREAM, trace.getName()); + + assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); + assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); + assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); + assertEquals("getStartTime", 1, trace.getStartTime().getValue()); + assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); + } // ------------------------------------------------------------------------ // Get/Set time range @@ -167,6 +339,7 @@ public class TmfTraceTest extends TestCase { public void testSetTimeRange() throws Exception { final TmfTraceStub trace = new TmfTraceStub(fTrace); + trace.indexTrace(); assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); @@ -184,6 +357,7 @@ public class TmfTraceTest extends TestCase { public void testSetStartTime() throws Exception { final TmfTraceStub trace = new TmfTraceStub(fTrace); + trace.indexTrace(); assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); @@ -201,6 +375,7 @@ public class TmfTraceTest extends TestCase { public void testSetEndTime() throws Exception { final TmfTraceStub trace = new TmfTraceStub(fTrace); + trace.indexTrace(); assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); @@ -217,240 +392,20 @@ public class TmfTraceTest extends TestCase { } // ------------------------------------------------------------------------ - // Verify checkpoints - // ------------------------------------------------------------------------ - - public void testTmfTraceIndexing() throws Exception { - assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize()); - assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents()); - assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); - assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); - assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); - assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); - - final Vector checkpoints = fTrace.getCheckpoints(); - final int pageSize = fTrace.getIndexPageSize(); - assertTrue("Checkpoints exist", checkpoints != null); - - // Validate that each checkpoint points to the right event - for (int i = 0; i < checkpoints.size(); i++) { - final TmfCheckpoint checkpoint = checkpoints.get(i); - final TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize); - final ITmfEvent event = fTrace.parseEvent(context); - assertTrue(context.getRank() == i * pageSize); - assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); - } - } - - // ------------------------------------------------------------------------ - // parseEvent - make sure parseEvent doesn't update the context - // ------------------------------------------------------------------------ - - public void testParseEvent() throws Exception { - - final int NB_READS = 20; - - // On lower bound, returns the first event (ts = 0) - final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); - TmfContext svContext = new TmfContext(context); - - ITmfEvent event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); - assertTrue("parseEvent", context.equals(svContext)); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); - assertTrue("parseEvent", context.equals(svContext)); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", 0, context.getRank()); - assertTrue("parseEvent", context.equals(svContext)); - - // Position the trace at event NB_READS - for (int i = 1; i < NB_READS; i++) { - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", i, event.getTimestamp().getValue()); - } - - svContext = new TmfContext(context); - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS -1 , context.getRank()); - assertTrue("parseEvent", context.equals(svContext)); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS - 1, context.getRank()); - assertTrue("parseEvent", context.equals(svContext)); - } - - // ------------------------------------------------------------------------ - // getNextEvent - updates the context - // ------------------------------------------------------------------------ - - public void testGetNextEvent() throws Exception { - - final int NB_READS = 20; - - // On lower bound, returns the first event (ts = 1) - final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); - - // Read NB_EVENTS - ITmfEvent event; - for (int i = 0; i < NB_READS; i++) { - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", i + 1, context.getRank()); - } - - // Make sure we stay positioned - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue()); - assertEquals("Event rank", NB_READS, context.getRank()); - } - - // ------------------------------------------------------------------------ - // seekLocation - // Note: seekLocation() does not reliably set the rank + // seekEvent on timestamp // ------------------------------------------------------------------------ - public void testSeekLocationOnCacheBoundary() throws Exception { + public void testSeekEventOnNullTimestamp() throws Exception { // Position trace at event rank 0 - TmfContext context = fTrace.seekLocation(null); - ITmfEvent event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + ITmfContext context = fTrace.seekEvent(null); assertEquals("Event rank", 0, context.getRank()); - context = fTrace.seekLocation(context.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event rank 1000 - ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event rank 4000 - tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - } - - public void testSeekLocationNotOnCacheBoundary() throws Exception { - - // Position trace at event rank 9 - ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); - TmfContext context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - ITmfEvent event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event rank 999 - tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event rank 1001 - tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event rank 4500 - tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - } - - public void testSeekLocationOutOfScope() throws Exception { - - // Position trace at beginning - ITmfContext tmpContext = fTrace.seekLocation(null); - ITmfContext context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - ITmfEvent event = fTrace.parseEvent(context); assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - // Position trace at event passed the end - tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); - context = fTrace.seekLocation(tmpContext.getLocation()); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.parseEvent(context); - assertEquals("Event timestamp", null, event); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); - - event = fTrace.getNextEvent(context); - assertEquals("Event timestamp", null, event); - assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); + assertEquals("Event rank", 0, context.getRank()); } - // ------------------------------------------------------------------------ - // seekEvent on timestamp - // ------------------------------------------------------------------------ - public void testSeekEventOnTimestampOnCacheBoundary() throws Exception { // Position trace at event rank 0 @@ -584,6 +539,17 @@ public class TmfTraceTest extends TestCase { // seekEvent on rank // ------------------------------------------------------------------------ + public void testSeekEventOnNegativeRank() throws Exception { + + // Position trace at event rank 0 + ITmfContext context = fTrace.seekEvent(-1); + assertEquals("Event rank", 0, context.getRank()); + + ITmfEvent event = fTrace.parseEvent(context); + assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + assertEquals("Event rank", 0, context.getRank()); + } + public void testSeekOnRankOnCacheBoundary() throws Exception { // On lower bound, returns the first event (ts = 1) @@ -701,6 +667,76 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", NB_EVENTS, context.getRank()); } + // ------------------------------------------------------------------------ + // parseEvent - make sure parseEvent doesn't update the context + // ------------------------------------------------------------------------ + + public void testParseEvent() throws Exception { + + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 0) + final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); + TmfContext svContext = new TmfContext(context); + + ITmfEvent event = fTrace.parseEvent(context); + assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + assertEquals("Event rank", 0, context.getRank()); + assertTrue("parseEvent", context.equals(svContext)); + + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + assertEquals("Event rank", 0, context.getRank()); + assertTrue("parseEvent", context.equals(svContext)); + + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); + assertEquals("Event rank", 0, context.getRank()); + assertTrue("parseEvent", context.equals(svContext)); + + // Position the trace at event NB_READS + for (int i = 1; i < NB_READS; i++) { + event = fTrace.getNextEvent(context); + assertEquals("Event timestamp", i, event.getTimestamp().getValue()); + } + + svContext = new TmfContext(context); + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", NB_READS -1 , context.getRank()); + assertTrue("parseEvent", context.equals(svContext)); + + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); + assertEquals("Event rank", NB_READS - 1, context.getRank()); + assertTrue("parseEvent", context.equals(svContext)); + } + + // ------------------------------------------------------------------------ + // getNextEvent - updates the context + // ------------------------------------------------------------------------ + + public void testGetNextEvent() throws Exception { + + final int NB_READS = 20; + + // On lower bound, returns the first event (ts = 1) + final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); + + // Read NB_EVENTS + ITmfEvent event; + for (int i = 0; i < NB_READS; i++) { + event = fTrace.getNextEvent(context); + assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", i + 1, context.getRank()); + } + + // Make sure we stay positioned + event = fTrace.parseEvent(context); + assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue()); + assertEquals("Event rank", NB_READS, context.getRank()); + } + // ------------------------------------------------------------------------ // processRequest // ------------------------------------------------------------------------ @@ -729,8 +765,9 @@ public class TmfTraceTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) + for (int i = 0; i < NB_EVENTS; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } @SuppressWarnings("unchecked") @@ -756,8 +793,9 @@ public class TmfTraceTest extends TestCase { // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) + for (int i = 0; i < NB_EVENTS; i++) { assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); + } } // ------------------------------------------------------------------------ @@ -775,8 +813,9 @@ public class TmfTraceTest extends TestCase { public void handleData(final TmfEvent event) { super.handleData(event); requestedEvents.add(event); - if (++nbRead == BLOCK_SIZE) + if (++nbRead == BLOCK_SIZE) { cancel(); + } } }; final ITmfDataProvider[] providers = (ITmfDataProvider[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); @@ -788,4 +827,166 @@ public class TmfTraceTest extends TestCase { assertTrue("isCancelled", request.isCancelled()); } + +// // ------------------------------------------------------------------------ +// // seekLocation +// // Note: seekLocation() does not reliably set the rank +// // ------------------------------------------------------------------------ +// +// public void testSeekLocationOnCacheBoundary() throws Exception { +// +// // Position trace at event rank 0 +// TmfContext context = fTrace.seekLocation(null); +// ITmfEvent event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); +// assertEquals("Event rank", 0, context.getRank()); +// +// context = fTrace.seekLocation(context.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event rank 1000 +// ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event rank 4000 +// tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// } +// +// public void testSeekLocationNotOnCacheBoundary() throws Exception { +// +// // Position trace at event rank 9 +// ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); +// TmfContext context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// ITmfEvent event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event rank 999 +// tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event rank 1001 +// tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event rank 4500 +// tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// } +// +// public void testSeekLocationOutOfScope() throws Exception { +// +// // Position trace at beginning +// ITmfContext tmpContext = fTrace.seekLocation(null); +// ITmfContext context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// ITmfEvent event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// // Position trace at event passed the end +// tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); +// context = fTrace.seekLocation(tmpContext.getLocation()); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.parseEvent(context); +// assertEquals("Event timestamp", null, event); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// +// event = fTrace.getNextEvent(context); +// assertEquals("Event timestamp", null, event); +// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); +// } + + // ------------------------------------------------------------------------ + // Verify checkpoints + // ------------------------------------------------------------------------ + + // public void testTmfTraceIndexing() throws Exception { + // assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize()); + // assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents()); + // assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); + // assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); + // assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); + // assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); + // + // final Vector checkpoints = fTrace.getCheckpoints(); + // final int pageSize = fTrace.getIndexPageSize(); + // assertTrue("Checkpoints exist", checkpoints != null); + // + // // Validate that each checkpoint points to the right event + // for (int i = 0; i < checkpoints.size(); i++) { + // final TmfCheckpoint checkpoint = checkpoints.get(i); + // final TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize); + // final ITmfEvent event = fTrace.parseEvent(context); + // assertTrue(context.getRank() == i * pageSize); + // assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); + // } + // } + } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java index a279396bc2..6df409a7ec 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java @@ -45,7 +45,7 @@ public class TmfDataProviderStub extends TmfDataProvider { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); try { final File test = new File(FileLocator.toFileURL(location).toURI()); - fTrace = new TmfTraceStub(test.getPath(), true); + fTrace = new TmfTraceStub(test.getPath(), 0, true); } catch (final URISyntaxException e) { e.printStackTrace(); } diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java index 69682adad4..34d87e1baa 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java @@ -45,7 +45,7 @@ public class TmfEventProviderStub extends TmfEventProvider { final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); try { final File test = new File(FileLocator.toFileURL(location).toURI()); - fTrace = new TmfTraceStub(test.getPath(), true); + fTrace = new TmfTraceStub(test.getPath(), 0, true); } catch (final URISyntaxException e) { e.printStackTrace(); } diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java index c28cbe01d8..b2bced5b67 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.concurrent.locks.ReentrantLock; +import org.eclipse.core.resources.IResource; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; @@ -24,6 +25,7 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; @@ -44,7 +46,7 @@ public class TmfTraceStub extends TmfTrace { private RandomAccessFile fTrace; // The associated event parser - private final ITmfEventParser fParser; + private ITmfEventParser fParser; // The synchronization lock private final ReentrantLock fLock = new ReentrantLock(); @@ -53,12 +55,21 @@ public class TmfTraceStub extends TmfTrace { // Constructors // ------------------------------------------------------------------------ + /** + * @param path + * @throws FileNotFoundException + */ + public TmfTraceStub() { + super(); + fParser = new TmfEventParserStub(); + } + /** * @param path * @throws FileNotFoundException */ public TmfTraceStub(final String path) throws FileNotFoundException { - this(path, DEFAULT_INDEX_PAGE_SIZE, false); + this(path, DEFAULT_TRACE_CACHE_SIZE, false); } /** @@ -70,13 +81,22 @@ public class TmfTraceStub extends TmfTrace { this(path, cacheSize, false); } + /** + * @param path + * @param cacheSize + * @throws FileNotFoundException + */ + public TmfTraceStub(final String path, final int cacheSize, final ITmfTraceIndexer indexer) throws FileNotFoundException { + this(path, cacheSize, false, null, indexer); + } + /** * @param path * @param waitForCompletion * @throws FileNotFoundException */ public TmfTraceStub(final String path, final boolean waitForCompletion) throws FileNotFoundException { - this(path, DEFAULT_INDEX_PAGE_SIZE, waitForCompletion); + this(path, DEFAULT_TRACE_CACHE_SIZE, waitForCompletion); } /** @@ -86,12 +106,24 @@ public class TmfTraceStub extends TmfTrace { * @throws FileNotFoundException */ public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion) throws FileNotFoundException { - // super(null, TmfEvent.class, path, cacheSize, false); + // this(path, cacheSize, waitForCompletion, null); super(null, TmfEvent.class, path, cacheSize); fTrace = new RandomAccessFile(path, "r"); fParser = new TmfEventParserStub(); } + /** + * @param path + * @param cacheSize + * @param waitForCompletion + * @throws FileNotFoundException + */ + public TmfTraceStub(final IResource resource, final String path, final int cacheSize, final boolean waitForCompletion) throws FileNotFoundException { + // this(path, cacheSize, waitForCompletion, null); + super(resource, TmfEvent.class, path, cacheSize); + fTrace = new RandomAccessFile(path, "r"); + fParser = new TmfEventParserStub(); + } /** * @param path @@ -100,38 +132,32 @@ public class TmfTraceStub extends TmfTrace { * @param parser * @throws FileNotFoundException */ - public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion, final ITmfEventParser parser) throws FileNotFoundException { - // super(null, TmfEvent.class, path, cacheSize, false); - super(null, TmfEvent.class, path, cacheSize); + public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion, + final ITmfEventParser parser, final ITmfTraceIndexer indexer) throws FileNotFoundException { + super(null, TmfEvent.class, path, cacheSize, 0, indexer); fTrace = new RandomAccessFile(path, "r"); - fParser = parser; + fParser = (parser != null) ? parser : new TmfEventParserStub(); } /** * Copy constructor */ public TmfTraceStub(final TmfTraceStub trace) throws FileNotFoundException { - // super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize(), false); - super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize()); + super(trace); fTrace = new RandomAccessFile(getPath(), "r"); fParser = new TmfEventParserStub(); - // This is really not pretty (the object is not constructed yet...) - indexTrace(true); } - // /** - // */ - // @Override - // public TmfTraceStub clone() { - // TmfTraceStub clone = null; - // try { - // clone = (TmfTraceStub) super.clone(); - // clone.fTrace = new RandomAccessFile(getPath(), "r"); - // clone.fParser = new TmfEventParserStub(); - // } catch (final FileNotFoundException e) { - // } - // return clone; - // } + public void indexTrace() { + fIndexer.buildIndex(true); + } + + @Override + public void initTrace(final IResource resource, final String path, final Class type) throws FileNotFoundException { + fTrace = new RandomAccessFile(path, "r"); + fParser = new TmfEventParserStub(); + super.initTrace(resource, path, type); + } // ------------------------------------------------------------------------ // Accessors @@ -160,8 +186,9 @@ public class TmfTraceStub extends TmfTrace { loc = ((TmfLocation) location).getLocation(); rank = ITmfContext.UNKNOWN_RANK; } - if (loc != fTrace.getFilePointer()) + if (loc != fTrace.getFilePointer()) { fTrace.seek(loc); + } final TmfContext context = new TmfContext(getCurrentLocation(), rank); return context; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index bfcd90e6e0..9481d2d3e2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -158,7 +158,7 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr } @Override - public int getIndexPageSize() { + public int getCacheSize() { return 50000; // not true, but it works } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index bdb48815ae..ed97585068 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -193,7 +193,7 @@ public class TmfExperiment extends TmfEventProvider impl } @Override - public int getIndexPageSize() { + public int getCacheSize() { return fIndexPageSize; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index c1ee9be3e7..15666917f8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -128,6 +128,11 @@ public interface ITmfTrace extends ITmfDataProvider { */ public String getPath(); + /** + * @return the trace cache size + */ + public int getCacheSize(); + // ------------------------------------------------------------------------ // Trace characteristics getters // ------------------------------------------------------------------------ @@ -252,11 +257,6 @@ public interface ITmfTrace extends ITmfDataProvider { // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ - /** - * @return the trace index page size - */ - public int getIndexPageSize(); - /** * @return the streaming interval in ms (0 if not a streaming trace) */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java new file mode 100644 index 0000000000..dcf878f49a --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.trace; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; + +/** + * ITmfTraceIndexer + *

+ */ +public interface ITmfTraceIndexer> { + + /** + * Start an asynchronous index building job and waits for the job completion + * if required. Typically, the indexing job sends notifications at regular + * intervals to indicate its progress. + * + * @param waitForCompletion + */ + public void buildIndex(boolean waitForCompletion); + + /** + * Adds an entry to the trace index. + * + * @param context + * @param rank + * @param timestamp + */ + public void updateIndex(ITmfContext context, long rank, ITmfTimestamp timestamp); + + /** + * Returns the context of the checkpoint immediately preceding the requested + * timestamp (or at the timestamp if it coincides with a checkpoint). + * + * @param timestamp the requested timestamp + * @return the checkpoint context + */ + public ITmfContext seekIndex(ITmfTimestamp timestamp); + + /** + * Returns the context of the checkpoint immediately preceding the requested + * rank (or at rank if it coincides with a checkpoint). + * + * @param rank the requested event rank + * @return the checkpoint context + */ + public ITmfContext seekIndex(long rank); + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index 200ac7ae63..d50c2b1a46 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -7,8 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Francois Chouinard - Initial API and implementation - * Francois Chouinard - Updated as per TMF Trace Model 1.0 + * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Updated as per TMF Trace Model 1.0 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.trace; @@ -20,11 +20,7 @@ import java.util.Vector; 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.Path; -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; @@ -32,18 +28,13 @@ 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.TmfTraceUpdatedSignal; /** * TmfTrace *

* Abstract implementation of ITmfTrace. *

- * It should be sufficient to extend this class and provide implementations for - * getCurrentLocation() and seekLocation(), as well - * as a proper parser, to have a working concrete implementation. + * Document me... */ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { @@ -52,9 +43,9 @@ public abstract class TmfTrace extends TmfEventProvider // ------------------------------------------------------------------------ /** - * The default number of events in an index page. Can be used as block size. + * The default trace cache size */ - public static final int DEFAULT_INDEX_PAGE_SIZE = 1000; + public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; // ------------------------------------------------------------------------ // Attributes @@ -67,9 +58,9 @@ public abstract class TmfTrace extends TmfEventProvider private String fPath; /** - * The cache page size AND checkpoints interval + * The cache page size AND trace checkpoints interval */ - protected int fIndexPageSize = DEFAULT_INDEX_PAGE_SIZE; + protected int fCacheSize = DEFAULT_TRACE_CACHE_SIZE; // The set of event stream checkpoints protected Vector fCheckpoints = new Vector(); @@ -86,6 +77,11 @@ public abstract class TmfTrace extends TmfEventProvider */ protected long fStreamingInterval = 0; + /** + * The trace indexer + */ + protected ITmfTraceIndexer> fIndexer; + // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ @@ -93,37 +89,56 @@ public abstract class TmfTrace extends TmfEventProvider /** * The default, parameterless, constructor */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public TmfTrace() { super(); + fIndexer = new TmfTraceIndexer(this); } /** * The standard constructor (non-streaming trace) * - * @param name the trace display name + * @param resource the resource associated to the trace + * @param type the trace event type + * @param path the trace path + * @param cacheSize the trace cache size + * @throws FileNotFoundException + */ + protected TmfTrace(final IResource resource, final Class type, final String path, final int cacheSize) throws FileNotFoundException { + this(resource, type, path, cacheSize, 0, null); + } + + /** + * The standard constructor (streaming trace) + * + * @param resource the resource associated to the trace * @param type the trace event type * @param path the trace path - * @param pageSize the trace index page size + * @param cacheSize the trace cache size + * @param interval the trace streaming interval * @throws FileNotFoundException */ - protected TmfTrace(final IResource resource, final Class type, final String path, final int indexPageSize) throws FileNotFoundException { - this(resource, type, path, 0, indexPageSize); + protected TmfTrace(final IResource resource, final Class type, final String path, final int cacheSize, final long interval) throws FileNotFoundException { + this(resource, type, path, cacheSize, interval, null); } /** * The full constructor * - * @param name the trace display name + * @param resource the resource associated to the trace * @param type the trace event type * @param path the trace path - * @param pageSize the trace index page size + * @param cacheSize the trace cache size + * @param indexer the trace indexer * @throws FileNotFoundException */ - protected TmfTrace(final IResource resource, final Class type, final String path, final long interval, final int indexPageSize) throws FileNotFoundException - { + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected TmfTrace(final IResource resource, final Class type, final String path, final int cacheSize, + final long interval, final ITmfTraceIndexer indexer) throws FileNotFoundException { super(); + fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE; fStreamingInterval = interval; - fIndexPageSize = (indexPageSize > 0) ? indexPageSize : DEFAULT_INDEX_PAGE_SIZE; + fIndexer = (indexer != null) ? indexer : new TmfTraceIndexer(this); initialize(resource, path, type); } @@ -132,20 +147,17 @@ public abstract class TmfTrace extends TmfEventProvider * * @param trace the original trace */ - public TmfTrace(final ITmfTrace trace) throws FileNotFoundException { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public TmfTrace(final TmfTrace trace) throws FileNotFoundException { super(); if (trace == null) throw new IllegalArgumentException(); - fStreamingInterval = getStreamingInterval(); - fIndexPageSize = getIndexPageSize(); + fCacheSize = trace.getCacheSize(); + fStreamingInterval = trace.getStreamingInterval(); + fIndexer = new TmfTraceIndexer(this); initialize(trace.getResource(), trace.getPath(), trace.getType()); - indexTrace(false); } - // ------------------------------------------------------------------------ - // ITmfTrace - Initializers - // ------------------------------------------------------------------------ - /** * @param resource * @param path @@ -168,17 +180,23 @@ public abstract class TmfTrace extends TmfEventProvider super.init(traceName, type); } + // ------------------------------------------------------------------------ + // ITmfTrace - Initializers + // ------------------------------------------------------------------------ + /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class) */ @Override public void initTrace(final IResource resource, final String path, final Class type) throws FileNotFoundException { initialize(resource, path, type); - indexTrace(false); + fIndexer.buildIndex(false); } /* (non-Javadoc) * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String) + * + * Default validation: make sure the trace file exists. */ @Override public boolean validate(final IProject project, final String path) { @@ -215,6 +233,22 @@ public abstract class TmfTrace extends TmfEventProvider return fPath; } + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize() + */ + @Override + public int getCacheSize() { + return fCacheSize; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval() + */ + @Override + public long getStreamingInterval() { + return fStreamingInterval; + } + // ------------------------------------------------------------------------ // ITmfTrace - Trace characteristics getters // ------------------------------------------------------------------------ @@ -240,7 +274,7 @@ public abstract class TmfTrace extends TmfEventProvider */ @Override public ITmfTimestamp getStartTime() { - return new TmfTimestamp(fStartTime); + return fStartTime.clone(); } /* (non-Javadoc) @@ -248,7 +282,48 @@ public abstract class TmfTrace extends TmfEventProvider */ @Override public ITmfTimestamp getEndTime() { - return new TmfTimestamp(fEndTime); + return fEndTime.clone(); + } + + // ------------------------------------------------------------------------ + // Convenience setters + // ------------------------------------------------------------------------ + + /** + * Update the trace events time range + * + * @param range the new time range + */ + protected void setTimeRange(final TmfTimeRange range) { + fStartTime = range.getStartTime().clone(); + fEndTime = range.getEndTime().clone(); + } + + /** + * Update the trace chronologically first event timestamp + * + * @param startTime the new first event timestamp + */ + protected void setStartTime(final ITmfTimestamp startTime) { + fStartTime = startTime.clone(); + } + + /** + * Update the trace chronologically last event timestamp + * + * @param endTime the new last event timestamp + */ + protected void setEndTime(final ITmfTimestamp endTime) { + fEndTime = endTime.clone(); + } + + /** + * Update the trace streaming interval + * + * @param interval the new trace streaming interval + */ + protected void setStreamingInterval(final long interval) { + fStreamingInterval = interval; } // ------------------------------------------------------------------------ @@ -299,7 +374,7 @@ public abstract class TmfTrace extends TmfEventProvider return seekLocation(null); // Find the checkpoint at or before the requested rank. - final int index = (int) rank / fIndexPageSize; + final int index = (int) rank / fCacheSize; final ITmfContext context = seekCheckpoint(index); // And locate the requested event context @@ -333,7 +408,7 @@ public abstract class TmfTrace extends TmfEventProvider } } final ITmfContext context = seekLocation(location); - context.setRank(index * fIndexPageSize); + context.setRank(index * fCacheSize); return context; } @@ -379,9 +454,9 @@ public abstract class TmfTrace extends TmfEventProvider fNbEvents = rank + 1; } // Build the index as we go along - if ((rank % fIndexPageSize) == 0) { + if ((rank % fCacheSize) == 0) { // Determine the table position - final long position = rank / fIndexPageSize; + final long position = rank / fCacheSize; // Add new entry at proper location (if empty) if (fCheckpoints.size() == position) { final ITmfLocation location = context.getLocation().clone(); @@ -392,130 +467,104 @@ public abstract class TmfTrace extends TmfEventProvider } } - // ------------------------------------------------------------------------ - // ITmfTrace - indexing - // ------------------------------------------------------------------------ - - /* - * The index is a list of contexts that point to events at regular interval - * (rank-wise) in the trace. After it is built, the index can be used to - * quickly access any event by rank or timestamp. - * - * fIndexPageSize holds the event interval (default INDEX_PAGE_SIZE). - */ - - @SuppressWarnings({ "unchecked" }) - protected void indexTrace(final boolean waitForCompletion) { - - // The monitoring job - 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(); - - // Clear the checkpoints - fCheckpoints.clear(); - - // Build a background request for all the trace data. The index is - // updated as we go by getNextEvent(). - final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, - TmfTimeRange.ETERNITY, - TmfDataRequest.ALL_DATA, fIndexPageSize, ITmfDataRequest.ExecutionType.BACKGROUND) - { - - ITmfTimestamp startTime = null; - ITmfTimestamp lastTime = null; - - @Override - public void handleData(final ITmfEvent event) { - super.handleData(event); - if (event != null) { - final ITmfTimestamp timestamp = event.getTimestamp(); - if (startTime == null) { - startTime = timestamp.clone(); - } - lastTime = timestamp.clone(); - - // Update the trace status at regular intervals - if ((getNbRead() % fIndexPageSize) == 0) { - updateTraceStatus(); - } - } - } - - @Override - public void handleSuccess() { - updateTraceStatus(); - } - - @Override - public void handleCompleted() { - job.cancel(); - super.handleCompleted(); - } - - private synchronized void updateTraceStatus() { - final int nbRead = getNbRead(); - if (nbRead != 0) { - fStartTime = startTime; - fEndTime = lastTime; - fNbEvents = nbRead; - notifyListeners(); - } - } - }; - - // Submit the request and wait for completion if required - sendRequest((ITmfDataRequest) request); - if (waitForCompletion) { - try { - request.waitForCompletion(); - } catch (final InterruptedException e) { - } - } - } - - private void notifyListeners() { - broadcast(new TmfTraceUpdatedSignal(this, this, new TmfTimeRange(fStartTime, fEndTime))); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @SuppressWarnings("unchecked") - public Vector getCheckpoints() { - return (Vector) fCheckpoints.clone(); - } - - // ------------------------------------------------------------------------ - // Operators - // ------------------------------------------------------------------------ - - protected void setTimeRange(final TmfTimeRange range) { - fStartTime = range.getStartTime(); - fEndTime = range.getEndTime(); - } - - protected void setStartTime(final ITmfTimestamp startTime) { - fStartTime = startTime; - } - - protected void setEndTime(final ITmfTimestamp endTime) { - fEndTime = endTime; - } +// // ------------------------------------------------------------------------ +// // ITmfTrace - indexing +// // ------------------------------------------------------------------------ +// +// /* +// * The index is a list of contexts that point to events at regular interval +// * (rank-wise) in the trace. After it is built, the index can be used to +// * quickly access any event by rank or timestamp. +// * +// * fIndexPageSize holds the event interval (default INDEX_PAGE_SIZE). +// */ +// +// @SuppressWarnings({ "unchecked" }) +// protected void indexTrace(final boolean waitForCompletion) { +// +// // The monitoring job +// 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(); +// +// // Clear the checkpoints +// fCheckpoints.clear(); +// +// // Build a background request for all the trace data. The index is +// // updated as we go by getNextEvent(). +// final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, +// TmfTimeRange.ETERNITY, +// TmfDataRequest.ALL_DATA, fCacheSize, ITmfDataRequest.ExecutionType.BACKGROUND) +// { +// +// ITmfTimestamp startTime = null; +// ITmfTimestamp lastTime = null; +// +// @Override +// public void handleData(final ITmfEvent event) { +// super.handleData(event); +// if (event != null) { +// final ITmfTimestamp timestamp = event.getTimestamp(); +// if (startTime == null) { +// startTime = timestamp.clone(); +// } +// lastTime = timestamp.clone(); +// +// // Update the trace status at regular intervals +// if ((getNbRead() % fCacheSize) == 0) { +// updateTraceStatus(); +// } +// } +// } +// +// @Override +// public void handleSuccess() { +// updateTraceStatus(); +// } +// +// @Override +// public void handleCompleted() { +// job.cancel(); +// super.handleCompleted(); +// } +// +// private synchronized void updateTraceStatus() { +// final int nbRead = getNbRead(); +// if (nbRead != 0) { +// fStartTime = startTime; +// fEndTime = lastTime; +// fNbEvents = nbRead; +// notifyListeners(); +// } +// } +// }; +// +// // Submit the request and wait for completion if required +// sendRequest((ITmfDataRequest) request); +// if (waitForCompletion) { +// try { +// request.waitForCompletion(); +// } catch (final InterruptedException e) { +// } +// } +// } +// +// private void notifyListeners() { +// broadcast(new TmfTraceUpdatedSignal(this, this, new TmfTimeRange(fStartTime, fEndTime))); +// } // ------------------------------------------------------------------------ // TmfProvider @@ -541,8 +590,8 @@ public abstract class TmfTrace extends TmfEventProvider * @param context * @return the event referred to by context */ - @SuppressWarnings("unchecked") @Override + @SuppressWarnings("unchecked") public T getNext(final ITmfContext context) { if (context instanceof TmfContext) return (T) getNextEvent(context); @@ -554,35 +603,12 @@ public abstract class TmfTrace extends TmfEventProvider // toString // ------------------------------------------------------------------------ - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override @SuppressWarnings("nls") public String toString() { - return "[TmfTrace (" + getName() + ")]"; - } - - // ------------------------------------------------------------------------ - // ITmfTrace - Trace TBD getters - // ------------------------------------------------------------------------ - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval() - */ - @Override - public long getStreamingInterval() { - return fStreamingInterval; - } - - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize() - */ - @Override - public int getIndexPageSize() { - return fIndexPageSize; + return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize + + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime + + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]"; } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceIndexer.java new file mode 100644 index 0000000000..81d15a926d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceIndexer.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * 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.trace; + +import java.util.Collections; +import java.util.Vector; + +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.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.TmfTraceUpdatedSignal; + +/** + * TmfTraceIndexer + *

+ * A simple trace indexer that builds an array of trace checkpoints. Checkpoints + * are stored at fixed intervals (event rank) in ascending timestamp order. + *

+ * The goal being to access a random trace event reasonably fast from the user's + * standpoint, picking the right interval value becomes a trade-off between speed + * and memory usage (a shorter inter-event interval is faster but requires more + * checkpoints). + *

+ * Locating a specific checkpoint is trivial for both rank (rank % interval) and + * timestamp (bsearch in the array). + */ +public class TmfTraceIndexer> implements ITmfTraceIndexer { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The event trace to index + */ + private final ITmfTrace fTrace; + + /** + * The interval between checkpoints + */ + protected final int fCheckpointInterval; + + /** + * The trace index. It is composed of checkpoints taken at intervals of + * fCheckpointInterval events. + */ + protected final Vector fTraceIndex; + + // ------------------------------------------------------------------------ + // Construction + // ------------------------------------------------------------------------ + + /** + * Basic constructor that uses the default trace block size as checkpoints + * intervals + * + * @param trace the trace to index + */ + public TmfTraceIndexer(final ITmfTrace trace) { + this(trace, TmfTrace.DEFAULT_BLOCK_SIZE); + } + + /** + * Full trace indexer + * + * @param trace the trace to index + * @param interval the checkpoints interval + */ + public TmfTraceIndexer(final ITmfTrace trace, final int interval) { + fTrace = trace; + fCheckpointInterval = interval; + fTraceIndex = new Vector(); + } + + // ------------------------------------------------------------------------ + // ITmfTraceIndexer + // ------------------------------------------------------------------------ + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#indexTrace(boolean) + * + * The index is a list of contexts that point to events at regular interval + * (rank-wise) in the trace. After it is built, the index can be used to + * quickly access any event by rank or timestamp (using seekIndex()). + * + * The index is built simply by reading the trace + */ + @Override + public void buildIndex(final boolean waitForCompletion) { + + // The monitoring job + final Job job = new Job("Indexing " + fTrace.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(); + + // Clear the checkpoints + fTraceIndex.clear(); + + // Build a background request for all the trace data. The index is + // updated as we go by getNextEvent(). + final ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, + TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND) + { + ITmfTimestamp startTime = null; + ITmfTimestamp lastTime = null; + + @Override + public void handleData(final ITmfEvent event) { + super.handleData(event); + if (event != null) { + final ITmfTimestamp timestamp = event.getTimestamp(); + if (startTime == null) { + startTime = timestamp.clone(); + } + lastTime = timestamp.clone(); + + // Update the trace status at regular intervals + if ((getNbRead() % fCheckpointInterval) == 0) { + updateTraceStatus(); + } + } + } + + @Override + public void handleSuccess() { + updateTraceStatus(); + } + + @Override + public void handleCompleted() { + job.cancel(); + super.handleCompleted(); + } + + private void updateTraceStatus() { + if (getNbRead() != 0) { + notifyListeners(startTime, lastTime); + } + } + }; + + // Submit the request and wait for completion if required + fTrace.sendRequest(request); + if (waitForCompletion) { + try { + request.waitForCompletion(); + } catch (final InterruptedException e) { + } + } + } + + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer#seekIndex(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp) + */ + @Override + public ITmfContext seekIndex(final ITmfTimestamp timestamp) { + // Adjust the timestamp if needed + ITmfTimestamp ts = timestamp; + if (ts == null) { + ts = TmfTimestamp.BIG_BANG; + } + + // First, find the right checkpoint + int index = Collections.binarySearch(fTraceIndex, new TmfCheckpoint(ts, 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 figure out the context. + if (index < 0) { + index = Math.max(0, -(index + 2)); + } + + // Position the trace at the checkpoint + ITmfLocation location; + synchronized (fTraceIndex) { + if (!fTraceIndex.isEmpty()) { + if (index >= fTraceIndex.size()) { + index = fTraceIndex.size() - 1; + } + location = fTraceIndex.elementAt(index).getLocation(); + } else { + location = null; + } + } + final ITmfContext context = fTrace.seekLocation(location); + context.setRank(index * fCheckpointInterval); + + return context; + } + + @Override + public ITmfContext seekIndex(final long rank) { + + // Position the stream at the previous checkpoint + int index = (int) rank / fCheckpointInterval; + ITmfLocation location; + synchronized (fTraceIndex) { + if (fTraceIndex.isEmpty()) { + location = null; + } else { + if (index >= fTraceIndex.size()) { + index = fTraceIndex.size() - 1; + } + location = fTraceIndex.elementAt(index).getLocation(); + } + } + + final ITmfContext context = fTrace.seekLocation(location); + final long pos = index * fCheckpointInterval; + context.setRank(pos); + + return context; + } + + private void notifyListeners(final ITmfTimestamp startTime, final ITmfTimestamp endTime) { + fTrace.broadcast(new TmfTraceUpdatedSignal(fTrace, fTrace, new TmfTimeRange(startTime, endTime))); + } + + @Override + public void updateIndex(final ITmfContext context, final long rank, final ITmfTimestamp timestamp) { + if ((rank % fCheckpointInterval) == 0) { + // Determine the table position + final long position = rank / fCheckpointInterval; + // Add new entry at proper location (if empty) + if (fTraceIndex.size() == position) { + final ITmfLocation location = context.getLocation().clone(); + fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), location)); + // System.out.println(getName() + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString()); + } + } + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF index 2b4a9cef4b..a503ce17d1 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.junit;bundle-version="3.8.2", org.eclipse.ui;bundle-version="3.7.0", org.eclipse.core.runtime;bundle-version="3.7.0", + org.eclipse.core.resources;bundle-version="3.7.100", org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0", org.eclipse.linuxtools.tmf.ui;bundle-version="0.4.0", org.eclipse.linuxtools.tmf.core.tests;bundle-version="0.4.0" diff --git a/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/impl/Uml2SDTestFacility.java b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/impl/Uml2SDTestFacility.java index 2c1637f8d9..f5f254677f 100644 --- a/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/impl/Uml2SDTestFacility.java +++ b/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/impl/Uml2SDTestFacility.java @@ -42,23 +42,23 @@ import org.osgi.framework.FrameworkUtil; /** * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides - * utility methods for interacting with the loader/view. + * utility methods for interacting with the loader/view. */ public class Uml2SDTestFacility { - + // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ private static Uml2SDTestFacility fInstance = null; - + private TmfUml2SDSyncLoader fLoader; private SDView fSdView; private TmfTraceStub fTrace = null; private TmfUml2SDTestTrace fParser = null; private TmfExperiment fExperiment = null; - + private boolean fIsInitialized = false; - + // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ @@ -80,12 +80,12 @@ public class Uml2SDTestFacility { * Initial the test facility. */ public void init() { - + if (!fIsInitialized) { fParser = new TmfUml2SDTestTrace(); fTrace = setupTrace(fParser); - + IViewPart view; try { // Remove welcome view to avoid interference during test execution @@ -93,19 +93,19 @@ public class Uml2SDTestFacility { .getActiveWorkbenchWindow() .getActivePage() .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$ - + if (view != null) { PlatformUI.getWorkbench() .getActiveWorkbenchWindow() - .getActivePage().hideView(view); + .getActivePage().hideView(view); } - + view = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage() - .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$ - - } catch (PartInitException e) { + .getActiveWorkbenchWindow() + .getActivePage() + .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$ + + } catch (final PartInitException e) { throw new RuntimeException(e); } @@ -118,23 +118,23 @@ public class Uml2SDTestFacility { } } - - private TmfTraceStub setupTrace(ITmfEventParser parser) { - - try { - // Create test trace object - URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$ - File test = new File(FileLocator.toFileURL(location).toURI()); - return new TmfTraceStub(test.getPath(), 500, true, parser); - } catch (URISyntaxException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } + + private TmfTraceStub setupTrace(final ITmfEventParser parser) { + + try { + // Create test trace object + final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$ + final File test = new File(FileLocator.toFileURL(location).toURI()); + return new TmfTraceStub(test.getPath(), 500, true, parser, null); + } catch (final URISyntaxException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } catch (final IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } } - + /** * Dispose the resource */ @@ -149,15 +149,15 @@ public class Uml2SDTestFacility { fIsInitialized = false; } } - + /** - * Sleeps current thread or GUI thread for a given time. + * Sleeps current thread or GUI thread for a given time. * @param waitTimeMillis */ - public void delay(long waitTimeMillis) { - Display display = Display.getCurrent(); + public void delay(final long waitTimeMillis) { + final Display display = Display.getCurrent(); if (display != null) { - long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; + final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; while(System.currentTimeMillis() < endTimeMillis) { if (!display.readAndDispatch()) { display.sleep(); @@ -167,7 +167,7 @@ public class Uml2SDTestFacility { } else { try { Thread.sleep(waitTimeMillis); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { // Ignored } } @@ -216,7 +216,7 @@ public class Uml2SDTestFacility { public TmfExperiment getExperiment() { return fExperiment; } - + /** * Go to next page; */ @@ -234,7 +234,7 @@ public class Uml2SDTestFacility { fLoader.waitForCompletion(); delay(IUml2SDTestConstants.GUI_REFESH_DELAY); } - + /** * Go to last page. */ @@ -252,32 +252,32 @@ public class Uml2SDTestFacility { fLoader.waitForCompletion(); delay(IUml2SDTestConstants.GUI_REFESH_DELAY); } - + /** * @param page number to set */ - public void setPage(int page) { + public void setPage(final int page) { fLoader.pageNumberChanged(page);; fLoader.waitForCompletion(); delay(IUml2SDTestConstants.GUI_REFESH_DELAY); } - + /** * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean) */ public void selectExperiment() { this.selectExperiment(true); } - + /** - * Selects the experiment. + * Selects the experiment. * @param wait true to wait for indexing to finish else false */ @SuppressWarnings({ "rawtypes", "unchecked" }) - public void selectExperiment(boolean wait) { + public void selectExperiment(final boolean wait) { fTrace = setupTrace(fParser); - ITmfTrace traces[] = new ITmfTrace[1]; + final ITmfTrace traces[] = new ITmfTrace[1]; traces[0] = fTrace; fExperiment = new TmfExperiment(TmfEvent.class, "TestExperiment", traces); //$NON-NLS-1$ fTrace.broadcast(new TmfExperimentSelectedSignal(this, fExperiment)); @@ -289,7 +289,7 @@ public class Uml2SDTestFacility { delay(IUml2SDTestConstants.GUI_REFESH_DELAY); } } - + /** * Disposes the experiment. */ @@ -297,18 +297,18 @@ public class Uml2SDTestFacility { fExperiment.dispose(); delay(IUml2SDTestConstants.GUI_REFESH_DELAY); } - + /** - * Creates some global filter criteria and saves them to disk. + * Creates some global filter criteria and saves them to disk. */ public void createFilterCriteria() { // Create Filter Criteria and save tme - List filterToSave = new ArrayList(); + final List filterToSave = new ArrayList(); Criteria criteria = new Criteria(); criteria.setLifeLineSelected(true); criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME); filterToSave.add(new FilterCriteria(criteria, true, false)); - + criteria = new Criteria(); criteria.setSyncMessageSelected(true); criteria.setExpression("BALL_.*"); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java index ef0a53e96d..99a1dca40b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -142,7 +142,7 @@ public class OpenExperimentHandler extends AbstractHandler { } catch (final FileNotFoundException e) { displayErrorMsg(""); //$NON-NLS-1$ } - cacheSize = Math.min(cacheSize, trace.getIndexPageSize()); + cacheSize = Math.min(cacheSize, trace.getCacheSize()); final String editorId = element.getEditorId(); if (editorId == null) { useEditor = false; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java index 425dc2fe39..e4ce66a07b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java @@ -188,7 +188,7 @@ public class OpenTraceHandler extends AbstractHandler { else { // Create the experiment final ITmfTrace[] traces = new ITmfTrace[] { trace }; - final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), fTrace.getName(), traces, trace.getIndexPageSize()); + final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), fTrace.getName(), traces, trace.getCacheSize()); experiment.setBookmarksFile(file); TmfExperiment.setCurrentExperiment(experiment); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java index f145e550b9..217aa36d08 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java @@ -136,7 +136,7 @@ public class EventsViewEditor extends TmfEditor { trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); } catch (final FileNotFoundException e) { } - cacheSize = Math.min(cacheSize, trace.getIndexPageSize()); + cacheSize = Math.min(cacheSize, trace.getCacheSize()); traces[i] = trace; } final TmfExperiment experiment = new TmfExperiment(TmfEvent.class, experimentElement.getName(), traces, cacheSize); @@ -166,7 +166,7 @@ public class EventsViewEditor extends TmfEditor { } catch (final FileNotFoundException e) { } final ITmfTrace[] traces = new ITmfTrace[] { trace }; - final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), traceElement.getName(), traces, trace.getIndexPageSize()); + final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), traceElement.getName(), traces, trace.getCacheSize()); experiment.setBookmarksFile(fFile); fTrace = experiment; TmfExperiment.setCurrentExperiment(experiment); @@ -191,7 +191,7 @@ public class EventsViewEditor extends TmfEditor { } catch (final FileNotFoundException e) { } final ITmfTrace[] traces = new ITmfTrace[] { trace }; - final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), traceElement.getName(), traces, trace.getIndexPageSize()); + final TmfExperiment experiment = new TmfExperiment(traceEvent.getClass(), traceElement.getName(), traces, trace.getCacheSize()); experiment.setBookmarksFile(fFile); fTrace = experiment; TmfExperiment.setCurrentExperiment(experiment); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java index da21b9d841..e9f9e9cad0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java @@ -130,7 +130,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); } catch (final FileNotFoundException e) { } - cacheSize = Math.min(cacheSize, trace.getIndexPageSize()); + cacheSize = Math.min(cacheSize, trace.getCacheSize()); traces[i] = trace; } final TmfExperiment experiment = new TmfExperiment(TmfEvent.class, experimentElement.getName(), traces, cacheSize); @@ -222,7 +222,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus super.setInput(new FileEditorInput(fFile)); fEventsTable.dispose(); if (fTrace != null) { - fEventsTable = createEventsTable(fParent, fTrace.getIndexPageSize()); + fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); fEventsTable.refreshBookmarks(fFile); broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable)); @@ -237,7 +237,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus fParent = parent; if (fTrace != null) { setPartName(fTrace.getName()); - fEventsTable = createEventsTable(parent, fTrace.getIndexPageSize()); + fEventsTable = createEventsTable(parent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); fEventsTable.refreshBookmarks(fFile); broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable)); @@ -471,7 +471,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus } fEventsTable.dispose(); if (fTrace != null) { - fEventsTable = createEventsTable(fParent, fTrace.getIndexPageSize()); + fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); fEventsTable.setTrace(fTrace, true); broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable)); } else diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index ef3900c6a9..d4a82ec8c0 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -1013,7 +1013,7 @@ ITmfEventsFilterProvider { if (nbRequested <= 0) return; request = new TmfEventRequest(TmfEvent.class, TmfTimeRange.ETERNITY, (int) fFilterCheckCount, - nbRequested, fTrace.getIndexPageSize(), ExecutionType.BACKGROUND) { + nbRequested, fTrace.getCacheSize(), ExecutionType.BACKGROUND) { @Override public void handleData(final TmfEvent event) { super.handleData(event); @@ -1189,9 +1189,9 @@ ITmfEventsFilterProvider { boolean wrapped = false; while (!monitor.isCanceled() && (foundRank == -1) && (fTrace != null)) { int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1, - fTrace.getIndexPageSize())); + fTrace.getCacheSize())); if (direction == Direction.BACKWARD) - rank = Math.max(0, rank - fTrace.getIndexPageSize() + 1); + rank = Math.max(0, rank - fTrace.getCacheSize() + 1); request = new TmfDataRequest(TmfEvent.class, (int) rank, nbRequested) { long currentRank = rank; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java index df749ae875..0d20170c43 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java @@ -108,7 +108,7 @@ public class TmfEventsView extends TmfView { if (fExperiment == null) { return new TmfEventsTable(parent, DEFAULT_CACHE_SIZE); } - int cacheSize = fExperiment.getIndexPageSize(); + int cacheSize = fExperiment.getCacheSize(); String commonTraceType = null; try { for (ITmfTrace trace : fExperiment.getTraces()) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java index 5707fa51a6..b386e4f7b1 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramRequest.java @@ -38,7 +38,7 @@ public class HistogramRequest extends TmfEventRequest { // ------------------------------------------------------------------------ public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range, int rank, int nbEvents, ITmfDataRequest.ExecutionType execType) { - super(ITmfEvent.class, range, rank, nbEvents, TmfTrace.DEFAULT_INDEX_PAGE_SIZE, execType); + super(ITmfEvent.class, range, rank, nbEvents, TmfTrace.DEFAULT_TRACE_CACHE_SIZE, execType); fHistogram = histogram; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java index e48fe24dea..2c27264ca9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartEvent.java @@ -195,7 +195,7 @@ public class TimeChartEvent implements ITimeEvent { } public void merge(RankRangeList rankRangeList) { - long threshold = fParentEntry.getTrace().getIndexPageSize(); + long threshold = fParentEntry.getTrace().getCacheSize(); for (RankRange newRange : rankRangeList) { boolean merged = false; for (RankRange oldRange : fRankRangeList) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java index 3b0a377fcf..e105915b0f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java @@ -196,7 +196,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList done = true; break; } - if (context.getRank() % trace.getIndexPageSize() == 1) { + if (context.getRank() % trace.getCacheSize() == 1) { // break for UI refresh break; } @@ -411,7 +411,7 @@ public class TimeChartView extends TmfView implements ITmfTimeScaleSelectionList entryIsBookmarked |= event.isBookmarked(); entryIsVisible |= event.isVisible(); entryIsSearchMatch |= event.isSearchMatch(); - if (++fCount % timeAnalysisEntry.getTrace().getIndexPageSize() == 0) { + if (++fCount % timeAnalysisEntry.getTrace().getCacheSize() == 0) { refreshViewer(false); } } -- 2.34.1