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);
}
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()));
}
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");
}
Aggregations