tmf: Split StateHistorySystem into two interfaces
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 30 Apr 2012 20:04:28 +0000 (16:04 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 1 May 2012 17:20:50 +0000 (13:20 -0400)
This will offer a query-only interface, which has no method
to write to or modify the state history in any way. This is
much safer, now that the views are starting to use it.

As part of the process, the history-less StateSystem is no
longer easily available. It was never much used in practice,
but if it's ever needed in the future it should be relatively
easy to bring it back.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
14 files changed:
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/CtfDummyInput.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/CtfKernelStateInputTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullThreadedHistoryTest.java
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateHistorySystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/HistoryBuilder.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateChangeInput.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemBuilder.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemQuerier.java [new file with mode: 0644]

index 5cc2664be3509966627caee7d68dc614c37ff2d3..d6924c4334d0712608fae261585aa869c3e95b8e 100644 (file)
@@ -15,8 +15,8 @@ package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemBuilder;
 
 /**
  * "Dummy" version of the CTF event input plugin. This one only reads events
@@ -64,17 +64,7 @@ public class CtfDummyInput implements IStateChangeInput {
      * method does nothing.
      */
     @Override
-    public void assignTargetStateSystem(StateSystem ss) {
+    public void assignTargetStateSystem(IStateSystemBuilder ssb) {
         //
     }
-
-    /**
-     * Since there is no target state system in the dummy input, this always
-     * returns null.
-     */
-    @Override
-    public StateSystem getStateSystem() {
-        return null;
-    }
-
 }
index 84fa94b8827d7ae6fb20e3697d1714fd1c7c99b1..556ea96962f798fa56e7439a846c70fd2320deb0 100644 (file)
@@ -16,7 +16,6 @@ import static org.junit.Assert.assertEquals;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -50,12 +49,12 @@ public class CtfKernelStateInputTest {
         assertEquals(testStartTime, CtfTestFiles.startTime);
     }
 
-    @Test
-    public void testRunning() {
-        StateSystem ss = new StateSystem();
-        input.assignTargetStateSystem(ss);
-        input.getStateSystem(); /* Let's pad that coverage... */
-        input.run();
-    }
+    //FIXME re-enable once we offer history-less state systems again
+//    @Test
+//    public void testRunning() {
+//        StateSystem ss = new StateSystem();
+//        input.assignTargetStateSystem(ss);
+//        input.run();
+//    }
 
 }
index 1fb93b0b8ed5b246ebb6a8b1da02ffbdaa1cf32b..d886d6e56e2533e2b8aba73a100c9680b205d08a 100644 (file)
@@ -15,20 +15,18 @@ package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 import static org.junit.Assert.*;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.List;
 
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
 import org.eclipse.linuxtools.tmf.core.statesystem.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.TimeRangeException;
 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.HistoryBuilder;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateHistoryBackend;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemBuilder;
 import org.eclipse.linuxtools.tmf.core.statevalue.StateValueTypeException;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
 import org.eclipse.linuxtools.lttng2.kernel.core.trace.Attributes;
@@ -50,7 +48,7 @@ public class StateSystemFullHistoryTest {
     static HistoryBuilder builder;
     static IStateChangeInput input;
     static IStateHistoryBackend hp;
-    static StateHistorySystem shs;
+    static IStateSystemBuilder ssb;
 
     /* Offset in the trace + start time of the trace */
     private final static long interestingTimestamp1 = 18670067372290L + 1331649577946812237L;
@@ -71,7 +69,7 @@ public class StateSystemFullHistoryTest {
             e.printStackTrace();
         }
         builder.run();
-        shs = (StateHistorySystem) builder.getSS();
+        ssb = builder.getStateSystemBuilder();
         builder.close(); /* Waits for the construction to finish */
     }
 
@@ -112,13 +110,13 @@ public class StateSystemFullHistoryTest {
     @Test
     public void testOpenExistingStateFile() throws IOException {
         IStateHistoryBackend hp2 = null;
-        StateHistorySystem shs2 = null;
+        IStateSystemBuilder ssb2 = null;
 
         /* 'newStateFile' should have already been created */
         hp2 = new HistoryTreeBackend(stateFile);
-        shs2 = new StateHistorySystem(hp2, false);
+        ssb2 = HistoryBuilder.openExistingHistory(hp2);
 
-        assertNotNull(shs2);
+        assertNotNull(ssb2);
         assertEquals(CtfTestFiles.startTime, hp2.getStartTime());
         assertEquals(CtfTestFiles.endTime, hp2.getEndTime());
     }
@@ -132,23 +130,23 @@ public class StateSystemFullHistoryTest {
         int quark, quark2, valueInt;
         String valueStr;
 
-        list = shs.loadStateAtTime(interestingTimestamp1);
+        list = ssb.loadStateAtTime(interestingTimestamp1);
 
-        quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         interval = list.get(quark);
         valueInt = interval.getStateValue().unboxInt();
         assertEquals(1397, valueInt);
 
-        quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
+        quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
         interval = list.get(quark);
         valueStr = interval.getStateValue().unboxStr();
         assertEquals("gdbus", valueStr);
 
         /* Query a stack attribute, has to be done in two passes */
-        quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_MODE_STACK);
+        quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_MODE_STACK);
         interval = list.get(quark);
         valueInt = interval.getStateValue().unboxInt(); /* The stack depth */
-        quark2 = shs.getQuarkRelative(quark, Integer.toString(valueInt));
+        quark2 = ssb.getQuarkRelative(quark, Integer.toString(valueInt));
         interval = list.get(quark2);
         valueStr = interval.getStateValue().unboxStr();
         assertTrue(valueStr.equals("sys_poll"));
@@ -173,8 +171,8 @@ public class StateSystemFullHistoryTest {
         ITmfStateInterval interval;
         String valueStr;
 
-        quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
-        interval = shs.querySingleState(timestamp, quark);
+        quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
+        interval = ssb.querySingleState(timestamp, quark);
         valueStr = interval.getStateValue().unboxStr();
         assertEquals("gdbus", valueStr);
     }
@@ -201,8 +199,8 @@ public class StateSystemFullHistoryTest {
         int quark;
         List<ITmfStateInterval> intervals;
 
-        quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
-        intervals = shs.queryHistoryRange(quark, time1, time2);
+        quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        intervals = ssb.queryHistoryRange(quark, time1, time2);
         assertEquals(487, intervals.size()); /* Number of context switches! */
         assertEquals(1685, intervals.get(100).getStateValue().unboxInt());
         assertEquals(1331668248427681372L, intervals.get(205).getEndTime());
@@ -218,11 +216,11 @@ public class StateSystemFullHistoryTest {
 
         List<ITmfStateInterval> intervals;
         
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.IRQ_STACK);
-        long ts1 = shs.getHistoryBackend().getStartTime(); /* start of the trace */
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.IRQ_STACK);
+        long ts1 = ssb.getStartTime(); /* start of the trace */
         long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid, but ignored */
 
-        intervals = shs.queryHistoryRange(quark, ts1, ts2);
+        intervals = ssb.queryHistoryRange(quark, ts1, ts2);
 
         /* Nb of IRQs on CPU 0 during the whole trace */
         assertEquals(1653, intervals.size());
