Search in sources :

Example 6 with ITmfTimestampTransform

use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.

the class TsTransformTest method testComposition.

/**
 * Test the transform composition function
 */
@Test
public void testComposition() {
    long t = 100;
    ITmfTimestampTransform ti = TmfTimestampTransform.IDENTITY;
    ITmfTimestampTransform ttl = new TmfTimestampTransformLinear(BigDecimal.valueOf(2.0), BigDecimal.valueOf(3));
    ITmfTimestampTransform ttl2 = new TmfTimestampTransformLinear(BigDecimal.valueOf(1.5), BigDecimal.valueOf(8));
    ITmfTimestampTransform tc1 = ti.composeWith(ttl);
    /* Should be ttl */
    assertEquals(ttl, tc1);
    assertEquals(203, tc1.transform(t));
    tc1 = ttl.composeWith(ti);
    /* Should be ttl also */
    assertEquals(ttl, tc1);
    assertEquals(203, tc1.transform(t));
    tc1 = ti.composeWith(ti);
    /* Should be identity */
    assertEquals(tc1, TmfTimestampTransform.IDENTITY);
    assertEquals(100, tc1.transform(t));
    tc1 = ttl.composeWith(ttl2);
    assertEquals(ttl.transform(ttl2.transform(t)), tc1.transform(t));
    assertEquals(319, tc1.transform(t));
    tc1 = ttl2.composeWith(ttl);
    assertEquals(ttl2.transform(ttl.transform(t)), tc1.transform(t));
    assertEquals(312, tc1.transform(t));
}
Also used : TmfTimestampTransformLinear(org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinear) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) Test(org.junit.Test)

Example 7 with ITmfTimestampTransform

use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.

the class TmfExperimentTest method testWithMultiHostClockOffset.

/**
 * Tests that opening an experiment whose traces already have a
 * synchronization formula will not eliminate that formula. This test makes
 * the supposition that the experiment was synchronized and the
 * synchronization added the clock offset correction to the total formula.
 */
