use of org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm in project tracecompass by tracecompass.
the class ExperimentSyncTest method testDjangoExperimentSync.
/**
* Testing synchronization with 3 traces, one of which synchronizes with
* both other
*/
@Test
public void testDjangoExperimentSync() {
CtfTmfTrace trace1 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_CLIENT);
CtfTmfTrace trace2 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_DB);
CtfTmfTrace trace3 = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DJANGO_HTTPD);
ITmfTrace[] traces = { trace1, trace2, trace3 };
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);
ITmfTimestampTransform tt3 = syncAlgo.getTimestampTransform(trace3);
trace1.setTimestampTransform(tt1);
trace2.setTimestampTransform(tt2);
trace3.setTimestampTransform(tt3);
assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2.toString());
assertEquals("TmfTimestampTransformLinearFast [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3.toString());
experiment.dispose();
}
use of org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm in project tracecompass by tracecompass.
the class SyncTest method testFullyIncremental.
/**
* Testing fully incremental algorithm with communication between the two
* traces
*/
@Test
public void testFullyIncremental() {
SynchronizationAlgorithm syncAlgo = SynchronizationAlgorithmFactory.getFullyIncrementalAlgorithm();
syncAlgo.init(fTraces);
assertEquals(SyncQuality.ABSENT, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t2, 1, t1, 1);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString());
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 1, t2, 3);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString());
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t2, 2, t1, 3);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0.5 ]]", syncAlgo.toString());
assertEquals(SyncQuality.APPROXIMATE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 3, t2, 5);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo.toString());
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 4, t2, 8);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo.toString());
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t2, 4, t1, 5);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo.toString());
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t2, 4, t1, 6);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo.toString());
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 6, t2, 7);
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.725 beta 1.275 ]]", syncAlgo.toString());
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(t2);
ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(t1);
assertEquals(syncAlgo.getTimestampTransform(t1.getHostId()), tt1);
assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
assertEquals(syncAlgo.getTimestampTransform(t2.getHostId()), tt2);
assertTrue(tt2 instanceof TmfTimestampTransformLinearFast);
/*
* Make the two hulls intersect, and make sure the last good formula is
* kept after failure
*/
addSyncMatch(syncAlgo, t1, 7, t2, 4);
assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.375 beta 1.625 ]]", syncAlgo.toString());
// Last good synchronization
tt2 = syncAlgo.getTimestampTransform(t2);
tt1 = syncAlgo.getTimestampTransform(t1);
assertTrue(tt2 instanceof TmfTimestampTransformLinearFast);
addSyncMatch(syncAlgo, t2, 7, t1, 3);
assertEquals(SyncQuality.FAIL, syncAlgo.getSynchronizationQuality(t1, t2));
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.375 beta 1.625 ]]", syncAlgo.toString());
assertEquals(tt2, syncAlgo.getTimestampTransform(t2.getHostId()));
assertEquals(tt1, syncAlgo.getTimestampTransform(t1.getHostId()));
assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
}
use of org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm in project tracecompass by tracecompass.
the class SynchronizeTracesHandler method execute.
// ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Check if we are closing down
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
// Get the selection
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
// Make sure selection contains only traces
fSelection = null;
final ArrayList<TmfTraceElement> tl = new ArrayList<>();
final ArrayList<TmfExperimentElement> uiexperiment = new ArrayList<>();
if (selection instanceof TreeSelection) {
fSelection = (TreeSelection) selection;
Iterator<Object> iterator = fSelection.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof TmfExperimentElement) {
TmfExperimentElement exp = (TmfExperimentElement) element;
uiexperiment.add(exp);
for (TmfTraceElement trace : exp.getTraces()) {
tl.add(trace);
}
}
}
}
if ((uiexperiment.size() != 1) || (tl.size() < 2)) {
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongTraceNumber);
return null;
}
fExperiment = uiexperiment.get(0);
fRootNode = null;
fRootNodeId = null;
// Fire the Select Root Node Wizard
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = workbenchWindow.getShell();
SelectRootNodeWizard wizard = new SelectRootNodeWizard(fExperiment);
WizardDialog dialog = new WizardDialog(shell, wizard);
int returnValue = dialog.open();
if (returnValue == Window.CANCEL) {
return null;
}
fRootNode = wizard.getRootNode();
Thread thread = new Thread() {
@Override
public void run() {
final ITmfTrace[] traces = new ITmfTrace[tl.size()];
final TmfExperimentElement exp = uiexperiment.get(0);
for (int i = 0; i < tl.size(); i++) {
TmfTraceElement traceElement = tl.get(i).getElementUnderTraceFolder();
ITmfTrace trace = traceElement.instantiateTrace();
ITmfEvent traceEvent = traceElement.instantiateEvent();
if (trace == null) {
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_WrongType + traceElement.getName());
for (int j = 0; j < i; j++) {
traces[j].dispose();
}
return;
}
try {
trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), traceEvent.getClass());
TmfTraceManager.refreshSupplementaryFiles(trace);
} catch (TmfTraceException e) {
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_InitError + CR + CR + e);
trace.dispose();
for (int j = 0; j < i; j++) {
traces[j].dispose();
}
return;
}
if (traceElement.getElementPath().equals(fRootNode.getElementPath())) {
fRootNodeId = trace.getHostId();
}
traces[i] = trace;
}
/*
* FIXME Unlike traces, there is no instanceExperiment, so we
* call this function here alone. Maybe it would be better to do
* this on experiment's element constructor?
*/
exp.refreshSupplementaryFolder();
final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, exp.getName(), traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, exp.getResource());
final SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
syncAlgo.setRootNode(fRootNodeId);
TmfTraceManager.refreshSupplementaryFiles(experiment);
Display.getDefault().asyncExec(() -> {
List<TmfTraceElement> tracesToAdd = new ArrayList<>();
List<TmfTraceElement> tracesToRemove = new ArrayList<>();
/*
* For each trace in the experiment, if there is a
* transform equation, copy the original trace, so that
* a new state system will be generated with sync time.
*/
for (TmfTraceElement traceel : tl) {
/* Find the original trace */
TmfTraceElement origtrace = traceel.getElementUnderTraceFolder();
/*
* Find the trace corresponding to this element in
* the experiment
*/
ITmfTrace expTrace = null;
for (ITmfTrace t : experiment.getTraces()) {
if (t.getResource().equals(origtrace.getResource())) {
expTrace = t;
break;
}
}
if ((expTrace != null) && syncAlgo.isTraceSynced(expTrace.getHostId())) {
/*
* Make sure a trace with the new name does not
* exist
*/
StringBuilder newname = new StringBuilder(traceel.getName());
IContainer parentFolder = origtrace.getResource().getParent();
boolean traceexists;
do {
traceexists = false;
newname.append('_');
if (parentFolder.findMember(newname.toString()) != null) {
traceexists = true;
}
} while (traceexists);
/* Copy the original trace */
TmfTraceElement newtrace = origtrace.copy(newname.toString());
if (newtrace == null) {
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + String.format(Messages.SynchronizeTracesHandler_CopyProblem, origtrace.getName()));
continue;
}
/*
* Instantiate the new trace and set its sync
* formula
*/
ITmfTrace trace1 = newtrace.instantiateTrace();
ITmfEvent traceEvent = newtrace.instantiateEvent();
try {
trace1.initTrace(newtrace.getResource(), newtrace.getResource().getLocation().toOSString(), traceEvent.getClass());
} catch (TmfTraceException e1) {
Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), traceel.getName()), e1);
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e1.getMessage());
}
trace1.setTimestampTransform(syncAlgo.getTimestampTransform(expTrace));
TmfTraceManager.refreshSupplementaryFiles(trace1);
trace1.dispose();
tracesToAdd.add(newtrace);
tracesToRemove.add(traceel);
}
}
experiment.dispose();
// Move synchronization file temporarily so that
// it doesn't get deleted by the experiment change
IFolder tmpFolder = exp.getTraceSupplementaryFolder(exp.getName() + '.' + experiment.getSynchronizationFolder(false));
IResource syncFile = null;
for (IResource resource : exp.getSupplementaryResources()) {
if (resource.getName().equals(experiment.getSynchronizationFolder(false))) {
try {
resource.move(tmpFolder.getFullPath(), false, null);
syncFile = resource;
break;
} catch (CoreException e2) {
Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e2);
}
}
}
for (TmfTraceElement trace2 : tracesToRemove) {
try {
exp.removeTrace(trace2);
} catch (CoreException e3) {
Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingForTrace, exp.getName(), trace2.getName()), e3);
TraceUtils.displayErrorMsg(Messages.SynchronizeTracesHandler_Title, Messages.SynchronizeTracesHandler_Error + CR + CR + e3.getMessage());
}
}
for (TmfTraceElement trace3 : tracesToAdd) {
exp.addTrace(trace3);
}
// Move synchronization file back
if (tmpFolder.exists() && syncFile != null) {
try {
tmpFolder.move(syncFile.getFullPath(), false, null);
} catch (CoreException e4) {
Activator.getDefault().logError(String.format(Messages.SynchronizeTracesHandler_ErrorSynchingExperiment, exp.getName()), e4);
}
}
});
}
};
thread.start();
return null;
}
use of org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm in project tracecompass by tracecompass.
the class TraceSynchronizationBenchmark method runMemoryTest.
/* Benchmark memory used by the algorithm */
private static void runMemoryTest(@NonNull TmfExperiment experiment, String testName, int loop_count) {
Performance perf = Performance.getDefault();
PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + testName + MEMORY);
perf.tagAsSummary(pm, TEST_SUMMARY + ':' + testName + MEMORY, Dimension.USED_JAVA_HEAP);
for (int i = 0; i < loop_count; i++) {
System.gc();
pm.start();
SynchronizationAlgorithm algo = SynchronizationManager.synchronizeTraces(null, Collections.singleton(experiment), true);
assertNotNull(algo);
System.gc();
pm.stop();
}
pm.commit();
}
use of org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm in project tracecompass by tracecompass.
the class SyncTest method testOneHull.
/**
* Testing the fully incremental synchronization algorithm when
* communication goes in only one direction
*/
@Test
public void testOneHull() {
SynchronizationAlgorithm syncAlgo = SynchronizationAlgorithmFactory.getFullyIncrementalAlgorithm();
syncAlgo.init(fTraces);
assertEquals(SyncQuality.ABSENT, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 1, t2, 3);
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 2, t2, 5);
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 3, t2, 5);
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
addSyncMatch(syncAlgo, t1, 4, t2, 7);
assertEquals(SyncQuality.INCOMPLETE, syncAlgo.getSynchronizationQuality(t1, t2));
assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo.toString());
}
Aggregations