use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.
the class TsTransformFactoryTest method transformIdentity.
/**
* Test with identity
*/
@Test
public void transformIdentity() {
final ITmfTimestampTransform identity = TimestampTransformFactory.createWithOffset(0);
final ITmfTimestampTransform innefficientIdentity = new TmfConstantTransform();
final ITmfTimestampTransform compositeInnefficientIdentity = identity.composeWith(innefficientIdentity);
final ITmfTimestampTransform compositeInnefficientIdentity2 = innefficientIdentity.composeWith(innefficientIdentity);
final ITmfTimestampTransform compositeInnefficientIdentity3 = innefficientIdentity.composeWith(identity);
assertEquals(t0, identity.transform(t0));
assertEquals(tn0, identity.transform(tn0));
assertEquals(t100, identity.transform(t100));
assertEquals(t1e2, identity.transform(t100));
assertEquals(t1e2, identity.transform(t1e2));
assertEquals(t1e3, identity.transform(t1e3));
assertEquals(tn100, identity.transform(tn100));
// bad practice
assertEquals(t0, innefficientIdentity.transform(t0));
// bad
assertEquals(t0, compositeInnefficientIdentity.transform(t0));
// practice
// bad
assertEquals(t0, compositeInnefficientIdentity2.transform(t0));
// practice
// bad
assertEquals(t0, compositeInnefficientIdentity3.transform(t0));
// practice
}
use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.
the class SyncTest method testFullyIncrementalSerialization.
/**
* Testing the serialization of the fully incremental synchronization
* algorithm
*/
@Test
public void testFullyIncrementalSerialization() {
/* Do a run of synchronization and check the results */
SynchronizationAlgorithm syncAlgo = SynchronizationAlgorithmFactory.getFullyIncrementalAlgorithm();
syncAlgo.init(fTraces);
addSyncMatch(syncAlgo, t2, 1, t1, 1);
addSyncMatch(syncAlgo, t1, 1, t2, 3);
addSyncMatch(syncAlgo, t2, 2, t1, 3);
addSyncMatch(syncAlgo, t1, 3, t2, 5);
addSyncMatch(syncAlgo, t1, 4, t2, 8);
addSyncMatch(syncAlgo, t2, 4, t1, 5);
addSyncMatch(syncAlgo, t2, 4, t1, 6);
addSyncMatch(syncAlgo, t1, 6, t2, 7);
ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(t2);
ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(t1);
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
assertEquals(syncAlgo.getTimestampTransform(t1.getHostId()), tt1);
assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
assertEquals(syncAlgo.getTimestampTransform(t2.getHostId()), tt2);
/* Serialize the object */
String filePath = null;
try {
File temp = File.createTempFile("serialSyncAlgo", ".tmp");
filePath = temp.getAbsolutePath();
} catch (IOException e) {
fail("Could not create temporary file for serialization");
}
assertNotNull(filePath);
try (FileOutputStream fileOut = new FileOutputStream(filePath);
ObjectOutputStream out = new ObjectOutputStream(fileOut)) {
out.writeObject(syncAlgo);
} catch (IOException e) {
fail("Error serializing the synchronization algorithm " + e.getMessage());
}
SynchronizationAlgorithm deserialAlgo = null;
/* De-Serialize the object */
try (FileInputStream fileIn = new FileInputStream(filePath);
ObjectInputStream in = new ObjectInputStream(fileIn)) {
deserialAlgo = (SynchronizationAlgorithm) in.readObject();
} catch (IOException | ClassNotFoundException e) {
fail("Error de-serializing the synchronization algorithm " + e.getMessage());
}
/* Check that the deserialize algorithm is equivalent to original */
assertNotNull(deserialAlgo);
assertTrue(deserialAlgo instanceof SyncAlgorithmFullyIncremental);
assertEquals(SyncQuality.ACCURATE, deserialAlgo.getSynchronizationQuality(t1, t2));
assertEquals(tt1, deserialAlgo.getTimestampTransform(t1));
assertEquals(tt2, deserialAlgo.getTimestampTransform(t2));
}
use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.
the class TsTransformTest method testIdentityTransform.
/**
* Test for the identity transform
*/
@Test
public void testIdentityTransform() {
ITmfTimestampTransform tt = TmfTimestampTransform.IDENTITY;
assertEquals(ts, tt.transform(ts));
assertEquals(oTs, tt.transform(oTs));
}
use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.
the class TmfExperiment method initExperiment.
/**
* Initialization of an experiment, taking the type, path, traces,
* indexPageSize and resource
*
* @param type
* the event type
* @param path
* the experiment path
* @param traces
* the experiment set of traces
* @param indexPageSize
* the experiment index page size
* @param resource
* the resource associated to the experiment
*/
public void initExperiment(final Class<? extends ITmfEvent> type, final String path, final ITmfTrace[] traces, final int indexPageSize, @Nullable final IResource resource) {
setCacheSize(indexPageSize);
setStreamingInterval(0);
Multimap<String, ITmfTrace> tracesPerHost = HashMultimap.create();
// traces have to be set before super.initialize()
if (traces != null) {
// initialize
for (ITmfTrace trace : traces) {
if (trace != null) {
tracesPerHost.put(trace.getHostId(), trace);
addChild(trace);
}
}
}
try {
super.initialize(resource, path, type);
} catch (TmfTraceException e) {
// $NON-NLS-1$
Activator.logError("Error initializing experiment", e);
}
if (resource != null) {
synchronizeTraces();
}
/*
* For all traces on the same host, if two or more specify different
* clock offsets, adjust their clock offset by the average of all of them.
*
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=484620
*/
Function<ITmfPropertiesProvider, @Nullable Long> offsetGetter = trace -> {
String offset = trace.getProperties().get(CLOCK_OFFSET_PROPERTY);
if (offset == null) {
return null;
}
try {
return Long.parseLong(offset);
} catch (NumberFormatException e) {
return null;
}
};
for (Collection<ITmfTrace> values : tracesPerHost.asMap().values()) {
/*
* Only attempt to synchronize traces that provide a clock_offset
* property.
*/
Collection<ITmfPropertiesProvider> tracesToSynchronize = values.stream().filter(ITmfPropertiesProvider.class::isInstance).map(ITmfPropertiesProvider.class::cast).filter(trace -> offsetGetter.apply(trace) != null).collect(Collectors.toList());
if (tracesToSynchronize.size() < 2) {
continue;
}
/* Only synchronize traces if they haven't previously been synchronized */
if (tracesToSynchronize.stream().map(trace -> ((ITmfTrace) trace).getTimestampTransform()).anyMatch(transform -> !transform.equals(TmfTimestampTransform.IDENTITY))) {
continue;
}
/* Calculate the average of all clock offsets */
BigInteger sum = BigInteger.ZERO;
for (ITmfPropertiesProvider trace : tracesToSynchronize) {
long offset = checkNotNull(offsetGetter.apply(trace));
sum = sum.add(BigInteger.valueOf(offset));
}
long average = sum.divide(BigInteger.valueOf(tracesToSynchronize.size())).longValue();
if (average > CLOCK_OFFSET_THRESHOLD_NS) {
Activator.logWarning(// $NON-NLS-1$ //$NON-NLS-2$
"Average clock correction (" + average + ") is higher than threshold of " + CLOCK_OFFSET_THRESHOLD_NS + " ns for experiment " + // $NON-NLS-1$
this.toString());
}
/*
* Apply the offset correction to all identified traces, but only if
* they do not already have an equivalent one (for example, closing
* and re-opening the same experiment should not retrigger building
* all supplementary files).
*/
tracesToSynchronize.forEach(t -> {
long offset = checkNotNull(offsetGetter.apply(t));
long delta = average - offset;
ITmfTrace trace = (ITmfTrace) t;
ITmfTimestampTransform currentTransform = trace.getTimestampTransform();
ITmfTimestampTransform newTransform = TimestampTransformFactory.createWithOffset(delta);
if (!newTransform.equals(currentTransform)) {
TmfTraceManager.deleteSupplementaryFiles(trace);
trace.setTimestampTransform(newTransform);
}
});
}
}
use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.
the class ExperimentSyncTest method testExperimentSync.
/**
* Testing experiment synchronization
*/
@Test
public void testExperimentSync() {
CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_SRC);
CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.SYNC_DEST);
ITmfTrace[] traces = { trace1, trace2 };
TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null);
SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
trace1.setTimestampTransform(tt1);
trace2.setTimestampTransform(tt2);
assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1.toString());
assertEquals(TimestampTransformFactory.getDefaultTransform(), tt2);
assertEquals(syncAlgo.getTimestampTransform(trace1.getHostId()), trace1.getTimestampTransform());
assertEquals(syncAlgo.getTimestampTransform(trace2.getHostId()), trace2.getTimestampTransform());
experiment.dispose();
}
Aggregations