@Test
public void testWithMultiHostClockOffset() {
    // Data for this specific test
    String hostId = "Test Host 1";
    String hostId2 = "Test Host 2";
    long minOffset = 2000;
    long offset = 1000;
    String clockOffset = "clock_offset";
    ITmfTimestampTransform tt1 = TimestampTransformFactory.createLinear(2.0, offset / 2);
    ITmfTimestampTransform tt2 = TimestampTransformFactory.createLinear(2.0, -offset / 2);
    ITmfTimestampTransform tt3 = TimestampTransformFactory.createWithOffset(offset);
    ITmfTrace t1 = new TestTrace("t1") {

        @Override
        @NonNull
        public String getHostId() {
            return hostId;
        }

        @Override
        @NonNull
        public Map<@NonNull String, @NonNull String> getProperties() {
            return ImmutableMap.of(clockOffset, String.valueOf(minOffset));
        }
    };
    t1.setTimestampTransform(tt1);
    ITmfTrace t2 = new TestTrace("t2") {

        @Override
        @NonNull
        public String getHostId() {
            return hostId;
        }

        @Override
        @NonNull
        public Map<@NonNull String, @NonNull String> getProperties() {
            return ImmutableMap.of(clockOffset, String.valueOf(minOffset + offset));
        }
    };
    t2.setTimestampTransform(tt2);
    ITmfTrace t3 = new TmfXmlTraceStubNs() {

        @Override
        @NonNull
        public String getHostId() {
            return hostId2;
        }
    };
    t3.setTimestampTransform(tt3);
    TmfExperiment exp = new TmfExperimentStub(EXPERIMENT, new ITmfTrace[] { t1, t2, t3 }, BLOCK_SIZE) {

        @Override
        public SynchronizationAlgorithm synchronizeTraces() {
            return new SyncAlgorithmFullyIncremental() {

                private static final long serialVersionUID = 4206172498287480153L;

                @Override
                public ITmfTimestampTransform getTimestampTransform(String h) {
                    if (hostId.equals(h)) {
                        return TimestampTransformFactory.createLinear(2.0, 0);
                    }
                    return tt3;
                }
            };
        }
    };
    try {
        assertEquals(tt1, t1.getTimestampTransform());
        assertEquals(tt2, t2.getTimestampTransform());
        assertEquals(tt3, t3.getTimestampTransform());
    } finally {
        exp.dispose();
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) SyncAlgorithmFullyIncremental(org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) TmfTestTrace(org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 8 with ITmfTimestampTransform

use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.

the class SyncSpanningTree method getTimestampTransform.

/**
 * Get the timestamp transform to a host
 *
 * FIXME: This might not work in situations where we have disjoint graphs
 * since we only calculate 1 root node and each tree has its own root. When
 * implementing the algorithm with minimal spanning tree, we will solve this
 * problem.
 *
 * @param host
 *            The host to reach
 * @return The timestamp transform to host
 */
public ITmfTimestampTransform getTimestampTransform(String host) {
    ITmfTimestampTransform result = TimestampTransformFactory.getDefaultTransform();
    String rootNode = getRootNode();
    /*
         * Compute the path from reference node to the given host id
         */
    if (rootNode != null) {
        List<Edge<String, ITmfTimestampTransform>> path = fSyncGraph.path(rootNode, host);
        /*
             * Compute the resulting transform by chaining each transforms on
             * the path.
             */
        for (Edge<String, ITmfTimestampTransform> edge : path) {
            result = result.composeWith(edge.getLabel());
        }
    }
    return result;
}
Also used : ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)

Example 9 with ITmfTimestampTransform

use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.

the class TimestampTransformBenchmark method testCompareTimestampTransformPerformance.

/**
 * Benchmark to compare the classic and fast timestamp transform.
 *
 * Ignore when running automatically, just for local benchmarks.
 */
@Ignore
@Test
public void testCompareTimestampTransformPerformance() {
    /*
         * We call constructors directly instead of TimestampTransformFactory to
         * create properly each transform type.
         */
    ITmfTimestampTransform classic = new TmfTimestampTransformLinear(Math.PI, 1234);
    ITmfTimestampTransform fast = new TmfTimestampTransformLinearFast(Math.PI, 1234);
    doTimestampTransformRun("Linear transform classic", classic, 5);
    doTimestampTransformRun("Linear transform fast", fast, 5);
}
Also used : TmfTimestampTransformLinear(org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinear) TmfTimestampTransformLinearFast(org.eclipse.tracecompass.internal.tmf.core.synchronization.TmfTimestampTransformLinearFast) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with ITmfTimestampTransform

use of org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform in project tracecompass by tracecompass.

the class OffsetTraceHandler method execute.

// ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    // Get the set of selected trace elements
    final Set<TmfTraceElement> traceElements = new HashSet<>();
    if (selection instanceof StructuredSelection) {
        Iterator<Object> iterator = ((StructuredSelection) selection).iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof TmfTraceElement) {
                TmfTraceElement trace = (TmfTraceElement) element;
                traceElements.add(trace.getElementUnderTraceFolder());
            } else if (element instanceof TmfExperimentElement) {
                TmfExperimentElement exp = (TmfExperimentElement) element;
                for (TmfTraceElement trace : exp.getTraces()) {
                    traceElements.add(trace.getElementUnderTraceFolder());
                }
            } else if (element instanceof TmfTraceFolder) {
                TmfTraceFolder folder = (TmfTraceFolder) element;
                traceElements.addAll(folder.getTraces());
            }
        }
    }
    if (traceElements.isEmpty()) {
        return null;
    }
    final Map<TmfTraceElement, Long> offsets = new LinkedHashMap<>(traceElements.size());
    for (TmfTraceElement trace : traceElements) {
        offsets.put(trace, 0L);
    }
    Shell shell = HandlerUtil.getActiveShellChecked(event);
    OffsetDialog dialog = new OffsetDialog(shell, offsets);
    dialog.open();
    if (dialog.getReturnCode() != Window.OK) {
        return null;
    }
    TmfWorkspaceModifyOperation operation = new TmfWorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            for (final Map.Entry<TmfTraceElement, Long> entry : offsets.entrySet()) {
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
                final TmfTraceElement trace = entry.getKey();
                Long offset = entry.getValue();
                if (offset != 0 && trace.getResource().exists()) {
                    Display.getDefault().syncExec(trace::closeEditors);
                    long previousOffset = TimestampTransformFactory.getTimestampTransform(trace.getResource()).transform(0);
                    ITmfTimestampTransform transform = TimestampTransformFactory.createWithOffset(previousOffset + offset);
                    trace.deleteSupplementaryResources();
                    // make sure the supplementary folder exists
                    trace.refreshSupplementaryFolder();
                    TimestampTransformFactory.setTimestampTransform(trace.getResource(), transform);
                    trace.refreshSupplementaryFolder();
                }
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        TraceUtils.displayErrorMsg(e.toString(), e.getTargetException().toString());
    }
    return null;
}
Also used : OffsetDialog(org.eclipse.tracecompass.internal.tmf.ui.project.dialogs.offset.OffsetDialog) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) ISelection(org.eclipse.jface.viewers.ISelection) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TmfWorkspaceModifyOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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