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