@@ -241,8 +239,8 @@ public class StateSystemFullHistoryTest {
         int quark;
         List<ITmfStateInterval> intervals;
 
-        quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
-        intervals = shs.queryHistoryRange(quark, time1, time2, resolution);
+        quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        intervals = ssb.queryHistoryRange(quark, time1, time2, resolution);
         assertEquals(129, intervals.size()); /* Number of context switches! */
         assertEquals(1452, intervals.get(50).getStateValue().unboxInt());
         assertEquals(1331668248784789238L, intervals.get(100).getEndTime());
@@ -256,14 +254,14 @@ public class StateSystemFullHistoryTest {
     @Test(expected = TimeRangeException.class)
     public void testFullQueryInvalidTime1() throws TimeRangeException {
         long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC;
-        shs.loadStateAtTime(ts);
+        ssb.loadStateAtTime(ts);
 
     }
 
     @Test(expected = TimeRangeException.class)
     public void testFullQueryInvalidTime2() throws TimeRangeException {
         long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC;
-        shs.loadStateAtTime(ts);
+        ssb.loadStateAtTime(ts);
 
     }
 
@@ -271,40 +269,40 @@ public class StateSystemFullHistoryTest {
     public void testSingleQueryInvalidTime1()
             throws AttributeNotFoundException, TimeRangeException {
 
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC;
-        shs.querySingleState(ts, quark);
+        ssb.querySingleState(ts, quark);
     }
 
     @Test(expected = TimeRangeException.class)
     public void testSingleQueryInvalidTime2()
             throws AttributeNotFoundException, TimeRangeException {
 
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC;
-        shs.querySingleState(ts, quark);
+        ssb.querySingleState(ts, quark);
     }
 
     @Test(expected = TimeRangeException.class)
     public void testRangeQueryInvalidTime1() throws AttributeNotFoundException,
             TimeRangeException {
 
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         long ts1 = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
         long ts2 = CtfTestFiles.startTime + 1L * CtfTestFiles.NANOSECS_PER_SEC; /* valid */
 
-        shs.queryHistoryRange(quark, ts1, ts2);
+        ssb.queryHistoryRange(quark, ts1, ts2);
     }
 
     @Test(expected = TimeRangeException.class)
     public void testRangeQueryInvalidTime2() throws TimeRangeException,
             AttributeNotFoundException {
 
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         long ts1 = CtfTestFiles.startTime - 1L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
         long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
 
-        shs.queryHistoryRange(quark, ts1, ts2);
+        ssb.queryHistoryRange(quark, ts1, ts2);
     }
 
     /**
@@ -315,7 +313,7 @@ public class StateSystemFullHistoryTest {
     @Test(expected = AttributeNotFoundException.class)
     public void testQueryInvalidAttribute() throws AttributeNotFoundException {
 
-        shs.getQuarkAbsolute("There", "is", "no", "cow", "level");
+        ssb.getQuarkAbsolute("There", "is", "no", "cow", "level");
     }
 
     /**
@@ -332,8 +330,8 @@ public class StateSystemFullHistoryTest {
         ITmfStateInterval interval;
         int quark;
 
-        list = shs.loadStateAtTime(interestingTimestamp1);
-        quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        list = ssb.loadStateAtTime(interestingTimestamp1);
+        quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
         interval = list.get(quark);
 
         /* This is supposed to be an int value */
@@ -347,8 +345,8 @@ public class StateSystemFullHistoryTest {
         ITmfStateInterval interval;
         int quark;
 
-        list = shs.loadStateAtTime(interestingTimestamp1);
-        quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
+        list = ssb.loadStateAtTime(interestingTimestamp1);
+        quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
         interval = list.get(quark);
 
         /* This is supposed to be a String value */
@@ -357,14 +355,14 @@ public class StateSystemFullHistoryTest {
 
     @Test
     public void testFullAttributeName() throws AttributeNotFoundException {
-        int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
-        String name = shs.getFullAttributePath(quark);
+        int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+        String name = ssb.getFullAttributePath(quark);
         assertEquals(name, "CPUs/0/Current_thread");
     }
 
     @Test
     public void testGetQuarks_begin() {
-        List<Integer> list = shs.getQuarks("*", "1577", Attributes.EXEC_NAME);
+        List<Integer> list = ssb.getQuarks("*", "1577", Attributes.EXEC_NAME);
 
         assertEquals(1, list.size());
         assertEquals(Integer.valueOf(398), list.get(0));
@@ -372,7 +370,7 @@ public class StateSystemFullHistoryTest {
 
     @Test
     public void testGetQuarks_middle() {
-        List<Integer> list = shs.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME);
+        List<Integer> list = ssb.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME);
 
         assertEquals(Integer.valueOf(18), list.get(4));
         assertEquals(Integer.valueOf(54), list.get(10));
@@ -381,16 +379,9 @@ public class StateSystemFullHistoryTest {
 
     @Test
     public void testGetQuarks_end() {
-        List<Integer> list = shs.getQuarks(Attributes.THREADS, "1577", "*");
+        List<Integer> list = ssb.getQuarks(Attributes.THREADS, "1577", "*");
 
         assertEquals(3, list.size());
         assertEquals(Integer.valueOf(398), list.get(1));
     }
-
-    @Test
-    public void testDebugPrinting() throws FileNotFoundException {
-        PrintWriter pw = new PrintWriter(new File("/dev/null"));
-        shs.debugPrint(pw);
-        pw.close();
-    }
 }
index b812438f32d9513c3885044e204bb572bbfa9686..6e9a6e1cddd0eb60dd5e74fca7605b64b5cdfc85 100644 (file)
@@ -15,7 +15,6 @@ package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 import java.io.File;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedHistoryTreeBackend;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.HistoryBuilder;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput;
@@ -52,7 +51,7 @@ public class StateSystemFullThreadedHistoryTest extends
             e.printStackTrace();
         }
         builder.run();
-        shs = (StateHistorySystem) builder.getSS();
+        ssb = builder.getStateSystemBuilder();
         builder.close(); /* Waits for the construction to finish */
     }
 
index 7065cb62aded70fa7f3c7073788fce713e210d95..8f965f6df24cc03ff853710fa1944b19b35e5033 100644 (file)
@@ -21,9 +21,8 @@ import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngStrings;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.statesystem.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemBuilder;
 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
 import org.eclipse.linuxtools.tmf.core.statevalue.StateValueTypeException;
 import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
@@ -37,7 +36,7 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 class CtfKernelHandler implements Runnable {
 
     private final BlockingQueue<CtfTmfEvent> inQueue;
-    private StateSystem ss;
+    private IStateSystemBuilder ss;
 
     private CtfTmfEvent currentEvent;
 
@@ -60,14 +59,10 @@ class CtfKernelHandler implements Runnable {
         knownEventNames = fillEventNames();
     }
 
-    void assignStateSystem(StateSystem targetSS) {
+    void assignStateSystem(IStateSystemBuilder targetSS) {
         this.ss = targetSS;
     }
 
-    StateSystem getStateSystem() {
-        return ss;
-    }
-
     @Override
     public void run() {
         if (ss == null) {
@@ -94,16 +89,14 @@ class CtfKernelHandler implements Runnable {
 
     private void closeStateSystem() {
         /* Close the History system, if there is one */
-        if (ss.getClass() == StateHistorySystem.class) {
-            try {
-                ((StateHistorySystem) ss).closeHistory(currentEvent.getTimestamp().getValue());
-            } catch (TimeRangeException e) {
-                /*
-                 * Since we're using currentEvent.getTimestamp, this shouldn't
-                 * cause any problem
-                 */
-                e.printStackTrace();
-            }
+        try {
+            ss.closeHistory(currentEvent.getTimestamp().getValue());
+        } catch (TimeRangeException e) {
+            /*
+             * Since we're using currentEvent.getTimestamp, this shouldn't
+             * cause any problem
+             */
+            e.printStackTrace();
         }
     }
 
index 510f666d3f3c455f75c476917b46da81abd0fde2..ba742ac25c75e86b9b5f603d7e1f274edf8611db 100644 (file)
@@ -19,8 +19,8 @@ import java.util.concurrent.BlockingQueue;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemBuilder;
 
 /**
  * This is the state change input plugin for TMF's state system which handles
@@ -94,16 +94,11 @@ public class CtfKernelStateInput implements IStateChangeInput {
     }
 
     @Override
-    public void assignTargetStateSystem(StateSystem ss) {
-        eventHandler.assignStateSystem(ss);
+    public void assignTargetStateSystem(IStateSystemBuilder ssb) {
+        eventHandler.assignStateSystem(ssb);
         ssAssigned = true;
     }
 
-    @Override
-    public StateSystem getStateSystem() {
-        return eventHandler.getStateSystem();
-    }
-
     @Override
     public long getStartTime() {
         return traceReader.getCtfTmfTrace().getStartTime().getValue();
index 03fed9d9e21303295280aba61bb4de080fb194d7..64c2a3083128996ca33047226c0a8bc6d1d064f6 100644 (file)
@@ -19,7 +19,6 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem;
 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend;
 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedHistoryTreeBackend;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.HistoryBuilder;
@@ -51,11 +50,6 @@ public class CtfKernelTrace extends CtfTmfTrace {
         return true;
     }
 
-    @Override
-    public StateHistorySystem getStateSystem() {
-        return (StateHistorySystem) this.ss;
-    }
-
     @Override
     protected void buildStateSystem() throws TmfTraceException {
         /* Set up the path to the history tree file we'll use */
@@ -73,7 +67,7 @@ public class CtfKernelTrace extends CtfTmfTrace {
             /* Load an existing history */
             try {
                 htBackend = new HistoryTreeBackend(htFile);
-                this.ss = new StateHistorySystem(htBackend, false);
+                this.ss = HistoryBuilder.openExistingHistory(htBackend);
                 return;
             } catch (IOException e) {
                 /*
@@ -99,7 +93,7 @@ public class CtfKernelTrace extends CtfTmfTrace {
             throw new TmfTraceException(e.getMessage());
         }
 
-        this.ss = builder.getSS();
+        this.ss = builder.getStateSystemQuerier();
         builder.run(); /* Start the construction of the history */
 
         //FIXME We will have to call close() once we are notified that the
index ed7daf0896e0b0e66cd75f65cc2bdc152f2c2d93..6dbc66229dbadbe7ed0775fda372be0f3fc6ea04 100644 (file)
@@ -14,7 +14,7 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemQuerier;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -50,7 +50,7 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     protected CtfIterator iterator;
 
     /* Reference to the state system assigned to this trace */
-    protected StateSystem ss = null;
+    protected IStateSystemQuerier ss = null;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -324,14 +324,20 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
         return this.fResource;
     }
 
-    public StateSystem getStateSystem() {
+    public IStateSystemQuerier getStateSystem() {
         return this.ss;
     }
 
     CTFTrace getCTFTrace() {
         return fTrace;
     }
+    
 
+    /**
+     * Suppressing the warning, because the 'throws' will usually happen in
+     * sub-classes.
+     */
+    @SuppressWarnings("unused")
     protected void buildStateSystem() throws TmfTraceException {
         /*
          * Nothing is done in the basic implementation, please specify
index 4c69b6e669c1b4ac441d0109e94e10a062991cae..b195eb58e7778115e64f954441494598afedd1a5 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
 import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateHistoryBackend;
+import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateSystemBuilder;
 
 /**
  * This is the extension of the StateSystem, which will save the state intervals
@@ -36,14 +37,8 @@ import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateHistoryBackend;
  * @author alexmont
  * 
  */
-public class StateHistorySystem extends StateSystem {
-
-    /*
-     * Inherited from StateSystem
-     * 
-     * protected ArrayList<AttributeTreeNode> attributeList; protected
-     * TransientState transState; protected CurrentState curState;
-     */
+public class StateHistorySystem extends StateSystem implements
+        IStateSystemBuilder {
 
     /**
      * In addition, a state "history" system has a storage back-end from which
@@ -77,26 +72,17 @@ public class StateHistorySystem extends StateSystem {
         }
     }
 
-    public IStateHistoryBackend getHistoryBackend() {
-        return backend;
+    @Override
+    public long getStartTime() {
+        return backend.getStartTime();
     }
 
-    /**
-     * Method to close off the History Provider. This happens for example when
-     * we are done reading an off-line trace. First we close the TransientState,
-     * commit it to the Provider, mark it as inactive, then we write the
-     * Attribute Tree somewhere so we can reopen it later.
-     * 
-     * @param endTime
-     *            The requested End Time of the history, since it could be
-     *            bigger than the timestamp of the last event or state change we
-     *            have seen. All "ongoing" states will be extended until this
-     *            'endTime'.
-     * @throws TimeRangeException
-     *             If the passed endTime doesn't make sense (for example, if
-     *             it's earlier than the latest time) and the backend doesn't
-     *             know how to handle it.
-     */
+    @Override
+    public long getCurrentEndTime() {
+        return backend.getEndTime();
+    }
+
+    @Override
     public void closeHistory(long endTime) throws TimeRangeException {
         File attributeTreeFile;
         long attributeTreeFilePos;
@@ -127,23 +113,7 @@ public class StateHistorySystem extends StateSystem {
      * @name External query methods
      */
 
-    /**
-     * Load the complete state information at time 't' into the returned List.
-     * You can then get the intervals for single attributes by using
-     * List.get(n), where 'n' is the quark of the attribute.
-     * 
-     * On average if you need around 10 or more queries for the same timestamps,
-     * use this method. If you need less than 10 (for example, running many
-     * queries for the same attributes but at different timestamps), you might
-     * be better using the querySingleState() methods instead.
-     * 
-     * @param t
-     *            We will recreate the state information to what it was at time
-     *            t.
-     * @throws TimeRangeException
-     *             If the 't' parameter is outside of the range of the state
-     *             history.
-     */
+    @Override
     public synchronized List<ITmfStateInterval> loadStateAtTime(long t)
             throws TimeRangeException {
         List<ITmfStateInterval> stateInfo = new ArrayList<ITmfStateInterval>(
@@ -175,26 +145,7 @@ public class StateHistorySystem extends StateSystem {
         return stateInfo;
     }
 
-    /**
-     * Singular query method. This one does not update the whole stateInfo
-     * vector, like loadStateAtTimes() does. It only searches for one specific
-     * entry in the state history.
-     * 
-     * It should be used when you only want very few entries, instead of the
-     * whole state (or many entries, but all at different timestamps). If you do
-     * request many entries all at the same time, you should use the
-     * conventional loadStateAtTime() + List.get() method.
-     * 
-     * @param t
-     *            The timestamp at which we want the state
-     * @param attributeQuark
-     *            Which attribute we want to get the state of
-     * @return The StateInterval representing the state
-     * @throws TimeRangeException
-     *             If 't' is invalid
-     * @throws AttributeNotFoundException
-     *             If the requested quark does not exist in the model
-     */
+    @Override
     public ITmfStateInterval querySingleState(long t, int attributeQuark)
             throws AttributeNotFoundException, TimeRangeException {
         ITmfStateInterval ret;
@@ -208,29 +159,7 @@ public class StateHistorySystem extends StateSystem {
         return ret;
     }
 
-    /**
-     * Return a list of state intervals, containing the "history" of a given
-     * attribute between timestamps t1 and t2. The list will be ordered by
-     * ascending time.
-     * 
-     * Note that contrary to loadStateAtTime(), the returned list here is in the
-     * "direction" of time (and not in the direction of attributes, as is the
-     * case with loadStateAtTime()).
-     * 
-     * @param attributeQuark
-     *            Which attribute this query is interested in
-     * @param t1
-     *            Start time of the range query
-     * @param t2
-     *            Target end time of the query. If t2 is greater than the end of
-     *            the trace, we will return what we have up to the end of the
-     *            history.
-     * @return The List of state intervals that happened between t1 and t2
-     * @throws TimeRangeException
-     *             If t1 is invalid, or if t2 <= t1
-     * @throws AttributeNotFoundException
-     *             If the requested quark does not exist in the model.
-     */
+    @Override
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2) throws TimeRangeException,
             AttributeNotFoundException {
@@ -268,27 +197,7 @@ public class StateHistorySystem extends StateSystem {
         return intervals;
     }
 
-    /**
-     * Return the state history of a given attribute, but with at most one
-     * update per "resolution". This can be useful for populating views (where
-     * it's useless to have more than one query per pixel, for example).
-     * 
-     * @param attributeQuark
-     *            Which attribute this query is interested in
-     * @param t1
-     *            Start time of the range query
-     * @param t2
-     *            Target end time of the query. If t2 is greater than the end of
-     *            the trace, we will return what we have up to the end of the
-     *            history.
-     * @param resolution
-     *            The "step" of this query
-     * @return The List of states that happened between t1 and t2
-     * @throws TimeRangeException
-     *             If t1 is invalid, or if t2 <= t1
-     * @throws AttributeNotFoundException
-     *             If the attribute doesn't exist
-     */
+    @Override
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2, long resolution) throws TimeRangeException,
             AttributeNotFoundException {
index dab7ab0bf1e37d44bf1b42458d036be4918905e2..0e714698571eb2ee18aed979094d4a2673013413 100644 (file)
@@ -28,6 +28,8 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
  * will be built underneath (no information will be saved to disk) and it will
  * only be able to respond to queries to the current, latest time.
  * 
+ * (See IStateSystemQuerier and IStateSystemBuilder for the Javadoc.)
+ * 
  * @author alexmont
  * 
  */
@@ -51,133 +53,29 @@ public class StateSystem {
      * @name Quark-retrieving methods
      */
 
-    /**
-     * Basic quark-retrieving method. Pass an attribute in parameter as an array
-     * of strings, the matching quark will be returned.
-     * 
-     * This version will NOT create any new attributes. If an invalid attribute
-     * is requested, an exception will be thrown. This should ideally be used
-     * for doing read-only operations on the system, like queries for example.
-     * 
-     * @param attribute
-     *            Attribute given as its full path in the Attribute Tree
-     * @return The quark of the requested attribute, if it existed.
-     * @throws AttributeNotFoundException
-     *             This exception is thrown if the requested attribute simply
-     *             did not exist in the system.
-     */
     public int getQuarkAbsolute(String... attribute)
             throws AttributeNotFoundException {
         return attributeTree.getQuarkDontAdd(-1, attribute);
     }
 
-    /**
-     * Basic quark-retrieving method. Pass an attribute in parameter as an array
-     * of strings, the matching quark will be returned.
-     * 
-     * This version WILL create new attributes: if the attribute passed in
-     * parameter is new in the system, it will be added and its new quark will
-     * be returned.
-     * 
-     * @param attribute
-     *            Attribute given as its full path in the Attribute Tree
-     * @return The quark of the attribute (which either existed or just got
-     *         created)
-     */
     public int getQuarkAbsoluteAndAdd(String... attribute) {
         return attributeTree.getQuarkAndAdd(-1, attribute);
     }
 
-    /**
-     * "Relative path" quark-getting method. Instead of specifying a full path,
-     * if you know the path is relative to another attribute for which you
-     * already have the quark, use this for better performance.
-     * 
-     * This is useful for cases where a lot of modifications or queries will
-     * originate from the same branch of the attribute tree : the common part of
-     * the path won't have to be re-hashed for every access.
-     * 
-     * This version will NOT create any new attributes. If an invalid attribute
-     * is requested, an exception will be thrown. This should ideally be used
-     * for doing read-only operations on the system, like queries for example.
-     * 
-     * @param startingNodeQuark
-     *            The quark of the attribute from which 'subPath' originates.
-     * @param subPath
-     *            "Rest" of the path to get to the final attribute
-     * @return The matching quark, if it existed
-     * @throws AttributeNotFoundException
-     */
     public int getQuarkRelative(int startingNodeQuark, String... subPath)
             throws AttributeNotFoundException {
         return attributeTree.getQuarkDontAdd(startingNodeQuark, subPath);
     }
 
-    /**
-     * "Relative path" quark-getting method. Instead of specifying a full path,
-     * if you know the path is relative to another attribute for which you
-     * already have the quark, use this for better performance.
-     * 
-     * This is useful for cases where a lot of modifications or queries will
-     * originate from the same branch of the attribute tree : the common part of
-     * the path won't have to be re-hashed for every access.
-     * 
-     * This version WILL create new attributes: if the attribute passed in
-     * parameter is new in the system, it will be added and its new quark will
-     * be returned.
-     * 
-     * @param startingNodeQuark
-     *            The quark of the attribute from which 'subPath' originates.
-     * @param subPath
-     *            "Rest" of the path to get to the final attribute
-     * @return The matching quark, either if it's new of just got created.
-     */
     public int getQuarkRelativeAndAdd(int startingNodeQuark, String... subPath) {
         return attributeTree.getQuarkAndAdd(startingNodeQuark, subPath);
     }
 
-    /**
-     * Return the sub-attributes of the target attribute, as a List of quarks.
-     * 
-     * @param quark
-     *            The attribute of which you want to sub-attributes. You can use
-     *            "-1" here to specify the root node.
-     * @param recursive
-     *            True if you want all recursive sub-attributes, false if you
-     *            only want the first level.
-     * @return A List of integers, matching the quarks of the sub-attributes.
-     * @throws AttributeNotFoundException
-     *             If the quark was not existing or invalid.
-     */
     public List<Integer> getSubAttributes(int quark, boolean recursive)
             throws AttributeNotFoundException {
         return attributeTree.getSubAttributes(quark, recursive);
     }
 
-    /**
-     * Batch quark-retrieving method. This method allows you to specify a path
-     * pattern which includes a wildcard "*" somewhere. It will check all the
-     * existing attributes in the attribute tree and return those who match the
-     * pattern.
-     * 
-     * For example, passing ("Threads", "*", "Exec_mode") will return the list
-     * of quarks for attributes "Threads/1000/Exec_mode",
-     * "Threads/1500/Exec_mode", and so on, depending on what exists at this
-     * time in the attribute tree.
-     * 
-     * If no wildcard is specified, the behavior is the same as
-     * getQuarkAbsolute() (except it will return a List with one entry). This
-     * method will never create new attributes.
-     * 
-     * Only one wildcard "*" is supported at this time.
-     * 
-     * @param pattern
-     *            The array of strings representing the pattern to look for. It
-     *            should ideally contain one entry that is only a "*".
-     * @return A List of attribute quarks, representing attributes that matched
-     *         the pattern. If no attribute matched, the list will be empty (but
-     *         not null).
-     */
     public List<Integer> getQuarks(String... pattern) {
         List<Integer> quarks = new LinkedList<Integer>();
         List<String> prefix = new LinkedList<String>();
@@ -266,48 +164,12 @@ public class StateSystem {
      * @name External methods related to insertions in the history -
      */
 
-    /**
-     * Basic attribute modification method, we simply specify a new value, for a
-     * given attribute, effective at the given timestamp.
-     * 
-     * @param t
-     *            Timestamp of the state change
-     * @param value
-     *            The State Value we want to assign to the attribute
-     * @param attributeQuark
-     *            Integer value of the quark corresponding to the attribute we
-     *            want to modify
-     * @throws TimeRangeException
-     *             If the requested time is outside of the trace's range
-     * @throws AttributeNotFoundException
-     *             If the requested attribute quark is invalid
-     * @throws StateValueTypeException
-     *             If the inserted state value's type does not match what is
-     *             already assigned to this attribute.
-     */
     public void modifyAttribute(long t, ITmfStateValue value, int attributeQuark)
             throws TimeRangeException, AttributeNotFoundException,
             StateValueTypeException {
         transState.processStateChange(t, value, attributeQuark);
     }
 
-    /**
-     * Increment attribute method. Reads the current value of a given integer
-     * attribute (this value is right now in the Transient State), and increment
-     * it by 1. Useful for statistics.
-     * 
-     * @param t
-     *            Timestamp of the state change
-     * @param attributeQuark
-     *            Attribute to increment. If it doesn't exist it will be added,
-     *            with a new value of 1.
-     * @throws StateValueTypeException
-     *             If the attribute already exists but is not of type Integer
-     * @throws TimeRangeException
-     *             If the given timestamp is invalid
-     * @throws AttributeNotFoundException
-     *             If the quark is invalid
-     */
     public void incrementAttribute(long t, int attributeQuark)
             throws StateValueTypeException, TimeRangeException,
             AttributeNotFoundException {
@@ -317,28 +179,6 @@ public class StateSystem {
                 attributeQuark);
     }
 
-    /**
-     * "Push" helper method. This uses the given integer attribute as a stack:
-     * The value of that attribute will represent the stack depth (always >= 1).
-     * Sub-attributes will be created, their base-name will be the position in
-     * the stack (1, 2, etc.) and their value will be the state value 'value'
-     * that was pushed to this position.
-     * 
-     * @param t
-     *            Timestamp of the state change
-     * @param value
-     *            State value to assign to this stack position.
-     * @param attributeQuark
-     *            The base attribute to use as a stack. If it does not exist if
-     *            will be created (with depth = 1)
-     * @throws TimeRangeException
-     *             If the requested timestamp is invalid
-     * @throws AttributeNotFoundException
-     *             If the attribute is invalid
-     * @throws StateValueTypeException
-     *             If the attribute 'attributeQuark' already exists, but is not
-     *             of integer type.
-     */
     public void pushAttribute(long t, ITmfStateValue value, int attributeQuark)
             throws TimeRangeException, AttributeNotFoundException,
             StateValueTypeException {
@@ -377,24 +217,6 @@ public class StateSystem {
         modifyAttribute(t, value, subAttributeQuark);
     }
 
-    /**
-     * Antagonist of the pushAttribute(), pops the top-most attribute on the
-     * stack-attribute. If this brings it back to depth = 0, the attribute is
-     * kept with depth = 0. If the value is already 0, or if the attribute
-     * doesn't exist, nothing is done.
-     * 
-     * @param t
-     *            Timestamp of the state change
-     * @param attributeQuark
-     *            Quark of the stack-attribute to pop
-     * @throws AttributeNotFoundException
-     *             If the attribute is invalid
-     * @throws TimeRangeException
-     *             If the timestamp is invalid
-     * @throws StateValueTypeException
-     *             If the target attribute already exists, but its state value
-     *             type is invalid (not an integer)
-     */
     public void popAttribute(long t, int attributeQuark)
             throws AttributeNotFoundException, TimeRangeException,
             StateValueTypeException {
@@ -443,20 +265,6 @@ public class StateSystem {
         removeAttribute(t, subAttributeQuark);
     }
 
-    /**
-     * Remove attribute method. Similar to the above modify- methods, with value
-     * = 0 / null, except we will also "nullify" all the sub-contents of the
-     * requested path (a bit like "rm -rf")
-     * 
-     * @param t
-     *            Timestamp of the state change
-     * @param attributeQuark
-     *            Attribute to remove
-     * @throws TimeRangeException
-     *             If the timestamp is invalid
-     * @throws AttributeNotFoundException
-     *             If the quark is invalid
-     */
     public void removeAttribute(long t, int attributeQuark)
             throws TimeRangeException, AttributeNotFoundException {
         assert (attributeQuark >= 0);
@@ -488,73 +296,20 @@ public class StateSystem {
      * @name "Current" query/update methods -
      */
 
-    /**
-     * Returns the current state value we have (in the Transient State) for the
-     * given attribute.
-     * 
-     * This is useful even for a StateHistorySystem, as we are guaranteed it
-     * will only do a memory access and not go look on disk (and we don't even
-     * have to provide a timestamp!)
-     * 
-     * @param attributeQuark
-     *            For which attribute we want the current state
-     * @return The State value that's "current" for this attribute
-     * @throws AttributeNotFoundException
-     *             If the requested attribute is invalid
-     */
     public ITmfStateValue queryOngoingState(int attributeQuark)
             throws AttributeNotFoundException {
         return transState.getOngoingStateValue(attributeQuark);
     }
 
-    /**
-     * Modify a current "ongoing" state (instead of inserting a state change,
-     * like modifyAttribute() and others).
-     * 
-     * This can be used to update the value of a previous state change, for
-     * example when we get information at the end of the state and not at the
-     * beginning. (return values of system calls, etc.)
-     * 
-     * Note that past states can only be modified while they are still in
-     * memory, so only the "current state" can be updated. Once they get
-     * committed to disk (by inserting a new state change) it becomes too late.
-     * 
-     * @param newValue
-     *            The new value that will overwrite the "current" one.
-     * @param attributeQuark
-     *            For which attribute in the system
-     * @throws AttributeNotFoundException
-     *             If the requested attribute is invalid
-     */
     public void updateOngoingState(ITmfStateValue newValue, int attributeQuark)
             throws AttributeNotFoundException {
         transState.changeOngoingStateValue(attributeQuark, newValue);
     }
 
-    /**
-     * Return the name assigned to this quark. This returns only the "basename",
-     * not the complete path to this attribute.
-     * 
-     * @param attributeQuark
-     *            The quark for which we want the name
-     * @return The name of the quark
-     */
     public String getAttributeName(int attributeQuark) {
         return attributeTree.getAttributeName(attributeQuark);
     }
 
-    /**
-     * @name Debugging methods
-     */
-
-    /**
-     * This returns the slash-separated path of an attribute by providing its
-     * quark
-     * 
-     * @param attributeQuark
-     *            The quark of the attribute we want
-     * @return One single string separated with '/', like a filesystem path
-     */
     public String getFullAttributePath(int attributeQuark) {
         return attributeTree.getFullAttributeName(attributeQuark);
     }
index 3d18654602b84a361a8c0f298269126c052d3866..122eb4a4281a50c16634a153c11e3b60fa961679 100644 (file)
@@ -15,7 +15,6 @@ package org.eclipse.linuxtools.tmf.core.statesystem.helpers;
 import java.io.IOException;
 
 import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 
 /**
  * This is the high-level wrapper around the State History and its input and
@@ -31,7 +30,7 @@ import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
 public class HistoryBuilder implements Runnable {
 
     private final IStateChangeInput sci;
-    private final StateSystem ss;
+    private final StateHistorySystem shs;
     private final IStateHistoryBackend hb;
 
     private final Thread sciThread;
@@ -51,21 +50,33 @@ public class HistoryBuilder implements Runnable {
     public HistoryBuilder(IStateChangeInput stateChangeInput,
             IStateHistoryBackend backend) throws IOException {
         assert (stateChangeInput != null);
-        /* "backend" can be null, this implies no history */
-        sci = stateChangeInput;
+        assert (backend != null);
 
-        if (backend == null) {
-            hb = null;
-            ss = new StateSystem();
-        } else {
-            hb = backend;
-            ss = new StateHistorySystem(hb, true);
-        }
+        sci = stateChangeInput;
+        hb = backend;
+        shs = new StateHistorySystem(hb, true);
 
-        sci.assignTargetStateSystem(ss);
+        sci.assignTargetStateSystem(shs);
         sciThread = new Thread(sci, "Input Plugin"); //$NON-NLS-1$
     }
 
+    /**
+     * Factory-style method to open an existing history, you only have to
+     * provide the already-instantiated IStateHistoryBackend object.
+     * 
+     * @param hb
+     *            The history-backend object
+     * @return A IStateSystemBuilder reference to the new state system. If you
+     *         will only run queries on this history, you should *definitely*
+     *         cast it to IStateSystemQuerier.
+     * @throws IOException
+     *             If there was something wrong.
+     */
+    public static IStateSystemBuilder openExistingHistory(
+            IStateHistoryBackend hb) throws IOException {
+        return new StateHistorySystem(hb, false);
+    }
+
     @Override
     public void run() {
         sciThread.start();
@@ -85,13 +96,23 @@ public class HistoryBuilder implements Runnable {
     }
 
     /**
-     * Return the StateSystem (or StateHistorySystem) object that was created by
-     * this builder. You will need this reference to run queries.
+     * Return a read/write reference to the state system object that was
+     * created.
+     * 
+     * @return Reference to the state system, with access to everything.
+     */
+    public IStateSystemBuilder getStateSystemBuilder() {
+        return shs;
+    }
+
+    /**
+     * Return a read-only reference to the state system object that was created.
      * 
-     * @return The StateSystem that was generated
+     * @return Reference to the state system, but only with the query methods
+     *         available.
      */
-    public StateSystem getSS() {
-        return ss;
+    public IStateSystemQuerier getStateSystemQuerier() {
+        return shs;
     }
 
 }
\ No newline at end of file
index dfd7a29534b3b31fe8a2462f70503b5b2f7fa611..fe4d4b57fe4876268d1dc24472548f20d0a3250e 100644 (file)
@@ -12,8 +12,6 @@
 
 package org.eclipse.linuxtools.tmf.core.statesystem.helpers;
 
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystem;
-
 /**
  * This is the interface used to define the "state change input", which is the
  * main type of input that goes in the state system.
@@ -42,15 +40,7 @@ public interface IStateChangeInput extends Runnable {
      * 
      * This needs to be called before .run()!
      * 
-     * @param ss
-     */
-    public void assignTargetStateSystem(StateSystem ss);
-
-    /**
-     * Return the State System that was assigned to this SCI.
-     * 
-     * @return The target state system
+     * @param ssb
      */
-    public StateSystem getStateSystem();
-
+    public void assignTargetStateSystem(IStateSystemBuilder ssb);
 }
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemBuilder.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemBuilder.java
new file mode 100644 (file)
index 0000000..61e4f00
--- /dev/null
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * 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:
+ *   Alexandre Montplaisir - Initial API
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statesystem.helpers;
+
+import org.eclipse.linuxtools.tmf.core.statesystem.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.statesystem.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.tmf.core.statevalue.StateValueTypeException;
+
+/**
+ * This is the external interface to build or modify an existing state history.
+ * 
+ * It extends IStateSystemEnquirer, so you can still use it for reading the
+ * history, but it also provides write-access to it with the quark-creating and
+ * state-change insertion methods.
+ * 
+ * @author alexmont
+ * 
+ */
+public interface IStateSystemBuilder extends IStateSystemQuerier {
+
+    /**
+     * @name Read/write quark-getting methods
+     */
+
+    /**
+     * Basic quark-retrieving method. Pass an attribute in parameter as an array
+     * of strings, the matching quark will be returned.
+     * 
+     * This version WILL create new attributes: if the attribute passed in
+     * parameter is new in the system, it will be added and its new quark will
+     * be returned.
+     * 
+     * @param attribute
+     *            Attribute given as its full path in the Attribute Tree
+     * @return The quark of the attribute (which either existed or just got
+     *         created)
+     */
+    public int getQuarkAbsoluteAndAdd(String... attribute);
+
+    /**
+     * "Relative path" quark-getting method. Instead of specifying a full path,
+     * if you know the path is relative to another attribute for which you
+     * already have the quark, use this for better performance.
+     * 
+     * This is useful for cases where a lot of modifications or queries will
+     * originate from the same branch of the attribute tree : the common part of
+     * the path won't have to be re-hashed for every access.
+     * 
+     * This version WILL create new attributes: if the attribute passed in
+     * parameter is new in the system, it will be added and its new quark will
+     * be returned.
+     * 
+     * @param startingNodeQuark
+     *            The quark of the attribute from which 'subPath' originates.
+     * @param subPath
+     *            "Rest" of the path to get to the final attribute
+     * @return The matching quark, either if it's new of just got created.
+     */
+    public int getQuarkRelativeAndAdd(int startingNodeQuark, String... subPath);
+
+    /**
+     * @name State-changing methods
+     */
+
+    /**
+     * Modify a current "ongoing" state (instead of inserting a state change,
+     * like modifyAttribute() and others).
+     * 
+     * This can be used to update the value of a previous state change, for
+     * example when we get information at the end of the state and not at the
+     * beginning. (return values of system calls, etc.)
+     * 
+     * Note that past states can only be modified while they are still in
+     * memory, so only the "current state" can be updated. Once they get
+     * committed to disk (by inserting a new state change) it becomes too late.
+     * 
+     * @param newValue
+     *            The new value that will overwrite the "current" one.
+     * @param attributeQuark
+     *            For which attribute in the system
+     * @throws AttributeNotFoundException
+     *             If the requested attribute is invalid
+     */
+    public void updateOngoingState(ITmfStateValue newValue, int attributeQuark)
+            throws AttributeNotFoundException;
+
+    /**
+     * Basic attribute modification method, we simply specify a new value, for a
+     * given attribute, effective at the given timestamp.
+     * 
+     * @param t
+     *            Timestamp of the state change
+     * @param value
+     *            The State Value we want to assign to the attribute
+     * @param attributeQuark
+     *            Integer value of the quark corresponding to the attribute we
+     *            want to modify
+     * @throws TimeRangeException
+     *             If the requested time is outside of the trace's range
+     * @throws AttributeNotFoundException
+     *             If the requested attribute quark is invalid
+     * @throws StateValueTypeException
+     *             If the inserted state value's type does not match what is
+     *             already assigned to this attribute.
+     */
+    public void modifyAttribute(long t, ITmfStateValue value, int attributeQuark)
+            throws TimeRangeException, AttributeNotFoundException,
+            StateValueTypeException;
+
+    /**
+     * Increment attribute method. Reads the current value of a given integer
+     * attribute (this value is right now in the Transient State), and increment
+     * it by 1. Useful for statistics.
+     * 
+     * @param t
+     *            Timestamp of the state change
+     * @param attributeQuark
+     *            Attribute to increment. If it doesn't exist it will be added,
+     *            with a new value of 1.
+     * @throws StateValueTypeException
+     *             If the attribute already exists but is not of type Integer
+     * @throws TimeRangeException
+     *             If the given timestamp is invalid
+     * @throws AttributeNotFoundException
+     *             If the quark is invalid
+     */
+    public void incrementAttribute(long t, int attributeQuark)
+            throws StateValueTypeException, TimeRangeException,
+            AttributeNotFoundException;
+
+    /**
+     * "Push" helper method. This uses the given integer attribute as a stack:
+     * The value of that attribute will represent the stack depth (always >= 1).
+     * Sub-attributes will be created, their base-name will be the position in
+     * the stack (1, 2, etc.) and their value will be the state value 'value'
+     * that was pushed to this position.
+     * 
+     * @param t
+     *            Timestamp of the state change
+     * @param value
+     *            State value to assign to this stack position.
+     * @param attributeQuark
+     *            The base attribute to use as a stack. If it does not exist if
+     *            will be created (with depth = 1)
+     * @throws TimeRangeException
+     *             If the requested timestamp is invalid
+     * @throws AttributeNotFoundException
+     *             If the attribute is invalid
+     * @throws StateValueTypeException
+     *             If the attribute 'attributeQuark' already exists, but is not
+     *             of integer type.
+     */
+    public void pushAttribute(long t, ITmfStateValue value, int attributeQuark)
+            throws TimeRangeException, AttributeNotFoundException,
+            StateValueTypeException;
+
+    /**
+     * Antagonist of the pushAttribute(), pops the top-most attribute on the
+     * stack-attribute. If this brings it back to depth = 0, the attribute is
+     * kept with depth = 0. If the value is already 0, or if the attribute
+     * doesn't exist, nothing is done.
+     * 
+     * @param t
+     *            Timestamp of the state change
+     * @param attributeQuark
+     *            Quark of the stack-attribute to pop
+     * @throws AttributeNotFoundException
+     *             If the attribute is invalid
+     * @throws TimeRangeException
+     *             If the timestamp is invalid
+     * @throws StateValueTypeException
+     *             If the target attribute already exists, but its state value
+     *             type is invalid (not an integer)
+     */
+    public void popAttribute(long t, int attributeQuark)
+            throws AttributeNotFoundException, TimeRangeException,
+            StateValueTypeException;
+
+    /**
+     * Remove attribute method. Similar to the above modify- methods, with value
+     * = 0 / null, except we will also "nullify" all the sub-contents of the
+     * requested path (a bit like "rm -rf")
+     * 
+     * @param t
+     *            Timestamp of the state change
+     * @param attributeQuark
+     *            Attribute to remove
+     * @throws TimeRangeException
+     *             If the timestamp is invalid
+     * @throws AttributeNotFoundException
+     *             If the quark is invalid
+     */
+    public void removeAttribute(long t, int attributeQuark)
+            throws TimeRangeException, AttributeNotFoundException;
+
+    /**
+     * Method to close off the History Provider. This happens for example when
+     * we are done reading an off-line trace. First we close the TransientState,
+     * commit it to the Provider, mark it as inactive, then we write the
+     * Attribute Tree somewhere so we can reopen it later.
+     * 
+     * @param endTime
+     *            The requested End Time of the history, since it could be
+     *            bigger than the timestamp of the last event or state change we
+     *            have seen. All "ongoing" states will be extended until this
+     *            'endTime'.
+     * @throws TimeRangeException
+     *             If the passed endTime doesn't make sense (for example, if
+     *             it's earlier than the latest time) and the backend doesn't
+     *             know how to handle it.
+     */
+    public void closeHistory(long endTime) throws TimeRangeException;
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemQuerier.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateSystemQuerier.java
new file mode 100644 (file)
index 0000000..01cf0e5
--- /dev/null
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * 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:
+ *   Alexandre Montplaisir - Initial API
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.statesystem.helpers;
+
+import java.util.List;
+
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.statesystem.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.statesystem.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+
+/**
+ * This is the read-only interface to the generic state system. It contains all
+ * the read-only quark-getting methods, as well as the history-querying ones.
+ * 
+ * @author alexmont
+ * 
+ */
+public interface IStateSystemQuerier {
+
+    /**
+     * Return the start time of this history. It usually matches the start time
+     * of the original trace.
+     * 
+     * @return The history's registered start time
+     */
+    public long getStartTime();
+
+    /**
+     * Return the current end time of the history.
+     * 
+     * @return
+     */
+    public long getCurrentEndTime();
+
+    /**
+     * @name Read-only quark-getting methods
+     */
+
+    /**
+     * Basic quark-retrieving method. Pass an attribute in parameter as an array
+     * of strings, the matching quark will be returned.
+     * 
+     * This version will NOT create any new attributes. If an invalid attribute
+     * is requested, an exception will be thrown.
+     * 
+     * @param attribute
+     *            Attribute given as its full path in the Attribute Tree
+     * @return The quark of the requested attribute, if it existed.
+     * @throws AttributeNotFoundException
+     *             This exception is thrown if the requested attribute simply
+     *             did not exist in the system.
+     */
+    public int getQuarkAbsolute(String... attribute)
+            throws AttributeNotFoundException;
+
+    /**
+     * "Relative path" quark-getting method. Instead of specifying a full path,
+     * if you know the path is relative to another attribute for which you
+     * already have the quark, use this for better performance.
+     * 
+     * This is useful for cases where a lot of modifications or queries will
+     * originate from the same branch of the attribute tree : the common part of
+     * the path won't have to be re-hashed for every access.
+     * 
+     * This version will NOT create any new attributes. If an invalid attribute
+     * is requested, an exception will be thrown.
+     * 
+     * @param startingNodeQuark
+     *            The quark of the attribute from which 'subPath' originates.
+     * @param subPath
+     *            "Rest" of the path to get to the final attribute
+     * @return The matching quark, if it existed
+     * @throws AttributeNotFoundException
+     */
+    public int getQuarkRelative(int startingNodeQuark, String... subPath)
+            throws AttributeNotFoundException;
+
+    /**
+     * Return the sub-attributes of the target attribute, as a List of quarks.
+     * 
+     * @param quark
+     *            The attribute of which you want to sub-attributes. You can use
+     *            "-1" here to specify the root node.
+     * @param recursive
+     *            True if you want all recursive sub-attributes, false if you
+     *            only want the first level.
+     * @return A List of integers, matching the quarks of the sub-attributes.
+     * @throws AttributeNotFoundException
+     *             If the quark was not existing or invalid.
+     */
+    public List<Integer> getSubAttributes(int quark, boolean recursive)
+            throws AttributeNotFoundException;
+
+    /**
+     * Batch quark-retrieving method. This method allows you to specify a path
+     * pattern which includes a wildcard "*" somewhere. It will check all the
+     * existing attributes in the attribute tree and return those who match the
+     * pattern.
+     * 
+     * For example, passing ("Threads", "*", "Exec_mode") will return the list
+     * of quarks for attributes "Threads/1000/Exec_mode",
+     * "Threads/1500/Exec_mode", and so on, depending on what exists at this
+     * time in the attribute tree.
+     * 
+     * If no wildcard is specified, the behavior is the same as
+     * getQuarkAbsolute() (except it will return a List with one entry). This
+     * method will never create new attributes.
+     * 
+     * Only one wildcard "*" is supported at this time.
+     * 
+     * @param pattern
+     *            The array of strings representing the pattern to look for. It
+     *            should ideally contain one entry that is only a "*".
+     * @return A List of attribute quarks, representing attributes that matched
+     *         the pattern. If no attribute matched, the list will be empty (but
+     *         not null).
+     */
+    public List<Integer> getQuarks(String... pattern);
+
+    /**
+     * Return the name assigned to this quark. This returns only the "basename",
+     * not the complete path to this attribute.
+     * 
+     * @param attributeQuark
+     *            The quark for which we want the name
+     * @return The name of the quark
+     */
+    public String getAttributeName(int attributeQuark);
+
+    /**
+     * This returns the slash-separated path of an attribute by providing its
+     * quark
+     * 
+     * @param attributeQuark
+     *            The quark of the attribute we want
+     * @return One single string separated with '/', like a filesystem path
+     */
+    public String getFullAttributePath(int attributeQuark);
+
+    /**
+     * @name Query methods
+     */
+
+    /**
+     * Returns the current state value we have (in the Transient State) for the
+     * given attribute.
+     * 
+     * This is useful even for a StateHistorySystem, as we are guaranteed it
+     * will only do a memory access and not go look on disk (and we don't even
+     * have to provide a timestamp!)
+     * 
+     * @param attributeQuark
+     *            For which attribute we want the current state
+     * @return The State value that's "current" for this attribute
+     * @throws AttributeNotFoundException
+     *             If the requested attribute is invalid
+     */
+    public ITmfStateValue queryOngoingState(int attributeQuark)
+            throws AttributeNotFoundException;
+
+    /**
+     * Load the complete state information at time 't' into the returned List.
+     * You can then get the intervals for single attributes by using
+     * List.get(n), where 'n' is the quark of the attribute.
+     * 
+     * On average if you need around 10 or more queries for the same timestamps,
+     * use this method. If you need less than 10 (for example, running many
+     * queries for the same attributes but at different timestamps), you might
+     * be better using the querySingleState() methods instead.
+     * 
+     * @param t
+     *            We will recreate the state information to what it was at time
+     *            t.
+     * @throws TimeRangeException
+     *             If the 't' parameter is outside of the range of the state
+     *             history.
+     */
+    public List<ITmfStateInterval> loadStateAtTime(long t)
+            throws TimeRangeException;
+
+    /**
+     * Singular query method. This one does not update the whole stateInfo
+     * vector, like loadStateAtTimes() does. It only searches for one specific
+     * entry in the state history.
+     * 
+     * It should be used when you only want very few entries, instead of the
+     * whole state (or many entries, but all at different timestamps). If you do
+     * request many entries all at the same time, you should use the
+     * conventional loadStateAtTime() + List.get() method.
+     * 
+     * @param t
+     *            The timestamp at which we want the state
+     * @param attributeQuark
+     *            Which attribute we want to get the state of
+     * @return The StateInterval representing the state
+     * @throws TimeRangeException
+     *             If 't' is invalid
+     * @throws AttributeNotFoundException
+     *             If the requested quark does not exist in the model
+     */
+    public ITmfStateInterval querySingleState(long t, int attributeQuark)
+            throws AttributeNotFoundException, TimeRangeException;
+
+    /**
+     * Return a list of state intervals, containing the "history" of a given
+     * attribute between timestamps t1 and t2. The list will be ordered by
+     * ascending time.
+     * 
+     * Note that contrary to loadStateAtTime(), the returned list here is in the
+     * "direction" of time (and not in the direction of attributes, as is the
+     * case with loadStateAtTime()).
+     * 
+     * @param attributeQuark
+     *            Which attribute this query is interested in
+     * @param t1
+     *            Start time of the range query
+     * @param t2
+     *            Target end time of the query. If t2 is greater than the end of
+     *            the trace, we will return what we have up to the end of the
+     *            history.
+     * @return The List of state intervals that happened between t1 and t2
+     * @throws TimeRangeException
+     *             If t1 is invalid, or if t2 <= t1
+     * @throws AttributeNotFoundException
+     *             If the requested quark does not exist in the model.
+     */
+    public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+            long t1, long t2) throws TimeRangeException,
+            AttributeNotFoundException;
+
+    /**
+     * Return the state history of a given attribute, but with at most one
+     * update per "resolution". This can be useful for populating views (where
+     * it's useless to have more than one query per pixel, for example).
+     * 
+     * @param attributeQuark
+     *            Which attribute this query is interested in
+     * @param t1
+     *            Start time of the range query
+     * @param t2
+     *            Target end time of the query. If t2 is greater than the end of
+     *            the trace, we will return what we have up to the end of the
+     *            history.
+     * @param resolution
+     *            The "step" of this query
+     * @return The List of states that happened between t1 and t2
+     * @throws TimeRangeException
+     *             If t1 is invalid, or if t2 <= t1
+     * @throws AttributeNotFoundException
+     *             If the attribute doesn't exist
+     */
+    public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+            long t1, long t2, long resolution) throws TimeRangeException,
+            AttributeNotFoundException;
+}
This page took 0.063868 seconds and 5 git commands to generate.