Search in sources :

Example 86 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method moveToPage.

/**
 * Moves to a certain page.
 *
 * @param notifyAll
 *            true to broadcast time range signal to other signal handlers
 *            else false
 */
protected void moveToPage(boolean notifyAll) {
    TmfTimeRange window = null;
    fLock.lock();
    try {
        // Safety check
        if (fCurrentPage > fCheckPoints.size()) {
            return;
        }
        window = fCheckPoints.get(fCurrentPage);
    } finally {
        fLock.unlock();
    }
    if (window == null) {
        window = TmfTimeRange.ETERNITY;
    }
    fPageRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.FOREGROUND) {

        private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<>();

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
            if (sdEvent != null) {
                fSdEvent.add(sdEvent);
            }
        }

        @Override
        public void handleSuccess() {
            fillCurrentPage(fSdEvent);
            super.handleSuccess();
        }
    };
    fTrace.sendRequest(fPageRequest);
    if (notifyAll) {
        TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime());
        broadcast(new TmfWindowRangeUpdatedSignal(this, timeRange, fTrace));
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 87 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent 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 88 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method loadTrace.

/**
 * Method for loading the current selected trace into the view. Sub-class
 * need to override this method to add the view specific implementation.
 */
protected void loadTrace() {
    ITmfEventRequest indexRequest = null;
    fLock.lock();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        final Job job = new IndexingJob("Indexing " + getName() + "...");
        job.setUser(false);
        job.schedule();
        indexRequest = fIndexRequest;
        cancelOngoingRequests();
        TmfTimeRange window = TmfTimeRange.ETERNITY;
        fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {

            private ITmfTimestamp fFirstTime = null;

            private ITmfTimestamp fLastTime = null;

            private int fNbSeqEvents = 0;

            private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<>(MAX_NUM_OF_MSG);

            @Override
            public void handleData(ITmfEvent event) {
                super.handleData(event);
                ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
                ITmfTimestamp firstTime = fFirstTime;
                ITmfTimestamp lastTime = fLastTime;
                if (sdEvent != null) {
                    ++fNbSeqEvents;
                    if (firstTime == null) {
                        firstTime = event.getTimestamp();
                        fFirstTime = firstTime;
                    }
                    lastTime = event.getTimestamp();
                    fLastTime = lastTime;
                    if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
                        fLock.lock();
                        try {
                            fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                            if (fView != null) {
                                fView.updateCoolBar();
                            }
                        } finally {
                            fLock.unlock();
                        }
                        fFirstTime = null;
                    }
                    if (fNbSeqEvents > MAX_NUM_OF_MSG) {
                        // page is full
                        return;
                    }
                    fSdEvents.add(sdEvent);
                    if (fNbSeqEvents == MAX_NUM_OF_MSG) {
                        fillCurrentPage(fSdEvents);
                    }
                }
            }

            @Override
            public void handleSuccess() {
                final ITmfTimestamp firstTime = fFirstTime;
                final ITmfTimestamp lastTime = fLastTime;
                if ((firstTime != null) && (lastTime != null)) {
                    fLock.lock();
                    try {
                        fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                        if (fView != null) {
                            fView.updateCoolBar();
                        }
                    } finally {
                        fLock.unlock();
                    }
                }
                if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
                    fillCurrentPage(fSdEvents);
                }
                super.handleSuccess();
            }

            @Override
            public void handleCompleted() {
                if (fEvents.isEmpty()) {
                    fFrame = new Frame();
                    // make sure that view is not null when setting frame
                    SDView sdView;
                    fLock.lock();
                    try {
                        sdView = fView;
                    } finally {
                        fLock.unlock();
                    }
                    if (sdView != null) {
                        sdView.setFrameSync(fFrame);
                    }
                }
                super.handleCompleted();
                job.cancel();
            }
        };
    } finally {
        fLock.unlock();
    }
    if (indexRequest != null && !indexRequest.isCompleted()) {
        indexRequest.cancel();
    }
    resetLoader();
    fTrace.sendRequest(fIndexRequest);
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Job(org.eclipse.core.runtime.jobs.Job) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

Example 89 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class CopyToClipboardOperation method copy.

private IStatus copy(final StringBuilder sb, final IProgressMonitor monitor) {
    ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, fStartRank, (int) (fEndRank - fStartRank + 1), ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (monitor.isCanceled()) {
                cancel();
                return;
            }
            monitor.worked(1);
            if (fFilter == null || fFilter.matches(event)) {
                try {
                    boolean needTab = false;
                    for (TmfEventTableColumn column : fColumns) {
                        if (needTab) {
                            sb.append('\t');
                        }
                        sb.append(column.getItemString(event));
                        needTab = true;
                    }
                    sb.append(LINE_SEPARATOR);
                } catch (OutOfMemoryError e) {
                    sb.setLength(0);
                    sb.trimToSize();
                    showErrorDialog();
                    cancel();
                }
            }
        }
    };
    fTrace.sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Wait for completion interrupted for copy to clipboard ", e);
        Thread.currentThread().interrupt();
    }
    return Status.OK_STATUS;
}
Also used : ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 90 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class BtfTraceTest method testRead1stEvent.

/**
 * Read the first event
 */
@Test
public void testRead1stEvent() {
    ITmfContext ctx = fixture.seekEvent(0);
    ITmfEvent event = fixture.getNext(ctx);
    assertNotNull(event);
    validateCommentEvent(ECXPECT_CONTENT_EVENT_0, event);
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Aggregations

ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)182 Test (org.junit.Test)127 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)112 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)40 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)30 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)27 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)25 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)24 NonNull (org.eclipse.jdt.annotation.NonNull)20 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)17 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)16 Vector (java.util.Vector)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 Predicate (java.util.function.Predicate)14 TmfTraceUtils (org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 CtfTestTrace (org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace)13 CtfTmfTestTraceUtils (org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils)13 Assert.assertEquals (org.junit.Assert.assertEquals)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)13