Search in sources :

Example 81 with TmfTimeRange

use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method windowRangeUpdated.

/**
 * Moves to the page that contains the current time provided by signal. No
 * message will be selected however the focus will be set to the message if
 * the provided time is the time of a message.
 *
 * @param signal
 *            The window range signal
 * @since 1.0
 */
@TmfSignalHandler
public void windowRangeUpdated(TmfWindowRangeUpdatedSignal signal) {
    fLock.lock();
    try {
        if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent && (!fCheckPoints.isEmpty())) {
            TmfTimeRange newTimeRange = signal.getCurrentRange();
            fIsSelect = false;
            fCurrentTime = newTimeRange.getStartTime();
            moveToMessage();
        }
    } finally {
        fLock.unlock();
    }
}
Also used : TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 82 with TmfTimeRange

use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.

the class TrimTraceHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
    final TmfCommonProjectElement traceElem = (firstElement instanceof TmfTraceElement) ? ((TmfTraceElement) firstElement).getElementUnderTraceFolder() : (TmfCommonProjectElement) firstElement;
    ITmfTrace trace = traceElem.getTrace();
    if (trace == null || !isValid(trace)) {
        /* That trace is not currently opened */
        return null;
    }
    /* Retrieve the current time range */
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange timeRange = tm.getTraceContext(trace).getSelectionRange();
    if (Objects.equals(timeRange.getStartTime(), timeRange.getEndTime())) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidTimeRange_DialogTitle, Messages.TrimTraces_InvalidTimeRange_DialogText);
        return null;
    }
    /* Ensure the time range is in the right direction */
    final TmfTimeRange tr = ((timeRange.getStartTime().compareTo(timeRange.getEndTime()) > 0) ? new TmfTimeRange(timeRange.getEndTime(), timeRange.getStartTime()) : timeRange);
    /*
         * Pop a dialog asking the user to select a parent directory for the new
         * trace.
         */
    TrimTraceDialog dialog = new TrimTraceDialog(shell, traceElem);
    if (dialog.open() != Window.OK) {
        return null;
    }
    Object result = dialog.getFirstResult();
    if (result == null) {
        /* Dialog was cancelled, take no further action. */
        return null;
    }
    /* Verify that the selected path is valid and writeable */
    final Path destinationPath = checkNotNull(Paths.get(result.toString()));
    if (destinationPath.toFile().exists()) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidDirectory_DialogTitle, Messages.TrimTraces_InvalidDirectory_DialogText);
        return null;
    }
    TraceToTrim toTrim = TraceToTrim.create(traceElem, destinationPath);
    if (toTrim == null) {
        return null;
    }
    try {
        toTrim.createDir();
    } catch (IOException e) {
        /* Should not happen since we have checked permissions, etc. */
        throw new ExecutionException(e.getMessage(), e);
    }
    TmfWorkspaceModifyOperation trimOperation = new TmfWorkspaceModifyOperation() {

        @Override
        public void execute(@Nullable IProgressMonitor monitor) throws CoreException {
            SubMonitor mon = SubMonitor.convert(monitor, 2);
            toTrim.trim(tr, mon);
            /*
                 * Import the new trace into the current project, at the
                 * top-level.
                 */
            TmfProjectElement currentProjectElement = traceElem.getProject();
            TmfTraceFolder traceFolder = currentProjectElement.getTracesFolder();
            toTrim.importTrace(mon);
            if (mon.isCanceled()) {
                return;
            }
            if (traceFolder != null) {
                Display.getDefault().asyncExec(toTrim::open);
            } else {
                // $NON-NLS-1$
                Activator.getDefault().logWarning("Trace folder does not exist: " + toTrim.fDestinationPath);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, trimOperation);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        TraceUtils.displayErrorMsg(Messages.TrimTraceHandler_failMsg, e.getMessage(), e);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) SubMonitor(org.eclipse.core.runtime.SubMonitor) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IOException(java.io.IOException) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) InvocationTargetException(java.lang.reflect.InvocationTargetException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Shell(org.eclipse.swt.widgets.Shell) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) TrimTraceDialog(org.eclipse.tracecompass.tmf.ui.project.wizards.TrimTraceDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) ISelection(org.eclipse.jface.viewers.ISelection) TmfWorkspaceModifyOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) Nullable(org.eclipse.jdt.annotation.Nullable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 83 with TmfTimeRange

use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method findInNextPages.

/**
 * Background search in trace for expression in criteria.
 *
 * @param findCriteria
 *            The find criteria
 * @return true if background request was started else false
 */
protected boolean findInNextPages(Criteria findCriteria) {
    fLock.lock();
    try {
        if (fFindJob != null) {
            return true;
        }
        int nextPage = fCurrentPage + 1;
        if ((nextPage) >= fCheckPoints.size()) {
            // we are at the end
            return false;
        }
        TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime(), fCheckPoints.get(fCheckPoints.size() - 1).getEndTime());
        fFindJob = new SearchJob(findCriteria, window);
        fFindJob.schedule();
        fView.toggleWaitCursorAsync(true);
    } finally {
        fLock.unlock();
    }
    return true;
}
Also used : TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)

Example 84 with TmfTimeRange

use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange 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 85 with TmfTimeRange

use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.

the class HistogramCurrentTimeControl method updateValue.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
protected void updateValue() {
    if (getValue() == Long.MIN_VALUE) {
        // $NON-NLS-1$
        fTextValue.setText("");
        return;
    }
    String string = fTextValue.getText();
    long value = getValue();
    try {
        value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
    } catch (ParseException e) {
    }
    if (getValue() != value) {
        // Make sure that the new time is within range
        ITmfTrace trace = fParentView.getTrace();
        if (trace != null) {
            TmfTimeRange range = trace.getTimeRange();
            long startTime = range.getStartTime().toNanos();
            long endTime = range.getEndTime().toNanos();
            if (value < startTime) {
                value = startTime;
            } else if (value > endTime) {
                value = endTime;
            }
        }
        // Set and propagate
        setValue(value);
        updateSelectionTime(value);
    } else {
        setValue(value);
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ParseException(java.text.ParseException) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)

Aggregations

TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)168 Test (org.junit.Test)98 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)53 TmfWindowRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal)29 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)24 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)24 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)21 TmfSignalHandler (org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)20 TmfSelectionRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal)19 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)16 SWTBotTimeGraph (org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph)16 Vector (java.util.Vector)13 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)12 TmfTraceManager (org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager)10 ITmfEventProvider (org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider)9 AbstractTimeGraphView (org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView)9 TmfTraceContext (org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext)8 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)8 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 Point (org.eclipse.swt.graphics.Point)7