Search in sources :

Example 1 with ITimeReference

use of org.eclipse.tracecompass.tmf.core.markers.ITimeReference in project tracecompass by tracecompass.

the class PeriodicAnnotationProvider method adjustReference.

/*
     * Adjust to a reference that is closer to the start time, to avoid rounding
     * errors in floating point calculations with large numbers.
     */
private ITimeReference adjustReference(ITimeReference baseReference, long time) {
    long offsetIndex = (long) ((time - baseReference.getTime()) / fPeriod);
    long offsetTime = 0;
    Fraction fraction = fPeriodFraction;
    if (fraction != null) {
        /*
             * If period = int num/den, find an offset index that is an exact
             * multiple of den and calculate index * period = (index * int) +
             * (index / den * num), all exact calculations.
             */
        offsetIndex = offsetIndex - offsetIndex % fraction.getDenominator();
        offsetTime = offsetIndex * fPeriodInteger + offsetIndex / fraction.getDenominator() * fraction.getNumerator();
    } else {
        /*
             * Couldn't compute fractional part as fraction, use simple
             * multiplication but with possible rounding error.
             */
        offsetTime = Math.round(offsetIndex * fPeriod);
    }
    return new TimeReference(baseReference.getTime() + offsetTime, baseReference.getIndex() + offsetIndex);
}
Also used : Fraction(org.apache.commons.lang3.math.Fraction) TimeReference(org.eclipse.tracecompass.tmf.core.markers.TimeReference) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference)

Example 2 with ITimeReference

use of org.eclipse.tracecompass.tmf.core.markers.ITimeReference in project tracecompass by tracecompass.

the class PeriodicAnnotationProvider method fetchAnnotations.

