Search in sources :

Example 16 with ITmfTimestampTransform

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
}
Also used : TmfConstantTransform(org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfConstantTransform) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) Test(org.junit.Test)

Example 17 with ITmfTimestampTransform

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) SyncAlgorithmFullyIncremental(org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental) IOException(java.io.IOException) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) SynchronizationAlgorithm(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 18 with ITmfTimestampTransform

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));
}
Also used : ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) Test(org.junit.Test)

Example 19 with ITmfTimestampTransform

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);
            }
        });
    }
}
Also used : TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) MultiStatus(org.eclipse.core.runtime.MultiStatus) TmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp) ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) TmfTraceType(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType) CoreException(org.eclipse.core.runtime.CoreException) TmfExperimentLocation(org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation) ByteBuffer(java.nio.ByteBuffer) IStatus(org.eclipse.core.runtime.IStatus) Activator(org.eclipse.tracecompass.internal.tmf.core.Activator) TmfTimestampTransform(org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransform) HashMultimap(com.google.common.collect.HashMultimap) Nullable(org.eclipse.jdt.annotation.Nullable) TimestampTransformFactory(org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory) BigInteger(java.math.BigInteger) ITmfPersistentlyIndexable(org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable) SynchronizationAlgorithm(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTraceRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) TmfBaseAspects(org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) TmfTraceSynchronizedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSynchronizedSignal) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Collectors(java.util.stream.Collectors) TmfCommonConstants(org.eclipse.tracecompass.tmf.core.TmfCommonConstants) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) List(java.util.List) TmfBTreeTraceIndexer(org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) TmfLocationArray(org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfLocationArray) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) ITmfPropertiesProvider(org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider) TmfExperimentContext(org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentContext) IProject(org.eclipse.core.resources.IProject) SynchronizationManager(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationManager) NonNullUtils.checkNotNull(org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ITmfTraceIndexer(org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer) File(java.io.File) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) Lock(java.util.concurrent.locks.Lock) ContextTuple(org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentContext.ContextTuple) IResource(org.eclipse.core.resources.IResource) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) Collections(java.util.Collections) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) BigInteger(java.math.BigInteger) ITmfPropertiesProvider(org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider)

Example 20 with ITmfTimestampTransform

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();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) SynchronizationAlgorithm(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm) Test(org.junit.Test)

Aggregations

ITmfTimestampTransform (org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)20 Test (org.junit.Test)17 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)7 SynchronizationAlgorithm (org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm)5 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)4 TmfTimestampTransformLinear (org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinear)3 TmfContext (org.eclipse.tracecompass.tmf.core.trace.TmfContext)3 File (java.io.File)2 SyncAlgorithmFullyIncremental (org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental)2 TmfConstantTransform (org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfConstantTransform)2 TmfTimestampTransformLinearFast (org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinearFast)2 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)2 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Multimap (com.google.common.collect.Multimap)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1