Search in sources :

Example 6 with TmfTraceContext

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

the class AbstractSegmentStoreDensityViewer method loadTrace.

/**
 * A Method to load a trace into the viewer.
 *
 * @param trace
 *            A trace to apply in the viewer
 */
protected void loadTrace(@Nullable ITmfTrace trace) {
    clearContent();
    TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
    TmfTimeRange windowRange = ctx.getWindowRange();
    innerLoadTrace(trace);
    updateWindowRange(windowRange, true);
    fTrace = trace;
    fCurrentTimeRange = windowRange;
    zoom(getDefaultRange());
}
Also used : TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)

Example 7 with TmfTraceContext

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

the class TmfTraceManagerTest method testTwoTracesTimestampValid.

// ------------------------------------------------------------------------
// Test multiple, non-overlapping traces in parallel
// ------------------------------------------------------------------------
/**
 * Test, with two traces in parallel, when we select a timestamp that is
 * part of the first trace.
 *
 * The first trace's timestamp should be updated, but the second trace's one
 * should not change.
 */
@Test
public void testTwoTracesTimestampValid() {
    openTrace(trace1);
    openTrace(trace2);
    selectTrace(trace1);
    ITmfTimestamp ts = TmfTimestamp.fromNanos(t1start + ONE_SECOND);
    selectTimestamp(ts);
    /* Timestamp of trace1 should have been updated */
    TmfTraceContext ctx = tm.getCurrentTraceContext();
    assertEquals(ts, ctx.getSelectionRange().getStartTime());
    assertEquals(ts, ctx.getSelectionRange().getEndTime());
    /* Timestamp of trace2 should not have changed */
    selectTrace(trace2);
    ctx = tm.getCurrentTraceContext();
    assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getStartTime());
    assertEquals(trace2.getStartTime(), ctx.getSelectionRange().getEndTime());
}
Also used : TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Test(org.junit.Test)

Example 8 with TmfTraceContext

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

the class TmfTimeViewer method selectionRangeUpdated.

/**
 * Signal handler for handling of the selected range signal.
 *
 * @param signal
 *            The {@link TmfSelectionRangeUpdatedSignal}
 * @since 1.0
 */
@TmfSignalHandler
public void selectionRangeUpdated(@Nullable TmfSelectionRangeUpdatedSignal signal) {
    final ITmfTrace trace = fTrace;
    if (signal != null && (signal.getSource() != this) && (trace != null)) {
        TmfTraceContext ctx = TmfTraceManager.getInstance().getTraceContext(trace);
        long selectedTime = ctx.getSelectionRange().getStartTime().toNanos();
        long selectedEndTime = ctx.getSelectionRange().getEndTime().toNanos();
        setSelectionRange(selectedTime, selectedEndTime);
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 9 with TmfTraceContext

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

the class TmfTimeViewer method windowRangeUpdated.

/**
 * Signal handler for handling of the window range signal.
 *
 * @param signal
 *            The {@link TmfWindowRangeUpdatedSignal}
 * @since 1.0
 */
@TmfSignalHandler
public void windowRangeUpdated(@Nullable TmfWindowRangeUpdatedSignal signal) {
    final ITmfTrace trace = fTrace;
    if (signal != null && trace != null) {
        TmfTraceContext ctx = TmfTraceManager.getInstance().getTraceContext(trace);
        // Validate the time range
        TmfTimeRange range = ctx.getWindowRange().getIntersection(trace.getTimeRange());
        if (range == null) {
            return;
        }
        if (signal.getSource() != this) {
            // Update the time range
            long windowStartTime = range.getStartTime().toNanos();
            long windowEndTime = range.getEndTime().toNanos();
            setWindowRange(windowStartTime, windowEndTime);
        }
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 10 with TmfTraceContext

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

TmfTraceContext (org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext)19 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)11 TmfSignalHandler (org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)7 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)6 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)3 ArrayList (java.util.ArrayList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 FlowScopeLog (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog)2 FlowScopeLogBuilder (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder)2 ResourcesEntryModel (org.eclipse.tracecompass.internal.analysis.os.linux.core.resourcesstatus.ResourcesEntryModel)2 ITmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel)2 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)2 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1