@Override
@NonNull
public TmfModelResponse<@NonNull AnnotationModel> fetchAnnotations(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    if (times == null) {
        return EMPTY_MODEL_RESPONSE;
    }
    int size = times.size() - 1;
    long startTime = times.get(0);
    long endTime = times.get(size);
    long resolution = (endTime - startTime) / (size);
    if (startTime > endTime) {
        return EMPTY_MODEL_RESPONSE;
    }
    long step = Math.max(Math.round(fPeriod), resolution);
    OutputElementStyle[] styles = new OutputElementStyle[2];
    styles[0] = generateOutputElementStyle(fColor1);
    RGBAColor color2 = fColor2;
    styles[1] = color2 == null ? styles[0] : generateOutputElementStyle(color2);
    Collection<Annotation> annotations = new ArrayList<>();
    /* Subtract 1.5 periods to ensure previous marker is included */
    long time = startTime - Math.max(Math.round(1.5 * fPeriod), resolution);
    ITimeReference reference = adjustReference(fReference, time);
    Annotation annotation = null;
    while (true) {
        long index = Math.round((time - reference.getTime()) / fPeriod) + reference.getIndex();
        long markerTime = Math.round((index - reference.getIndex()) * fPeriod) + reference.getTime();
        long duration = (fColor2 == null) ? 0 : Math.round((index + 1 - reference.getIndex()) * fPeriod) + reference.getTime() - markerTime;
        long labelIndex = index;
        if (fRollover != 0) {
            labelIndex %= fRollover;
            if (labelIndex < 0) {
                labelIndex += fRollover;
            }
        }
        /* Add previous marker if current is visible */
        if ((markerTime >= startTime || markerTime + duration > startTime) && annotation != null) {
            annotations.add(annotation);
        }
        if (isApplicable(labelIndex)) {
            OutputElementStyle style = Objects.requireNonNull((index % 2) == 0 ? styles[0] : styles[1]);
            annotation = new Annotation(markerTime, duration, -1, getAnnotationLabel(labelIndex), style);
        } else {
            annotation = null;
        }
        if (markerTime > endTime || (monitor != null && monitor.isCanceled())) {
            if (annotation != null && isApplicable(labelIndex)) {
                /* The next marker out of range is included */
                annotations.add(annotation);
            }
            break;
        }
        time += step;
    }
    Map<String, Collection<Annotation>> model = new HashMap<>();
    model.put(fCategory, annotations);
    // $NON-NLS-1$
    return new TmfModelResponse<>(new AnnotationModel(model), Status.COMPLETED, "");
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 3 with ITimeReference

use of org.eclipse.tracecompass.tmf.core.markers.ITimeReference in project tracecompass by tracecompass.

the class PeriodicAnnotationProviderTest method testReference.

/**
 * Test a periodic annotation provider with non-zero reference.
 */
@Test
public void testReference() {
    ITimeReference reference = new TimeReference(250L, 10);
    IOutputAnnotationProvider provider = new PeriodicAnnotationProvider(CATEGORY, reference, 100L, 0, COLOR, null);
    Map<String, List<Annotation>> expected = ImmutableMap.of(CATEGORY, Arrays.asList(new Annotation(-50L, 0L, -1, "7", COLOR_STYLE), new Annotation(50L, 0L, -1, "8", COLOR_STYLE), new Annotation(150L, 0L, -1, "9", COLOR_STYLE), new Annotation(250L, 0L, -1, "10", COLOR_STYLE), new Annotation(350L, 0L, -1, "11", COLOR_STYLE)));
    Map<String, Object> fetchParameters = ImmutableMap.of(DataProviderParameterUtils.REQUESTED_TIME_KEY, StateSystemUtils.getTimes(0L, 300L, 1));
    assertAnnotationModelResponse(expected, provider.fetchAnnotations(fetchParameters, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PeriodicAnnotationProvider(org.eclipse.tracecompass.internal.tmf.core.annotations.PeriodicAnnotationProvider) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) ArrayList(java.util.ArrayList) List(java.util.List) TimeReference(org.eclipse.tracecompass.tmf.core.markers.TimeReference) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) Test(org.junit.Test)

Example 4 with ITimeReference

use of org.eclipse.tracecompass.tmf.core.markers.ITimeReference in project tracecompass by tracecompass.

the class CustomAnnotationProvider method configure.

private CustomPeriodicAnnotationProvider configure(Marker marker) {
    if (marker instanceof PeriodicMarker) {
        PeriodicMarker periodicMarker = (PeriodicMarker) marker;
        long rollover = periodicMarker.getRange().hasUpperBound() ? (periodicMarker.getRange().upperEndpoint() - periodicMarker.getRange().lowerEndpoint() + 1) : 0;
        RGBAColor evenColor = getColor(marker);
        RGBAColor oddColor = getOddColor(evenColor);
        ITmfTrace trace = fTrace;
        double period = IMarkerConstants.convertToNanos(periodicMarker.getPeriod(), periodicMarker.getUnit(), trace);
        String referenceId = periodicMarker.getReferenceId();
        ITimeReference baseReference = null;
        if (trace instanceof IAdaptable && !referenceId.isEmpty()) {
            ITimeReferenceProvider adapter = ((IAdaptable) trace).getAdapter(ITimeReferenceProvider.class);
            if (adapter != null) {
                baseReference = adapter.apply(referenceId);
            }
        }
        if (baseReference == null) {
            baseReference = ITimeReference.ZERO;
        }
        ITimeReference reference = new TimeReference(baseReference.getTime() + Math.round(IMarkerConstants.convertToNanos(periodicMarker.getOffset(), periodicMarker.getUnit(), trace)), baseReference.getIndex());
        return new CustomPeriodicAnnotationProvider(periodicMarker, reference, period, rollover, evenColor, oddColor);
    }
    // $NON-NLS-1$
    throw new IllegalArgumentException("Marker must be of type PeriodicMarker or SubMarker");
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IAdaptable(org.eclipse.core.runtime.IAdaptable) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) TimeReference(org.eclipse.tracecompass.tmf.core.markers.TimeReference) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) ITimeReferenceProvider(org.eclipse.tracecompass.tmf.core.markers.ITimeReferenceProvider)

Aggregations

ITimeReference (org.eclipse.tracecompass.tmf.core.markers.ITimeReference)4 TimeReference (org.eclipse.tracecompass.tmf.core.markers.TimeReference)3 ArrayList (java.util.ArrayList)2 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)2 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Fraction (org.apache.commons.lang3.math.Fraction)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 AnnotationModel (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel)1 IOutputAnnotationProvider (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider)1 PeriodicAnnotationProvider (org.eclipse.tracecompass.internal.tmf.core.annotations.PeriodicAnnotationProvider)1 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)1 ITimeReferenceProvider (org.eclipse.tracecompass.tmf.core.markers.ITimeReferenceProvider)1 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1