Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2014-05-16 16:12:15 -0400
committerPatrick Tasse2014-06-03 16:14:32 -0400
commit822f2e53063058c6889fc0ac9f1943321d665817 (patch)
treea887126c1d49b91c5216ecc70df736a266bec6d5
parent8acaefc99983781120298365ffbfcb6e19d0bf2c (diff)
downloadorg.eclipse.linuxtools-822f2e53063058c6889fc0ac9f1943321d665817.tar.gz
org.eclipse.linuxtools-822f2e53063058c6889fc0ac9f1943321d665817.tar.xz
org.eclipse.linuxtools-822f2e53063058c6889fc0ac9f1943321d665817.zip
tmf: Bug 436491: Fix Synchronize Traces handling
- Refresh supplementary files for each element as soon as they are created. - Dispose traces and experiment instances when they are no longer needed. - Update the experiment element traces only after instances have been disposed. - Fix TmfTraceElement.copy() to use the correct resource according to its element path. - Fix TmfTraceElement.copy() to avoid manually creating a new TmfTraceElement and return the one created by the navigator resource handler instead. - Temporarily move synchronization.bin file during experiment update then restore it to its original location. Change-Id: I87b3be4dccaf2747fed70eabf63a2f521424b3cb Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/27861 Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java270
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java15
2 files changed, 161 insertions, 124 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java
index a62d5aefe9..2f71de8071 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java
@@ -14,11 +14,14 @@ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -29,6 +32,7 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils;
@@ -106,147 +110,175 @@ public class SynchronizeTracesHandler extends AbstractHandler {
}
}
- if ((uiexperiment.size() == 1) && (tl.size() > 1)) {
+ if ((uiexperiment.size() != 1) || (tl.size() < 2)) {
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongTraceNumber);
+ return null;
+ }
- Thread thread = new Thread() {
- @Override
- public void run() {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
- final ITmfTrace[] traces = new ITmfTrace[tl.size()];
- final TmfExperimentElement exp = uiexperiment.get(0);
+ final ITmfTrace[] traces = new ITmfTrace[tl.size()];
+ final TmfExperimentElement exp = uiexperiment.get(0);
- for (int i = 0; i < tl.size(); i++) {
- ITmfTrace trace = tl.get(i).instantiateTrace();
- ITmfEvent traceEvent = tl.get(i).instantiateEvent();
- if (trace == null) {
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongType + tl.get(i).getName());
- for (int j = 0; j < i; j++) {
- traces[j].dispose();
- }
- return;
- }
- try {
- trace.initTrace(tl.get(i).getResource(), tl.get(i).getLocation().getPath(), traceEvent.getClass());
- } catch (TmfTraceException e) {
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_InitError + CR + CR + e);
- trace.dispose();
- for (int j = 0; j < i; j++) {
- traces[j].dispose();
- }
- return;
+ for (int i = 0; i < tl.size(); i++) {
+ ITmfTrace trace = tl.get(i).instantiateTrace();
+ ITmfEvent traceEvent = tl.get(i).instantiateEvent();
+ if (trace == null) {
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongType + tl.get(i).getName());
+ for (int j = 0; j < i; j++) {
+ traces[j].dispose();
}
- traces[i] = trace;
+ return;
}
-
- /*
- * FIXME Unlike traces, there is no instanceExperiment, so
- * we call this function here alone. Maybe it would be
- * better to do this on experiment's element constructor?
- */
- exp.refreshSupplementaryFolder();
- final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, exp.getName(), traces, exp.getResource());
-
try {
- final SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
+ trace.initTrace(tl.get(i).getResource(), tl.get(i).getLocation().getPath(), traceEvent.getClass());
+ TmfTraceManager.refreshSupplementaryFiles(trace);
+ } catch (TmfTraceException e) {
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_InitError + CR + CR + e);
+ trace.dispose();
+ for (int j = 0; j < i; j++) {
+ traces[j].dispose();
+ }
+ return;
+ }
+ traces[i] = trace;
+ }
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
+ /*
+ * FIXME Unlike traces, there is no instanceExperiment, so
+ * we call this function here alone. Maybe it would be
+ * better to do this on experiment's element constructor?
+ */
+ exp.refreshSupplementaryFolder();
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, exp.getName(), traces, exp.getResource());
+
+ try {
+ final SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
+ TmfTraceManager.refreshSupplementaryFiles(experiment);
+
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ List<TmfTraceElement> tracesToAdd = new ArrayList<>();
+ List<TmfTraceElement> tracesToRemove = new ArrayList<>();
+ /*
+ * For each trace in the experiment, if there is
+ * a transform equation, copy the original
+ * trace, so that a new state system will be
+ * generated with sync time.
+ */
+ for (TmfTraceElement traceel : tl) {
/*
- * For each trace in the experiment, if there is
- * a transform equation, copy the original
- * trace, so that a new state system will be
- * generated with sync time.
+ * Find the trace corresponding to this
+ * element in the experiment
*/
- for (int i = 0; i < tl.size(); i++) {
- TmfTraceElement traceel = tl.get(i);
+ ITmfTrace expTrace = null;
+ for (ITmfTrace t : experiment.getTraces()) {
+ if (t.getResource().equals(traceel.getResource())) {
+ expTrace = t;
+ break;
+ }
+ }
+ if ((expTrace != null) && syncAlgo.isTraceSynced(expTrace.getHostId())) {
+
+ /* Find the original trace */
+ TmfTraceElement origtrace = traceel.getElementUnderTraceFolder();
+
/*
- * Find the trace corresponding to this
- * element in the experiment
+ * Make sure a trace with the
+ * new name does not exist
*/
- ITmfTrace expTrace = null;
- for (ITmfTrace t : experiment.getTraces()) {
- if (t.getResource().equals(traceel.getResource())) {
- expTrace = t;
- break;
+ String newname = traceel.getName();
+ IContainer parentFolder = origtrace.getResource().getParent();
+ boolean traceexists;
+ do {
+ traceexists = false;
+ newname += "_"; //$NON-NLS-1$
+ if (parentFolder.findMember(newname) != null) {
+ traceexists = true;
}
+ } while (traceexists);
+
+ /* Copy the original trace */
+ TmfTraceElement newtrace = origtrace.copy(newname);
+ if (newtrace == null) {
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title,
+ Messages.SynchronizeTracesHandler_Error + CR + CR + String.format(Messages.SynchronizeTracesHandler_CopyProblem, origtrace.getName()));
+ continue;
}
+
+ /*
+ * Instantiate the new trace
+ * and set its sync formula
+ */
+ ITmfTrace trace = newtrace.instantiateTrace();
+ ITmfEvent traceEvent = newtrace.instantiateEvent();
+
try {
- if ((expTrace != null) && syncAlgo.isTraceSynced(expTrace.getHostId())) {
-
- /* Find the original trace */
- TmfTraceElement origtrace = traceel.getElementUnderTraceFolder();
-
- if (origtrace != null) {
- /*
- * Make sure a trace with the
- * new name does not exist
- */
- String newname = traceel.getName();
- IContainer parentFolder = origtrace.getResource().getParent();
- boolean traceexists;
- do {
- traceexists = false;
- newname += "_"; //$NON-NLS-1$
- if (parentFolder.findMember(newname) != null) {
- traceexists = true;
- }
- } while (traceexists);
-
- /* Copy the original trace */
- TmfTraceElement newtrace = origtrace.copy(newname);
-
- if (newtrace != null) {
-
- /*
- * Instantiate the new trace
- * and set its sync formula
- */
- ITmfTrace trace = newtrace.instantiateTrace();
- ITmfEvent traceEvent = newtrace.instantiateEvent();
-
- trace.initTrace(newtrace.getResource(), newtrace.getLocation().getPath(), traceEvent.getClass());
- trace.setTimestampTransform(syncAlgo.getTimestampTransform(trace));
-
- /*
- * Add the new trace to the
- * experiment
- */
- exp.addTrace(newtrace);
-
- /*
- * Delete the original trace
- * element
- */
- exp.removeTrace(traceel);
- } else {
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title,
- Messages.SynchronizeTracesHandler_Error + CR + CR + String.format(Messages.SynchronizeTracesHandler_CopyProblem, origtrace.getName()));
- }
- }
- }
- } catch (CoreException e) {
- Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), traceel.getName()), e);
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage());
+ trace.initTrace(newtrace.getResource(), newtrace.getLocation().getPath(), traceEvent.getClass());
} catch (TmfTraceException e) {
Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), traceel.getName()), e);
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage());
}
+ trace.setTimestampTransform(syncAlgo.getTimestampTransform(trace));
+ TmfTraceManager.refreshSupplementaryFiles(trace);
+ trace.dispose();
+
+ tracesToAdd.add(newtrace);
+ tracesToRemove.add(traceel);
+ }
+ }
+ experiment.dispose();
+
+ // Move synchronization file temporarily so that
+ // it doesn't get deleted by the experiment change
+ IFolder tmpFolder = exp.getTraceSupplementaryFolder("."); //$NON-NLS-1$
+ IResource syncFile = null;
+ for (IResource resource : exp.getSupplementaryResources()) {
+ if (resource.getName().equals(TmfExperiment.SYNCHRONIZATION_FILE_NAME)) {
+ try {
+ resource.move(tmpFolder.getFile(exp.getName() + '.' + TmfExperiment.SYNCHRONIZATION_FILE_NAME).getFullPath(), false, null);
+ syncFile = resource;
+ break;
+ } catch (CoreException e) {
+ Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e);
+ }
}
}
- });
- } catch (TmfTraceException e) {
- Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e);
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage());
- }
- }
- };
- thread.start();
+ for (TmfTraceElement trace : tracesToRemove) {
+ try {
+ exp.removeTrace(trace);
+ } catch (CoreException e) {
+ Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), trace.getName()), e);
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage());
+ }
+ }
+ for (TmfTraceElement trace : tracesToAdd) {
+ exp.addTrace(trace);
+ }
- } else {
- TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongTraceNumber);
- }
+ // Move synchronization file back
+ IResource resource = tmpFolder.getFile(exp.getName() + '.' + TmfExperiment.SYNCHRONIZATION_FILE_NAME);
+ if (resource.exists() && syncFile != null) {
+ try {
+ resource.move(syncFile.getFullPath(), false, null);
+ } catch (CoreException e) {
+ Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e);
+ }
+ }
+ }
+ });
+
+ } catch (TmfTraceException e) {
+ Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e);
+ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage());
+ }
+ }
+ };
+ thread.start();
return null;
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
index 44590ab647..65001c953d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
@@ -499,15 +499,20 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
* Copy this trace in the trace folder. No other parameters are mentioned so
* the trace is copied in this element's project trace folder
*
- * @param string
+ * @param newName
* The new trace name
* @return the new Resource object
* @since 2.0
*/
- public TmfTraceElement copy(String string) {
- TmfTraceFolder folder = this.getProject().getTracesFolder();
- IResource res = super.copy(string, false);
- return new TmfTraceElement(string, res, folder);
+ public TmfTraceElement copy(String newName) {
+ TmfTraceFolder folder = (TmfTraceFolder) getParent();
+ IResource res = super.copy(newName, false);
+ for (TmfTraceElement trace : folder.getTraces()) {
+ if (trace.getResource().equals(res)) {
+ return trace;
+ }
+ }
+ return null;
}
/**

Back to the top