From: Francois Chouinard Date: Thu, 8 Jul 2010 20:54:57 +0000 (+0000) Subject: 2010-07-08 Francois Chouinard Partial implementation of... X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=664902f74d8db1dd9030819c137b19ed7e6d8ee3;p=deliverable%2Ftracecompass.git 2010-07-08 Francois Chouinard Partial implementation of Bug316354 (for Patrick's contribution) * src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java (indexTrace): New method + renamed a constant --- diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java index 91ba9941e5..5f1a4a072b 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java @@ -52,7 +52,7 @@ public class LTTngTraceStub extends TmfTrace { * @throws FileNotFoundException */ public LTTngTraceStub(String filename) throws FileNotFoundException { - this(filename, DEFAULT_CACHE_SIZE); + this(filename, DEFAULT_INDEX_PAGE_SIZE); } /** diff --git a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfTraceTest.java index aa8ee51129..8f3ce4903c 100644 --- a/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.tests/src/org/eclipse/linuxtools/tmf/tests/trace/TmfTraceTest.java @@ -122,7 +122,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertEquals("getPath", testfile.getPath(), trace.getPath()); assertEquals("getName", TEST_STREAM, trace.getName()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getCacheSize()); } public void testTmfTraceDefaultCacheSize() throws Exception { @@ -141,7 +141,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getType", TmfEvent.class, trace.getType()); assertEquals("getPath", testfile.getPath(), trace.getPath()); assertEquals("getName", TEST_STREAM, trace.getName()); - assertEquals("getCacheSize", TmfTrace.DEFAULT_CACHE_SIZE, trace.getCacheSize()); + assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getCacheSize()); } public void testTmfTrace() throws Exception { diff --git a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfTraceStub.java b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfTraceStub.java index b691326758..da556ba029 100644 --- a/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfTraceStub.java +++ b/org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfTraceStub.java @@ -47,7 +47,7 @@ public class TmfTraceStub extends TmfTrace { * @throws FileNotFoundException */ public TmfTraceStub(String filename) throws FileNotFoundException { - this(filename, DEFAULT_CACHE_SIZE, false); + this(filename, DEFAULT_INDEX_PAGE_SIZE, false); } /** @@ -65,7 +65,7 @@ public class TmfTraceStub extends TmfTrace { * @throws FileNotFoundException */ public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException { - this(filename, DEFAULT_CACHE_SIZE, waitForCompletion); + this(filename, DEFAULT_INDEX_PAGE_SIZE, waitForCompletion); } /** diff --git a/org.eclipse.linuxtools.tmf/ChangeLog b/org.eclipse.linuxtools.tmf/ChangeLog index 9df424b2d5..37961d5c40 100644 --- a/org.eclipse.linuxtools.tmf/ChangeLog +++ b/org.eclipse.linuxtools.tmf/ChangeLog @@ -1,3 +1,7 @@ +2010-07-08 Francois Chouinard + + * src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java (indexTrace): New method + renamed a constant + 2009-06-16 Andrew Overholt * META-INF/MANIFEST.MF: Change provider from Ericsson to Eclipse. \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java index 959fb32264..667b594380 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java @@ -23,6 +23,9 @@ import org.eclipse.linuxtools.tmf.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.request.ITmfDataRequest; import org.eclipse.linuxtools.tmf.request.ITmfEventRequest; +import org.eclipse.linuxtools.tmf.request.TmfDataRequest; +import org.eclipse.linuxtools.tmf.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.signal.TmfTraceUpdatedSignal; /** * TmfTrace @@ -52,7 +55,7 @@ public abstract class TmfTrace extends TmfEventProvider i // The default number of events to cache // TODO: Make the DEFAULT_CACHE_SIZE a preference - public static final int DEFAULT_CACHE_SIZE = 1000; + public static final int DEFAULT_INDEX_PAGE_SIZE = 1000; // ------------------------------------------------------------------------ // Attributes @@ -83,7 +86,7 @@ public abstract class TmfTrace extends TmfEventProvider i * @throws FileNotFoundException */ protected TmfTrace(String name, Class type, String path) throws FileNotFoundException { - this(name, type, path, DEFAULT_CACHE_SIZE); + this(name, type, path, DEFAULT_INDEX_PAGE_SIZE); } /** @@ -97,7 +100,7 @@ public abstract class TmfTrace extends TmfEventProvider i String simpleName = (sep >= 0) ? path.substring(sep + 1) : path; setName(simpleName); fPath = path; - fIndexPageSize = (cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE; + fIndexPageSize = (cacheSize > 0) ? cacheSize : DEFAULT_INDEX_PAGE_SIZE; } /* (non-Javadoc) @@ -358,4 +361,66 @@ public abstract class TmfTrace extends TmfEventProvider i return "[TmfTrace (" + getName() + ")]"; } + // ------------------------------------------------------------------------ + // Indexing + // ------------------------------------------------------------------------ + + /* + * The purpose of the index is to keep the information needed to rapidly + * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE + * event). + */ + + @SuppressWarnings({ "unchecked", "unused" }) + private void indexTrace(boolean waitForCompletion) { + + fCheckpoints.clear(); + + ITmfEventRequest request = new TmfEventRequest(TmfEvent.class, TmfTimeRange.Eternity, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.LONG) { + + TmfTimestamp startTime = null; + TmfTimestamp lastTime = null; + + @Override + public void handleData() { + TmfEvent[] events = getData(); + if (events.length > 0) { + TmfTimestamp ts = events[0].getTimestamp(); + if (startTime == null) { + startTime = new TmfTimestamp(ts); + fStartTime = startTime; + } + lastTime = new TmfTimestamp(ts); + + if ((fNbRead % DEFAULT_INDEX_PAGE_SIZE) == 0) { + updateTraceData(); + } + } + } + + @Override + public void handleSuccess() { + updateTraceData(); + } + + private void updateTraceData() { + fEndTime = new TmfTimestamp(lastTime); + fNbEvents = fNbRead; + notifyListeners(); + } + }; + + sendRequest((ITmfDataRequest) request); + if (waitForCompletion) + try { + request.waitForCompletion(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected void notifyListeners() { + broadcast(new TmfTraceUpdatedSignal(this, this, new TmfTimeRange(fStartTime, fEndTime))); + } + }