tmf: Save a snapshot of the state when doing a trim operation
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 7 Jul 2017 20:59:00 +0000 (16:59 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 7 Jul 2017 20:59:00 +0000 (16:59 -0400)
A "statedump" consisting of a full query at the start of the trim
range is done for every single state-system-driven analysis of this
trace.

This will ensure that the new trimmed trace does not lose any kind
of state information that could be inferred from the previous
events of the original trace.

Change-Id: Ia60585eaa117d75d45cc576ed39646fa1d0f3ad0
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/TrimTraceHandler.java

index 4a688bd97770f4cf4dd0a9777a1451327a045acf..63662078fbbf56725712dfd139db01d32b472a18 100644 (file)
@@ -76,6 +76,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
     private boolean fInitializationSucceeded;
 
     private volatile @Nullable ITmfStateProvider fStateProvider;
+    private @Nullable Integer fProviderVersion = null;
 
     /**
      * State system backend types
@@ -161,6 +162,16 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         return fStateSystem;
     }
 
+    /**
+     * Return the version of this module's state provider.
+     *
+     * @return The provider's version, or null if the provider is not set yet
+     * @since 2.3
+     */
+    public @Nullable Integer getProviderVersion() {
+        return fProviderVersion;
+    }
+
     /**
      * @since 2.0
      */
@@ -212,6 +223,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
     protected boolean executeAnalysis(@Nullable final  IProgressMonitor monitor) {
         IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
         final ITmfStateProvider provider = createStateProvider();
+        fProviderVersion = provider.getVersion();
 
         String id = getId();
 
index 73d0aeb88efa405252312f85b18d04019f219df1..d44943ab61480c262b9908a5ff3bf6299544e91c 100644 (file)
@@ -16,13 +16,18 @@ import java.lang.reflect.InvocationTargetException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -30,7 +35,12 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.DirectoryDialog;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tracecompass.common.core.StreamUtils;
+import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.Statedump;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
@@ -155,9 +165,40 @@ public class TrimTraceHandler extends AbstractHandler {
             public void execute(@Nullable IProgressMonitor monitor) throws CoreException {
                 IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
 
-                /* Perform the trace-specific trim operation. */
+                /* Retrieve the state system modules to use */
+                long dumpTime = tr.getStartTime().toNanos();
+                List<@NonNull TmfStateSystemAnalysisModule> statesystemModules = StreamUtils.getStream(trace.getAnalysisModules())
+                        .filter(module -> module instanceof TmfStateSystemAnalysisModule)
+                        .map(module -> (TmfStateSystemAnalysisModule) module)
+                        .collect(Collectors.toList());
+
+                /*
+                 * Perform the trace-specific trim operation. This should create
+                 * the trace file(s) in the destination path.
+                 */
                 trimmableTrace.trim(tr, tracePath, mon);
 
+                /* Write the statedump files in the new trace's location. */
+                try {
+                    for (TmfStateSystemAnalysisModule module : statesystemModules) {
+                        Integer version = module.getProviderVersion();
+                        ITmfStateSystem ss = module.getStateSystem();
+                        if (version == null || ss == null) {
+                            continue;
+                        }
+                        if (dumpTime > ss.getCurrentEndTime() || dumpTime < ss.getStartTime()) {
+                            continue;
+                        }
+
+                        Statedump statedump = new Statedump(ss, dumpTime, version);
+                        statedump.dumpState(tracePath, ss.getSSID());
+                    }
+
+                } catch (IOException e) {
+                    IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "An error occured while attempting to save the initial state"); //$NON-NLS-1$
+                    throw new CoreException(status);
+                }
+
                 /* Import the new trace into the current project, at the top-level. */
                 TmfProjectElement currentProjectElement = traceElem.getProject();
                 TmfTraceFolder traceFolder =currentProjectElement.getTracesFolder();
This page took 0.026285 seconds and 5 git commands to generate.