Search in sources :

Example 36 with TmfSignalHandler

use of org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler in project tracecompass by tracecompass.

the class TmfTrace method traceOpened.

// ------------------------------------------------------------------------
// Signal handlers
// ------------------------------------------------------------------------
/**
 * Handler for the Trace Opened signal
 *
 * @param signal
 *            The incoming signal
 */
@TmfSignalHandler
public void traceOpened(TmfTraceOpenedSignal signal) {
    boolean signalIsForUs = false;
    ITmfEventProvider provider = this;
    while (provider != null) {
        if (provider == signal.getTrace()) {
            signalIsForUs = true;
            break;
        }
        provider = provider.getParent();
    }
    if (!signalIsForUs) {
        return;
    }
    /*
         * The signal is either for this trace, or for a parent of this trace.
         */
    IStatus status = executeAnalysis();
    if (!status.isOK()) {
        Activator.log(status);
    }
    /* Refresh supplementary files in separate thread to prevent deadlock */
    new // $NON-NLS-1$
    Thread(// $NON-NLS-1$
    "Refresh supplementary files") {

        @Override
        public void run() {
            TmfTraceManager.refreshSupplementaryFiles(TmfTrace.this);
        }
    }.start();
    if (signal.getTrace() == this) {
        /* Additionally, the signal is directly for this trace. */
        if (getNbEvents() == 0) {
            return;
        }
        /* For a streaming trace, the range updated signal should be sent
             * by the subclass when a new safe time is determined.
             */
        if (getStreamingInterval() > 0) {
            return;
        }
        if (isComplete()) {
            final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
            final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
            // Broadcast in separate thread to prevent deadlock
            broadcastAsync(rangeUpdatedsignal);
        }
        return;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) TmfTraceRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 37 with TmfSignalHandler

use of org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler in project tracecompass by tracecompass.

the class TmfTraceManager method traceOpened.

// ------------------------------------------------------------------------
// Signal handlers
// ------------------------------------------------------------------------
/**
 * Signal handler for the traceOpened signal.
 *
 * @param signal
 *            The incoming signal
 */
@TmfSignalHandler
public synchronized void traceOpened(final TmfTraceOpenedSignal signal) {
    final ITmfTrace trace = signal.getTrace();
    final IFile editorFile = signal.getEditorFile();
    final TmfTimeRange windowRange = trace.getInitialTimeRange();
    final ITmfTimestamp startTs = windowRange.getStartTime();
    final TmfTimeRange selectionRange = new TmfTimeRange(startTs, startTs);
    final TmfTraceContext startCtx = trace.createTraceContext(selectionRange, windowRange, editorFile, null);
    fTraces.put(trace, startCtx);
    IResource resource = trace.getResource();
    if (resource != null) {
        fInstanceCounts.add(resource);
        updateTraceContext(trace, builder -> builder.setInstanceNumber(fInstanceCounts.count(resource)));
    }
    /* We also want to set the newly-opened trace as the active trace */
    fCurrentTrace = trace;
}
Also used : IFile(org.eclipse.core.resources.IFile) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) IResource(org.eclipse.core.resources.IResource) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 38 with TmfSignalHandler

use of org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler in project tracecompass by tracecompass.

the class TmfTraceManager method windowRangeUpdated.

/**
 * Signal handler for the window range signal.
 *
 * If the signal trace is null, the window range of *all* valid traces will
 * be updated to the new window range. If the signal contains a trace, the
 * signal trace and time-synchronized traces will be updated, but not other
 * instances of the signal trace.
 *
 * @param signal
 *            The incoming signal
 * @since 1.0
 */
@TmfSignalHandler
public synchronized void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) {
    final ITmfTrace signalTrace = signal.getTrace();
    for (Map.Entry<ITmfTrace, TmfTraceContext> entry : fTraces.entrySet()) {
        ITmfTrace trace = checkNotNull(entry.getKey());
        if (signalTrace != null && !isSynchronized(trace, signalTrace)) {
            continue;
        }
        final TmfTimeRange validTr = getValidTimeRange(trace);
        if (validTr == null) {
            continue;
        }
        /* Determine the new time range */
        TmfTimeRange targetTr = signal.getCurrentRange().getIntersection(validTr);
        if (targetTr != null) {
            updateTraceContext(trace, builder -> builder.setWindowRange(targetTr));
        }
    }
}
Also used : TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 39 with TmfSignalHandler

