From: Alexandre Montplaisir Date: Tue, 10 Sep 2013 20:15:51 +0000 (-0400) Subject: Merge commit '3a6b7eb9a532100a4cb85e0a81fbc8bd6e91db13' into lttng-luna X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=e3254d3a4df56dc911967c8cb02a64a8b9ea8f0b;p=deliverable%2Ftracecompass.git Merge commit '3a6b7eb9a532100a4cb85e0a81fbc8bd6e91db13' into lttng-luna These conflicts are a little intense, let's fix them one merge at a time... Signed-off-by: Alexandre Montplaisir Conflicts: lttng/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java Change-Id: If5589c465c299b4f2c718ae25426c5afe446fce1 --- e3254d3a4df56dc911967c8cb02a64a8b9ea8f0b diff --cc org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF index a5c826b816,ac876444c0..0382f319db --- a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF @@@ -9,8 -9,9 +9,9 @@@ Bundle-Activator: org.eclipse.linuxtool Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.eclipse.core.runtime, - org.eclipse.linuxtools.ctf.parser;bundle-version="1.0.0" + org.eclipse.linuxtools.ctf.parser;bundle-version="3.0.0" - Export-Package: org.eclipse.linuxtools.ctf.core.event, + Export-Package: org.eclipse.linuxtools.ctf.core, + org.eclipse.linuxtools.ctf.core.event, org.eclipse.linuxtools.ctf.core.event.io, org.eclipse.linuxtools.ctf.core.event.types, org.eclipse.linuxtools.ctf.core.trace, diff --cc org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java index 6e3dbb463a,9178188050..fc8b905f31 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java @@@ -54,8 -58,10 +58,10 @@@ public final class CtfTmfEventFactory String fileName, CtfTmfTrace originTrace) { /* Prepare what to pass to CtfTmfEvent's constructor */ - long ts = eventDef.getTimestamp(); - CtfTmfTimestamp timestamp = originTrace.createTimestamp(originTrace.getCTFTrace().timestampCyclesToNanos(ts)); + final IEventDeclaration eventDecl = eventDef.getDeclaration(); + final long ts = eventDef.getTimestamp(); - final CtfTmfTimestamp timestamp = new CtfTmfTimestamp( ++ final CtfTmfTimestamp timestamp = originTrace.createTimestamp( + originTrace.getCTFTrace().timestampCyclesToNanos(ts)); int sourceCPU = eventDef.getCPU(); diff --cc org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java index a7dd632233,c2b956e0d9..e429401771 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java @@@ -51,14 -44,6 +41,15 @@@ public class Messages extends NLS public static String DropAdapterAssistant_RenameTraceTitle; public static String DropAdapterAssistant_RenameTraceMessage; ++ public static String SynchronizeTracesHandler_InitError; + public static String SynchronizeTracesHandler_CopyProblem; + public static String SynchronizeTracesHandler_WrongType; + public static String SynchronizeTracesHandler_WrongTraceNumber; + public static String SynchronizeTracesHandler_Title; + public static String SynchronizeTracesHandler_Error; + public static String SynchronizeTracesHandler_ErrorSynchingExperiment; + public static String SynchronizeTracesHandler_ErrorSynchingForTrace; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --cc org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java index 9ac1c4c017,0000000000..ea98f53dee mode 100644,000000..100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SynchronizeTracesHandler.java @@@ -1,250 -1,0 +1,250 @@@ +/******************************************************************************* + * Copyright (c) 2013 École Polytechnique de Montréal + * + * 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: + * Geneviève Bastien - Initial implementation and API + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; + +import java.util.ArrayList; +import java.util.Iterator; + +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.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +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.ui.project.model.ITmfProjectModelElement; +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; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * Handles the synchronization of an experiment, when the user selects this + * option in the menu + */ +public class SynchronizeTracesHandler extends AbstractHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private TreeSelection fSelection = null; + private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Validation + // ------------------------------------------------------------------------ + + @Override + public boolean isEnabled() { + return true; + } + + // ------------------------------------------------------------------------ + // Execution + // ------------------------------------------------------------------------ + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // Check if we are closing down + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return null; + } + + // Get the selection + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPart part = page.getActivePart(); + if (part == null) { + return false; + } + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) { + return false; + } + ISelection selection = selectionProvider.getSelection(); + + // Make sure selection contains only traces + fSelection = null; + final ArrayList tl = new ArrayList(); + final ArrayList uiexperiment = new ArrayList(); + if (selection instanceof TreeSelection) { + fSelection = (TreeSelection) selection; + Iterator iterator = fSelection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (element instanceof TmfTraceElement) { + tl.add((TmfTraceElement) element); + } else if (element instanceof TmfExperimentElement) { + TmfExperimentElement exp = (TmfExperimentElement) element; + uiexperiment.add(exp); + for (TmfTraceElement trace : exp.getTraces()) { + tl.add(trace); + } + } + } + } + + if ((uiexperiment.size() == 1) && (tl.size() > 1)) { + + Thread thread = new Thread() { + @Override + public void run() { + + 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.OpenTraceHandler_InitError + CR + CR + 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; + } + + /* + * 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); + + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + /* + * 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 (int i = 0; i < tl.size(); i++) { + TmfTraceElement traceel = tl.get(i); + try { + if (syncAlgo.isTraceSynced(traceel.getName())) { + + /* Find the original trace */ + TmfTraceElement origtrace = null; + for (ITmfProjectModelElement el : traceel.getProject().getTracesFolder().getTraces()) { + if (el.getName().equals(traceel.getName())) { + origtrace = (TmfTraceElement) el; + } + } + + if (origtrace != null) { + /* + * Make sure a trace with the + * new name does not exist + */ + String newname = traceel.getName(); + boolean traceexists; + do { + traceexists = false; + newname += "_"; //$NON-NLS-1$ + for (ITmfProjectModelElement el : traceel.getProject().getTracesFolder().getTraces()) { + if (el.getName().equals(newname)) { + traceexists = true; + } + } + } while (traceexists); + + /* Copy the original trace */ + TmfTraceElement newtrace = origtrace.copy(newname); + + if (newtrace != null) { + + syncAlgo.renameTrace(origtrace.getName(), newtrace.getName()); + + /* + * 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()); + } 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()); + } + } + } + }); + + } catch (TmfTraceException e) { + Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e); - TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.OpenExperimentHandler_Error + CR + CR + e.getMessage()); ++ TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e.getMessage()); + } + } + }; + thread.start(); + + } else { + TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongTraceNumber); + } + + return null; + } + +} diff --cc org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties index e8cfa94dd4,4d321ac25b..ba2d8e31ce --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties @@@ -39,13 -27,3 +27,14 @@@ SelectTraceTypeHandler_InvalidTraceTyp # Drag and drop DropAdapterAssistant_RenameTraceTitle=Confirm rename trace DropAdapterAssistant_RenameTraceMessage=A trace with the name ''{0}'' already exists in the target project.\nRename the dropped trace? + +# Trace synchronization ++SynchronizeTracesHandler_InitError=Error initializing trace +SynchronizeTracesHandler_CopyProblem=Couldn't copy the original trace %s +SynchronizeTracesHandler_WrongTraceNumber=Experiment must have more than one trace +SynchronizeTracesHandler_Title=Synchronize traces +SynchronizeTracesHandler_WrongType=Trace is not a kernel trace:\n +SynchronizeTracesHandler_Error=Error synchronizing experiment + +SynchronizeTracesHandler_ErrorSynchingExperiment=Error synchronizing experiment %s +SynchronizeTracesHandler_ErrorSynchingForTrace=Error synchronizing experiment %s for trace %s