Search in sources :

Example 26 with TmfTraceException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException in project tracecompass by tracecompass.

the class XYChartViewTest method before.

/**
 * Before the test is run, make the view see the items.
 *
 * Reset the perspective and close all the views.
 *
 * @throws TmfTraceException
 *             could not load a trace
 */
@Before
public void before() throws TmfTraceException {
    fBot = new SWTWorkbenchBot();
    fBot.closeAllEditors();
    for (SWTBotView viewBot : fBot.views()) {
        viewBot.close();
    }
    fTrace = new TmfTraceStub() {

        @Override
        @NonNull
        public String getName() {
            return "Stub";
        }

        @Override
        public TmfContext seekEvent(ITmfLocation location) {
            return new TmfContext();
        }
    };
    fTrace.setStartTime(TmfTimestamp.fromNanos(0));
    fTrace.setEndTime(TmfTimestamp.fromNanos(180));
    TmfTraceStub trace = fTrace;
    trace.initialize(null, "", ITmfEvent.class);
    assertNotNull(trace);
    // Register trace to trace manager
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null)));
    // Open view
    SWTBotUtils.openView(XYChartViewStub.ID);
    fViewBot = fBot.viewById(XYChartViewStub.ID);
    fViewBot.show();
    TmfChartView viewPart = (TmfChartView) fViewBot.getViewReference().getView(true);
    fXyViewer = viewPart.getChartViewer();
    // Wait till SWT chart is constructed
    fViewBot.bot().waitUntil(new DefaultCondition() {

        @Override
        public boolean test() throws Exception {
            return fXyViewer.getSwtChart() != null;
        }

        @Override
        public String getFailureMessage() {
            return "SWT Chart is null";
        }
    });
    // Wait for trace to be loaded
    resetTimeRange();
}
Also used : SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) TmfChartView(org.eclipse.tracecompass.tmf.ui.views.xychart.TmfChartView) NonNull(org.eclipse.jdt.annotation.NonNull) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) TmfTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation) Before(org.junit.Before)

Example 27 with TmfTraceException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException 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 TmfTraceException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException in project tracecompass by tracecompass.

the class BtfTrace method initTrace.

@Override
public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException {
    super.initTrace(resource, path, type);
    fFile = new File(path);
    try {
        // $NON-NLS-1$
        fFileInput = new RandomAccessFile(fFile, "r");
        parseHeader(fFileInput);
    } catch (IOException e) {
        throw new TmfTraceException(e.getMessage(), e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BufferedRandomAccessFile(org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BufferedRandomAccessFile(org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile)

Example 29 with TmfTraceException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException in project tracecompass by tracecompass.

the class PcapTrace method initTrace.

@Override
@NonNullByDefault({ DefaultLocation.TYPE_ARGUMENT })
public synchronized void initTrace(@Nullable IResource resource, @Nullable String path, @Nullable Class<? extends ITmfEvent> type) throws TmfTraceException {
    super.initTrace(resource, path, type);
    if (path == null) {
        // $NON-NLS-1$
        throw new TmfTraceException("No path has been specified.");
    }
    Path filePath = checkNotNull(Paths.get(path));
    try {
        fPcapFile = PcapHelper.getPcapFile(filePath);
    } catch (IOException | BadPcapFileException e) {
        throw new TmfTraceException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) BadPcapFileException(org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException) IOException(java.io.IOException) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault)

Example 30 with TmfTraceException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException in project tracecompass by tracecompass.

the class Uml2SDTestFacility method setupTrace.

private TmfTraceStub setupTrace(final ITmfEventParser parser) {
    try {
        // Create test trace object
        final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null);
        final File test = new File(FileLocator.toFileURL(location).toURI());
        return new TmfTraceStub(test.getPath(), 500, true, parser);
    } catch (final TmfTraceException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (final URISyntaxException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (final IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) TmfTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub) File(java.io.File) URL(java.net.URL)

Aggregations

TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)50 File (java.io.File)17 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)14 IStatus (org.eclipse.core.runtime.IStatus)12 TmfTraceOpenedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal)12 TmfTraceStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub)11 IOException (java.io.IOException)10 IPath (org.eclipse.core.runtime.IPath)8 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)8 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)8 TmfXmlKernelTraceStub (org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub)7 Performance (org.eclipse.test.performance.Performance)6 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)6 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)6 TmfTrace (org.eclipse.tracecompass.tmf.core.trace.TmfTrace)6 Before (org.junit.Before)6 LttngKernelTrace (org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace)5 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4