Search in sources :

Example 1 with TimeReference

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

use of org.eclipse.tracecompass.tmf.core.markers.TimeReference 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 3 with TimeReference

use of org.eclipse.tracecompass.tmf.core.markers.TimeReference 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)3 TimeReference (org.eclipse.tracecompass.tmf.core.markers.TimeReference)3 ArrayList (java.util.ArrayList)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 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)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 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1 Test (org.junit.Test)1