Search in sources :

Example 26 with TmfExperiment

use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.

the class Uml2SDTestFacility method selectExperiment.

/**
 * Selects the experiment.
 * @param wait true to wait for indexing to finish else false
 */
public void selectExperiment(final boolean wait) {
    TmfUml2SDTestTrace parser = new TmfUml2SDTestTrace();
    ITmfTrace trace = setupTrace(parser);
    parser.setTrace(trace);
    final ITmfTrace[] traces = new ITmfTrace[] { trace };
    fExperiment = new TmfExperiment(ITmfEvent.class, "TestExperiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null) {

        @Override
        protected ITmfTraceIndexer createIndexer(int interval) {
            return new TmfCheckpointIndexer(this, interval);
        }
    };
    trace.broadcast(new TmfTraceOpenedSignal(this, fExperiment, null));
    trace.broadcast(new TmfTraceSelectedSignal(this, fExperiment));
    if (wait) {
        while (fExperiment.getNbEvents() == 0) {
            delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
        }
        waitForJobs();
        delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfTraceIndexer(org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) TmfUml2SDTestTrace(org.eclipse.tracecompass.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace) TmfCheckpointIndexer(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer)

Example 27 with TmfExperiment

use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.

the class SynchronizeTracesHandler method execute.

// ------------------------------------------------------------------------
// 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
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    // Make sure selection contains only traces
    fSelection = null;
    final ArrayList<TmfTraceElement> tl = new ArrayList<>();
    final ArrayList<TmfExperimentElement> uiexperiment = new ArrayList<>();
    if (selection instanceof TreeSelection) {
        fSelection = (TreeSelection) selection;
        Iterator<Object> iterator = fSelection.iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            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() < 2)) {
        TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongTraceNumber);
        return null;
    }
    fExperiment = uiexperiment.get(0);
    fRootNode = null;
    fRootNodeId = null;
    // Fire the Select Root Node Wizard
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    Shell shell = workbenchWindow.getShell();
    SelectRootNodeWizard wizard = new SelectRootNodeWizard(fExperiment);
    WizardDialog dialog = new WizardDialog(shell, wizard);
    int returnValue = dialog.open();
    if (returnValue == Window.CANCEL) {
        return null;
    }
    fRootNode = wizard.getRootNode();
    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++) {
                TmfTraceElement traceElement = tl.get(i).getElementUnderTraceFolder();
                ITmfTrace trace = traceElement.instantiateTrace();
                ITmfEvent traceEvent = traceElement.instantiateEvent();
                if (trace == null) {
                    TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongType + traceElement.getName());
                    for (int j = 0; j < i; j++) {
                        traces[j].dispose();
                    }
                    return;
                }
                try {
                    trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), 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;
                }
                if (traceElement.getElementPath().equals(fRootNode.getElementPath())) {
                    fRootNodeId = trace.getHostId();
                }
                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, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, exp.getResource());
            final SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
            syncAlgo.setRootNode(fRootNodeId);
            TmfTraceManager.refreshSupplementaryFiles(experiment);
            Display.getDefault().asyncExec(() -> {
                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) {
                    /* Find the original trace */
                    TmfTraceElement origtrace = traceel.getElementUnderTraceFolder();
                    /*
                         * Find the trace corresponding to this element in
                         * the experiment
                         */
                    ITmfTrace expTrace = null;
                    for (ITmfTrace t : experiment.getTraces()) {
                        if (t.getResource().equals(origtrace.getResource())) {
                            expTrace = t;
                            break;
                        }
                    }
                    if ((expTrace != null) && syncAlgo.isTraceSynced(expTrace.getHostId())) {
                        /*
                             * Make sure a trace with the new name does not
                             * exist
                             */
                        StringBuilder newname = new StringBuilder(traceel.getName());
                        IContainer parentFolder = origtrace.getResource().getParent();
                        boolean traceexists;
                        do {
                            traceexists = false;
                            newname.append('_');
                            if (parentFolder.findMember(newname.toString()) != null) {
                                traceexists = true;
                            }
                        } while (traceexists);
                        /* Copy the original trace */
                        TmfTraceElement newtrace = origtrace.copy(newname.toString());
                        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 trace1 = newtrace.instantiateTrace();
                        ITmfEvent traceEvent = newtrace.instantiateEvent();
                        try {
                            trace1.initTrace(newtrace.getResource(), newtrace.getResource().getLocation().toOSString(), traceEvent.getClass());
                        } catch (TmfTraceException e1) {
                            Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), traceel.getName()), e1);
                            TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e1.getMessage());
                        }
                        trace1.setTimestampTransform(syncAlgo.getTimestampTransform(expTrace));
                        TmfTraceManager.refreshSupplementaryFiles(trace1);
                        trace1.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(exp.getName() + '.' + experiment.getSynchronizationFolder(false));
                IResource syncFile = null;
                for (IResource resource : exp.getSupplementaryResources()) {
                    if (resource.getName().equals(experiment.getSynchronizationFolder(false))) {
                        try {
                            resource.move(tmpFolder.getFullPath(), false, null);
                            syncFile = resource;
                            break;
                        } catch (CoreException e2) {
                            Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e2);
                        }
                    }
                }
                for (TmfTraceElement trace2 : tracesToRemove) {
                    try {
                        exp.removeTrace(trace2);
                    } catch (CoreException e3) {
                        Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), trace2.getName()), e3);
                        TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e3.getMessage());
                    }
                }
                for (TmfTraceElement trace3 : tracesToAdd) {
                    exp.addTrace(trace3);
                }
                // Move synchronization file back
                if (tmpFolder.exists() && syncFile != null) {
                    try {
                        tmpFolder.move(syncFile.getFullPath(), false, null);
                    } catch (CoreException e4) {
                        Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e4);
                    }
                }
            });
        }
    };
    thread.start();
    return null;
}
Also used : TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Shell(org.eclipse.swt.widgets.Shell) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IContainer(org.eclipse.core.resources.IContainer) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SelectRootNodeWizard(org.eclipse.tracecompass.tmf.ui.project.wizards.SelectRootNodeWizard) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) CoreException(org.eclipse.core.runtime.CoreException) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SynchronizationAlgorithm(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 28 with TmfExperiment

use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.

the class StreamListAnalysis method canExecute.

@Override
public boolean canExecute(ITmfTrace trace) {
    // Trace is Pcap
    if (trace instanceof PcapTrace) {
        return true;
    }
    // Trace is not a TmfExperiment
    if (!(trace instanceof TmfExperiment)) {
        return false;
    }
    // Trace is TmfExperiment. Check if it has a PcapTrace.
    TmfExperiment experiment = (TmfExperiment) trace;
    List<ITmfTrace> traces = experiment.getTraces();
    for (ITmfTrace expTrace : traces) {
        if (expTrace instanceof PcapTrace) {
            return true;
        }
    }
    // No Pcap :(
    return false;
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) PcapTrace(org.eclipse.tracecompass.internal.tmf.pcap.core.trace.PcapTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)

Example 29 with TmfExperiment

use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.

the class TmfTraceTypeUIUtils method getPerspectiveId.

/**
 * Get the perspective id specified by the trace type's extension point, if
 * there is one.
 *
 * @param trace
 *            The trace for which we want the perspective id.
 * @return The corresponding perspective id, or 'null' if this trace type
 *         did not specify any.
 * @since 2.3
 */
@Nullable
public static String getPerspectiveId(ITmfTrace trace) {
    final String traceType = getTraceType(trace);
    if (traceType == null) {
        return null;
    }
    TraceElementType elType = (trace instanceof TmfExperiment) ? TraceElementType.EXPERIMENT : TraceElementType.TRACE;
    for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements(elType)) {
        if (ce.getAttribute(TRACETYPE_ATTR).equals(traceType)) {
            final IConfigurationElement[] perspectiveCE = ce.getChildren(PERSPECTIVE_ELEM);
            if (perspectiveCE.length != 1) {
                break;
            }
            final String perspectiveId = perspectiveCE[0].getAttribute(ID_ATTR);
            if (!perspectiveId.isEmpty()) {
                return perspectiveId;
            }
            break;
        }
    }
    return null;
}
Also used : TraceElementType(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 30 with TmfExperiment

use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.

the class TmfOpenTraceHelper method openExperimentElement.

private static ITmfTrace openExperimentElement(final TmfExperimentElement experimentElement) {
    /* Experiment element now has an experiment type associated with it */
    final TmfExperiment experiment = experimentElement.instantiateTrace();
    if (experiment == null) {
        TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement, experimentElement.getTypeName()), NLS.bind(Messages.TmfOpenTraceHelper_NoTraceOrExperimentType, experimentElement.getTypeName()));
        return null;
    }
    // Instantiate the experiment's traces
    final List<TmfTraceElement> traceEntries = experimentElement.getTraces();
    int cacheSize = Integer.MAX_VALUE;
    final ITmfTrace[] traces = new ITmfTrace[traceEntries.size()];
    for (int i = 0; i < traceEntries.size(); i++) {
        TmfTraceElement element = traceEntries.get(i);
        // Since trace is under an experiment, use the original trace from
        // the traces folder
        element = element.getElementUnderTraceFolder();
        ITmfTrace trace = null;
        if (element.getParent() instanceof TmfExperimentElement) {
            TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement, element.getTypeName()), NLS.bind(Messages.TmfOpenTraceHelper_TraceNotFound, element.getElementPath()));
        } else {
            trace = openTraceElement(element);
        }
        if (trace == null) {
            for (int j = 0; j < i; j++) {
                traces[j].dispose();
            }
            experiment.dispose();
            return null;
        }
        cacheSize = Math.min(cacheSize, trace.getCacheSize());
        traces[i] = trace;
    }
    // Create the experiment
    experiment.initExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource(), experimentElement.getTraceType());
    return experiment;
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)

Aggregations

TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)55 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)33 Test (org.junit.Test)31 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)11 TmfTraceOpenedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal)9 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)8 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)7 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)7 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)7 Nullable (org.eclipse.jdt.annotation.Nullable)5 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)3 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)3 TmfTraceSelectedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal)3 ITmfTimestampTransform (org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)3 SynchronizationAlgorithm (org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm)3 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)3 CtfTmfEvent (org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent)3 Before (org.junit.Before)3