use of org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler in project tracecompass by tracecompass.

the class OffsetDialog method traceOpened.

/**
 * Handler for the trace opened signal
 *
 * @param signal
 *            the trace opened signal
 */
@TmfSignalHandler
public void traceOpened(final TmfTraceOpenedSignal signal) {
    Display.getDefault().asyncExec(() -> {
        for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
            for (TmfTraceElement traceElement : fOffsetMap.keySet()) {
                if (traceElement.getResource().equals(trace.getResource())) {
                    if (fRefTimeMap.get(traceElement) == null) {
                        fRefTimeMap.put(traceElement, trace.getStartTime());
                        fViewer.getViewer().update(traceElement, null);
                    }
                    break;
                }
            }
        }
    });
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 40 with TmfSignalHandler

use of org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler in project tracecompass by tracecompass.

the class TmfEventsTable method selectionRangeUpdated.

/**
 * Handler for the selection range signal.
 *
 * @param signal
 *            The incoming signal
 * @since 1.0
 */
@TmfSignalHandler
public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
    ITmfTrace trace = fTrace;
    if ((signal.getSource() != this) && (trace != null) && (!fTable.isDisposed())) {
        Job timeSelectJob;
        synchronized (fTimeSelectMutexRule) {
            timeSelectJob = fTimeSelectJob;
            if (timeSelectJob != null) {
                timeSelectJob.cancel();
            }
            TmfTraceContext ctx = TmfTraceManager.getInstance().getTraceContext(trace);
            ITmfTimestamp ts = ctx.getSelectionRange().getStartTime();
            ITmfTimestamp tf = ctx.getSelectionRange().getEndTime();
            /*
                 * Run in separate thread to not block UI thread for too long.
                 */
            timeSelectJob = new // $NON-NLS-1$
            Job(// $NON-NLS-1$
            "Events table selection job") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    if (fTrace == null) {
                        return Status.OK_STATUS;
                    }
                    final Pair<Long, Long> selection = getSelectedRanks(monitor);
                    if (monitor.isCanceled() || (selection == null)) {
                        return Status.CANCEL_STATUS;
                    }
                    updateDisplayWithSelection(selection.getFirst().longValue(), selection.getSecond().longValue());
                    return Status.OK_STATUS;
                }

                /**
                 * Verify if the event is within the trace range and adjust if
                 * necessary.
                 * @param monitor
                 *                a progress monitor
                 * @return A pair of rank representing the selected area
                 */
                @Nullable
                private Pair<Long, Long> getSelectedRanks(IProgressMonitor monitor) {
                    /* Clamp the timestamp value to fit inside of the trace */
                    ITmfTimestamp timestampBegin = ts;
                    if (timestampBegin.compareTo(fTrace.getStartTime()) < 0) {
                        timestampBegin = fTrace.getStartTime();
                    }
                    if (timestampBegin.compareTo(fTrace.getEndTime()) > 0) {
                        timestampBegin = fTrace.getEndTime();
                    }
                    ITmfTimestamp timestampEnd = tf;
                    if (timestampEnd.compareTo(fTrace.getStartTime()) < 0) {
                        timestampEnd = fTrace.getStartTime();
                    }
                    if (timestampEnd.compareTo(fTrace.getEndTime()) > 0) {
                        timestampEnd = fTrace.getEndTime();
                    }
                    ITmfTimestamp tb;
                    ITmfTimestamp te;
                    long rankBegin;
                    long rankEnd;
                    ITmfContext contextBegin;
                    ITmfContext contextEnd;
                    if (monitor.isCanceled()) {
                        return null;
                    }
                    /* Adjust the rank of the selection to the right range */
                    if (timestampBegin.compareTo(timestampEnd) > 0) {
                        te = timestampEnd;
                        contextEnd = fTrace.seekEvent(te);
                        rankEnd = contextEnd.getRank();
                        contextEnd.dispose();
                        if (monitor.isCanceled()) {
                            return null;
                        }
                        /*
                             * To include all events at the begin time, seek at the
                             * next nanosecond and then use the previous rank
                             */
                        tb = timestampBegin.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
                        if (tb.compareTo(fTrace.getEndTime()) <= 0) {
                            contextBegin = fTrace.seekEvent(tb);
                            rankBegin = contextBegin.getRank();
                            contextBegin.dispose();
                        } else {
                            rankBegin = ITmfContext.UNKNOWN_RANK;
                        }
                        rankBegin = (rankBegin == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankBegin) - 1;
                        /*
                             * If no events in selection range, select only the next
                             * event
                             */
                        rankBegin = rankBegin >= rankEnd ? rankBegin : rankEnd;
                    } else {
                        tb = timestampBegin;
                        contextBegin = fTrace.seekEvent(tb);
                        rankBegin = contextBegin.getRank();
                        contextBegin.dispose();
                        if (monitor.isCanceled()) {
                            return null;
                        }
                        /*
                             * To include all events at the end time, seek at the
                             * next nanosecond and then use the previous rank
                             */
                        te = timestampEnd.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
                        if (te.compareTo(fTrace.getEndTime()) <= 0) {
                            contextEnd = fTrace.seekEvent(te);
                            rankEnd = contextEnd.getRank();
                            contextEnd.dispose();
                        } else {
                            rankEnd = ITmfContext.UNKNOWN_RANK;
                        }
                        rankEnd = (rankEnd == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankEnd) - 1;
                        /*
                             * If no events in selection range, select only the next
                             * event
                             */
                        rankEnd = rankEnd >= rankBegin ? rankEnd : rankBegin;
                    }
                    return new Pair<>(Long.valueOf(rankBegin), Long.valueOf(rankEnd));
                }

                private void updateDisplayWithSelection(final long rankBegin, final long rankEnd) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
                        // Return if table is disposed
                        if (fTable.isDisposed()) {
                            return;
                        }
                        if (fSelectedBeginRank == rankBegin && fSelectedRank == rankEnd) {
                            return;
                        }
                        fSelectedRank = rankEnd;
                        long toReveal = fSelectedBeginRank != rankBegin ? rankBegin : rankEnd;
                        fSelectedBeginRank = rankBegin;
                        int indexBegin = (int) rankBegin;
                        int indexEnd = (int) rankEnd;
                        if (fTable.getData(Key.FILTER_OBJ) != null) {
                            /* +1 for top filter status row */
                            indexBegin = fCache.getFilteredEventIndex(rankBegin) + 1;
                            indexEnd = rankEnd == rankBegin ? indexBegin : fCache.getFilteredEventIndex(rankEnd) + 1;
                        }
                        /* +1 for header row */
                        fTable.setSelectionRange(indexBegin + 1, indexEnd + 1);
                        fRawViewer.selectAndReveal(toReveal);
                        updateStatusLine(null);
                    });
                }
            };
            timeSelectJob.setSystem(true);
            /*
                 *  Make subsequent jobs not run concurrently so that they are
                 *  executed in order.
                 */
            timeSelectJob.setRule(fTimeSelectMutexRule);
            timeSelectJob.schedule();
            fTimeSelectJob = timeSelectJob;
        }
    }
}
Also used : TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) IStatus(org.eclipse.core.runtime.IStatus) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Job(org.eclipse.core.runtime.jobs.Job) Nullable(org.eclipse.jdt.annotation.Nullable) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Aggregations

TmfSignalHandler (org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)53 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)22 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)19 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)6 TmfTraceContext (org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext)6 Job (org.eclipse.core.runtime.jobs.Job)4 IFile (org.eclipse.core.resources.IFile)3 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)3 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)3 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)2 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)2 TmfSelectionRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal)2 TmfTraceStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub)2 HashMultiset (com.google.common.collect.HashMultiset)1