tmf: Store the ID in the state system itself
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 4 Feb 2014 22:53:18 +0000 (17:53 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 7 Feb 2014 18:59:39 +0000 (13:59 -0500)
Many components already refer to state systems with an ID, might
as well store it in the state system object itself for better
encapsulation.

Beyond the SSID pun, I like having it *not* be getId(), because that
quickly becomes confusing with IAnalysisModule.getId() (even though
those two values are usually the same).

Change-Id: I51babc177f54b4f8af66544e6c75be53da56b6c4
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/21540
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/mipmap/TmfMipmapStateProviderTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/mipmap/TmfMipmapStateProviderWeightedTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java

index 689b2325230470fced5d6f6bffabe9dc56f1ad75..aee84445b31f791174d08e28f63159d0a99c66bb 100644 (file)
@@ -82,7 +82,7 @@ public class StateSystemPushPopTest {
         testHtFile = File.createTempFile("test", ".ht");
 
         IStateHistoryBackend backend = new HistoryTreeBackend(testHtFile, 0, 0L);
-        ss = new StateSystem(backend, true);
+        ss = new StateSystem("push-pop-test", backend, true);
 
         /* Build the thing */
         final int attrib = ss.getQuarkAbsoluteAndAdd("Test", "stack");
index ecd53fc9750197fcacf0e390086d59b133c48570..67005bf6b52be334c4c6231198a8a5cae89723fa 100644 (file)
@@ -21,6 +21,7 @@ import static org.junit.Assert.fail;
 import java.util.List;
 import java.util.Random;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.InMemoryBackend;
@@ -41,6 +42,8 @@ import org.junit.Test;
  *
  */
 public class TmfMipmapStateProviderTest {
+
+    @NonNull private static final String SSID = "mimap-test";
     private static final String TEST_ATTRIBUTE_NAME = TmfMipmapStateProviderStub.TEST_ATTRIBUTE_NAME;
     private static final int NB_LEVELS = 4;
     private static final long START_TIME = 1000L;
@@ -59,7 +62,7 @@ public class TmfMipmapStateProviderTest {
     public static void init() {
         TmfMipmapStateProviderStub mmp = new TmfMipmapStateProviderStub(RESOLUTION, Type.LONG);
         IStateHistoryBackend be = new InMemoryBackend(0);
-        ssq = new StateSystem(be);
+        ssq = new StateSystem(SSID, be);
         mmp.assignTargetStateSystem(ssq);
 
         for (long time = START_TIME; time <= END_TIME; time += INTERVAL) {
index c75ae7c1812dafc11f435525a18fbd5a7ba8121c..8ed1a2394285c643145829e43d6f514f0aef1b9a 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.InMemoryBackend;
@@ -33,6 +34,8 @@ import org.junit.Test;
  *
  */
 public class TmfMipmapStateProviderWeightedTest {
+
+    @NonNull private static final String SSID = "mipmap-test";
     private static final String TEST_ATTRIBUTE_NAME = TmfMipmapStateProviderStub.TEST_ATTRIBUTE_NAME;
     private static final long END_TIME = 250000L;
     private static final long INTERVAL = 1000L;
@@ -49,12 +52,12 @@ public class TmfMipmapStateProviderWeightedTest {
         /* setup for INTEGER test */
         TmfMipmapStateProviderStub mmpi = new TmfMipmapStateProviderStub(RESOLUTION, Type.INTEGER);
         IStateHistoryBackend bei = new InMemoryBackend(0);
-        ssqi = new StateSystem(bei);
+        ssqi = new StateSystem(SSID, bei);
         mmpi.assignTargetStateSystem(ssqi);
         /* setup for DOUBLE test */
         TmfMipmapStateProviderStub mmpd = new TmfMipmapStateProviderStub(RESOLUTION, Type.DOUBLE);
         IStateHistoryBackend bed = new InMemoryBackend(0);
-        ssqd = new StateSystem(bed);
+        ssqd = new StateSystem(SSID, bed);
         mmpd.assignTargetStateSystem(ssqd);
         /*
          * Every 10,000 ns chunk contains the following states:
index 30db8416faace65850a70ab12fff7dc116cd7de0..44f1cc117d4c506aefee79787980bd5c5dd46123 100644 (file)
@@ -108,7 +108,7 @@ public class HistoryBuilder extends TmfComponent {
      */
     public static ITmfStateSystemBuilder openExistingHistory(
             @NonNull IStateHistoryBackend hb) throws IOException {
-        return new StateSystem(hb, false);
+        return new StateSystem("legacy-state-system", hb, false); //$NON-NLS-1$
     }
 
     /**
index ecba187de8ab85d725a11b22d290780690cefc59..02d6ef64b342d3683b7560e599fc92f1d086ae8d 100644 (file)
@@ -52,6 +52,8 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
  */
 public class StateSystem implements ITmfStateSystemBuilder {
 
+    private final String ssid;
+
     /* References to the inner structures */
     private final AttributeTree attributeTree;
     private final TransientState transState;
@@ -67,10 +69,13 @@ public class StateSystem implements ITmfStateSystemBuilder {
      * New-file constructor. For when you build a state system with a new file,
      * or if the back-end does not require a file on disk.
      *
+     * @param ssid
+     *            The ID of this statesystem. It should be unique.
      * @param backend
      *            Back-end plugin to use
      */
-    public StateSystem(@NonNull IStateHistoryBackend backend) {
+    public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend) {
+        this.ssid = ssid;
         this.backend = backend;
         this.transState = new TransientState(backend);
         this.attributeTree = new AttributeTree(this);
@@ -79,6 +84,8 @@ public class StateSystem implements ITmfStateSystemBuilder {
     /**
      * General constructor
      *
+     * @param ssid
+     *            The ID of this statesystem. It should be unique.
      * @param backend
      *            The "state history storage" back-end to use.
      * @param newFile
@@ -87,8 +94,9 @@ public class StateSystem implements ITmfStateSystemBuilder {
      * @throws IOException
      *             If there was a problem creating the new history file
      */
-    public StateSystem(@NonNull IStateHistoryBackend backend, boolean newFile)
+    public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend, boolean newFile)
             throws IOException {
+        this.ssid = ssid;
         this.backend = backend;
         this.transState = new TransientState(backend);
 
@@ -102,6 +110,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
         }
     }
 
+    @Override
+    public String getSSID() {
+        return ssid;
+    }
+
     @Override
     public boolean isCancelled() {
         return buildCancelled;
index 1684a83834039d84409246170fd6a17479821cc3..ee185cef08f6752324d6016b70fcb445e217714a 100644 (file)
@@ -53,7 +53,7 @@ public class PartialStateSystem extends StateSystem {
          * We use a Null back end here : we only use this state system for its
          * "ongoing" values, so no need to save the changes that are inserted.
          */
-        super(new NullBackend());
+        super("partial", new NullBackend()); //$NON-NLS-1$
     }
 
     /**
index 37b384cd77eb4b60f21f0ca3be3490773a8695fa..ea8534235322f04362a82e04132310817e831f07 100644 (file)
@@ -32,6 +32,14 @@ import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
  */
 public interface ITmfStateSystem {
 
+    /**
+     * Get the ID of this state system.
+     *
+     * @return The state system's ID
+     * @since 3.0
+     */
+    String getSSID();
+
     /**
      * Return the start time of this history. It usually matches the start time
      * of the original trace.
index a571f4a946896847b3b57f2235709b4eb961ab99..e19a1de88e1c355b78cf5b46d22e0858ece0529d 100644 (file)
@@ -57,6 +57,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         implements ITmfAnalysisModuleWithStateSystems {
 
     private static final String EXTENSION = ".ht"; //$NON-NLS-1$
+    private static final String UNDEFINED_ID = "undefined"; //$NON-NLS-1$
 
     private final CountDownLatch fInitialized = new CountDownLatch(1);
 
@@ -136,6 +137,12 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
         final ITmfStateProvider provider = createStateProvider();
 
+        String id = getId();
+        if (id == null) {
+            /* The analysis module does not specify an ID, use a generic one */
+            id = UNDEFINED_ID;
+        }
+
         /* FIXME: State systems should make use of the monitor, to be cancelled */
         try {
             /* Get the state system according to backend */
@@ -146,18 +153,18 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             case FULL:
                 directory = TmfTraceManager.getSupplementaryFileDir(getTrace());
                 htFile = new File(directory + getSsFileName());
-                createFullHistory(provider, htFile);
+                createFullHistory(id, provider, htFile);
                 break;
             case PARTIAL:
                 directory = TmfTraceManager.getSupplementaryFileDir(getTrace());
                 htFile = new File(directory + getSsFileName());
-                createPartialHistory(provider, htFile);
+                createPartialHistory(id, provider, htFile);
                 break;
             case INMEM:
-                createInMemoryHistory(provider);
+                createInMemoryHistory(id, provider);
                 break;
             case NULL:
-                createNullHistory(provider);
+                createNullHistory(id, provider);
                 break;
             default:
                 break;
@@ -193,7 +200,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      * exists, it will be opened directly. If not, it will be created from
      * scratch.
      */
-    private void createFullHistory(ITmfStateProvider provider, File htFile) throws TmfTraceException {
+    private void createFullHistory(String id, ITmfStateProvider provider, File htFile) throws TmfTraceException {
 
         /* If the target file already exists, do not rebuild it uselessly */
         // TODO for now we assume it's complete. Might be a good idea to check
@@ -203,8 +210,9 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
            /* Load an existing history */
             final int version = provider.getVersion();
             try {
-                fHtBackend = new HistoryTreeBackend(htFile, version);
-                fStateSystem = new StateSystem(fHtBackend, false);
+                IStateHistoryBackend backend = new HistoryTreeBackend(htFile, version);
+                fHtBackend = backend;
+                fStateSystem = new StateSystem(id, backend, false);
                 fInitialized.countDown();
                 return;
             } catch (IOException e) {
@@ -220,9 +228,10 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         final int QUEUE_SIZE = 10000;
 
         try {
-            fHtBackend = new ThreadedHistoryTreeBackend(htFile,
+            IStateHistoryBackend backend = new ThreadedHistoryTreeBackend(htFile,
                     provider.getStartTime(), provider.getVersion(), QUEUE_SIZE);
-            fStateSystem = new StateSystem(fHtBackend);
+            fHtBackend = backend;
+            fStateSystem = new StateSystem(id, backend);
             provider.assignTargetStateSystem(fStateSystem);
             build(provider);
         } catch (IOException e) {
@@ -244,7 +253,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      * underneath, (which are much slower), so this might not be a good fit for
      * a use case where you have to do lots of single queries.
      */
-    private void createPartialHistory(ITmfStateProvider provider, File htPartialFile)
+    private void createPartialHistory(String id, ITmfStateProvider provider, File htPartialFile)
             throws TmfTraceException {
         /*
          * The order of initializations is very tricky (but very important!)
@@ -292,7 +301,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
                 new PartialHistoryBackend(partialProvider, pss, realBackend, granularity);
 
         /* 4 */
-        StateSystem realSS = new StateSystem(partialBackend);
+        StateSystem realSS = new StateSystem(id, partialBackend);
 
         /* 5 */
         pss.assignUpstream(realSS);
@@ -312,9 +321,10 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      * no history intervals will be saved anywhere, and as such only
      * {@link ITmfStateSystem#queryOngoingState} will be available.
      */
-    private void createNullHistory(ITmfStateProvider provider) {
-        fHtBackend = new NullBackend();
-        fStateSystem = new StateSystem(fHtBackend);
+    private void createNullHistory(String id, ITmfStateProvider provider) {
+        IStateHistoryBackend backend = new NullBackend();
+        fHtBackend = backend;
+        fStateSystem = new StateSystem(id, backend);
         provider.assignTargetStateSystem(fStateSystem);
         build(provider);
     }
@@ -324,9 +334,10 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      * only be done for very small state system, and will be naturally limited
      * to 2^31 intervals.
      */
-    private void createInMemoryHistory(ITmfStateProvider provider) {
-        fHtBackend = new InMemoryBackend(provider.getStartTime());
-        fStateSystem = new StateSystem(fHtBackend);
+    private void createInMemoryHistory(String id, ITmfStateProvider provider) {
+        IStateHistoryBackend backend = new InMemoryBackend(provider.getStartTime());
+        fHtBackend = backend;
+        fStateSystem = new StateSystem(id, backend);
         provider.assignTargetStateSystem(fStateSystem);
         build(provider);
     }
index 5395842e266bd0f491666df8d22b467ec7aeb2e5..addb37bdfca70905d2585777d294bf365fb08233 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.tmf.core.statesystem;
 import java.io.File;
 import java.io.IOException;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
@@ -43,6 +44,8 @@ public final class TmfStateSystemFactory extends TmfComponent {
     /** "static" class */
     private TmfStateSystemFactory() {}
 
+    @NonNull private static final String SSID = "legacy-state-system"; //$NON-NLS-1$
+
     /** Size of the blocking queue to use when building a state history */
     private static final int QUEUE_SIZE = 10000;
 
@@ -105,7 +108,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
         try {
             htBackend = new ThreadedHistoryTreeBackend(htFile,
                     stateProvider.getStartTime(), stateProvider.getVersion(), QUEUE_SIZE);
-            StateSystem ss = new StateSystem(htBackend);
+            StateSystem ss = new StateSystem(SSID, htBackend);
             stateProvider.assignTargetStateSystem(ss);
             builder = new HistoryBuilder(stateProvider, ss, htBackend, buildManually);
         } catch (IOException e) {
@@ -133,7 +136,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
      */
     public static ITmfStateSystem newNullHistory(ITmfStateProvider stateProvider) {
         IStateHistoryBackend backend = new NullBackend();
-        StateSystem ss = new StateSystem(backend);
+        StateSystem ss = new StateSystem(SSID, backend);
         stateProvider.assignTargetStateSystem(ss);
 
         HistoryBuilder builder = new HistoryBuilder(stateProvider, ss, backend, true);
@@ -159,7 +162,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
     public static ITmfStateSystem newInMemHistory(ITmfStateProvider stateProvider,
             boolean buildManually) {
         IStateHistoryBackend backend = new InMemoryBackend(stateProvider.getStartTime());
-        StateSystem ss = new StateSystem(backend);
+        StateSystem ss = new StateSystem(SSID, backend);
         stateProvider.assignTargetStateSystem(ss);
 
         HistoryBuilder builder = new HistoryBuilder(stateProvider, ss, backend, buildManually);
@@ -237,7 +240,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
                 new PartialHistoryBackend(partialProvider, pss, realBackend, granularity);
 
         /* 4 */
-        StateSystem realSS = new StateSystem(partialBackend);
+        StateSystem realSS = new StateSystem(SSID, partialBackend);
 
         /* 5 */
         pss.assignUpstream(realSS);
This page took 0.259447 seconds and 5 git commands to generate.