tmf: Preload the statedump when building state systems, if there is one
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 7 Jul 2017 20:59:03 +0000 (16:59 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 7 Jul 2017 20:59:03 +0000 (16:59 -0400)
Change-Id: I57e363367713f0a9eb6a05a476662a45bae18eb1
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/statesystem/core/ITmfStateSystem.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java

index 4df70c16192068ce1d1b583dda7dab8fc9bd3867..a44383de61fe2b78ecdecd5d0d5225ee54d413d7 100644 (file)
@@ -44,7 +44,7 @@ public interface ITmfStateSystem {
      *
      * @return The state system's ID
      */
-    String getSSID();
+    @NonNull String getSSID();
 
     /**
      * Return the start time of this history. It usually matches the start time
index 63662078fbbf56725712dfd139db01d32b472a18..39a308e61ebe0680cbf533d87b20328fa378382a 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.tmf.core.statesystem;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
@@ -31,8 +32,10 @@ import org.eclipse.tracecompass.internal.tmf.core.statesystem.backends.partial.P
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
 import org.eclipse.tracecompass.statesystem.core.StateSystemFactory;
+import org.eclipse.tracecompass.statesystem.core.Statedump;
 import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend;
 import org.eclipse.tracecompass.statesystem.core.backend.StateHistoryBackendFactory;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
@@ -464,6 +467,14 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             throw new IllegalArgumentException();
         }
 
+        /*
+         * Note we have to do this before fStateProvider is assigned. After
+         * that, the signal listener below will start sending real trace events
+         * through the state provider.
+         */
+        loadInitialState(provider);
+
+        /* Continue on initializing the event request to read trace events. */
         ITmfEventRequest request = fRequest;
         if ((request != null) && (!request.isCompleted())) {
             request.cancel();
@@ -508,6 +519,42 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         }
     }
 
+    /**
+     * Batch-load the initial state, if there is any.
+     */
+    private void loadInitialState(ITmfStateProvider provider) {
+        final ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) provider.getAssignedStateSystem();
+        final ITmfTrace trace = getTrace();
+        if (ss == null || trace == null) {
+            /* These should have been initialized already. */
+            throw new IllegalStateException();
+        }
+        final long startTime = trace.getStartTime().toNanos();
+
+        Statedump sd = Statedump.loadState(Paths.get(trace.getPath()), ss.getSSID());
+        if (sd == null) {
+            /* No statedump found, nothing to pre-load */
+            return;
+        }
+
+        /*
+         * Do not load the statedump if its version does not match the current
+         * provider.
+         */
+        if (provider.getVersion() != sd.getVersion()) {
+            return;
+        }
+
+        /* Load the statedump into the statesystem */
+        for (int i = 0; i < sd.getAttributes().size(); i++) {
+            String[] attributePath = sd.getAttributes().get(i);
+            int quark = ss.getQuarkAbsoluteAndAdd(attributePath);
+            ITmfStateValue initialState = sd.getStates().get(i);
+
+            ss.modifyAttribute(startTime, initialState, quark);
+        }
+    }
+
     /**
      * A request to build a state system from a state provider
      *
@@ -515,6 +562,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
      */
     @VisibleForTesting
     protected class StateSystemEventRequest extends TmfEventRequest {
+
         private final ITmfStateProvider sci;
         private final ITmfTrace trace;
 
This page took 0.027908 seconds and 5 git commands to generate.