use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment 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.trace.experiment.TmfExperiment in project tracecompass by tracecompass.
the class TmfExperimentUtilsTest method testGetModuleByClass.
/**
* Test the
* {@link TmfExperimentUtils#getAnalysisModuleOfClassForHost(TmfExperiment, String, Class)}
* method
*/
@Test
public void testGetModuleByClass() {
Class<@NonNull TestAnalysis> commonClass = TestAnalysis.class;
Class<@NonNull TestAnalysis2> notCommonClass = TestAnalysis2.class;
String host1 = TmfTestTrace.A_TEST_10K.getPath();
String host2 = TmfTestTrace.A_TEST_10K2.getPath();
TmfExperiment experiment = fExperiment;
assertNotNull(experiment);
/* Common module for trace 1 */
TestAnalysis module1 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host1, commonClass);
assertNotNull(module1);
/* Make sure this module belongs to the trace */
IAnalysisModule sameModule = null;
for (IAnalysisModule mod : fTraces[0].getAnalysisModules()) {
if (mod == module1) {
sameModule = mod;
}
}
assertNotNull(sameModule);
/* Uncommon module from trace 1 */
TestAnalysis2 module2 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host1, notCommonClass);
assertNull(module2);
/* Common module for trace 1 */
module1 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host2, commonClass);
assertNotNull(module1);
/* Make sure this module belongs to the trace */
sameModule = null;
for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) {
if (mod == module1) {
sameModule = mod;
}
}
assertNotNull(sameModule);
/* Uncommon module from trace 1 */
module2 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host2, notCommonClass);
assertNotNull(module2);
/* Make sure this module belongs to the trace */
sameModule = null;
for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) {
if (mod == module1) {
sameModule = mod;
}
}
assertNotNull(sameModule);
}
use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.
the class TmfExperimentElement method instantiateTrace.
/**
* Instantiate a {@link TmfExperiment} object based on the experiment type
* and the corresponding extension.
*
* @return the {@link TmfExperiment} or <code>null</code> for an error
*/
@Override
public TmfExperiment instantiateTrace() {
try {
// make sure that supplementary folder exists
refreshSupplementaryFolder();
if (getTraceType() != null) {
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
if (ce == null) {
return null;
}
TmfExperiment experiment = (TmfExperiment) ce.createExecutableExtension(TmfTraceType.EXPERIMENT_TYPE_ATTR);
return experiment;
}
} catch (CoreException e) {
Activator.getDefault().logError(NLS.bind(Messages.TmfExperimentElement_ErrorInstantiatingTrace, getName()), e);
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.
the class TmfTraceTypeUIUtils method getEventTable.
/**
* Get the Event Table type specified by the trace type's extension point,
* if there is one.
*
* @param trace
* The trace for which we want the events table.
* @param parent
* The parent composite that the event table will have
* @param cacheSize
* The cache size to use with this event table. Should be defined
* by the trace type.
* @return The corresponding Event Table, or 'null' if this trace type did
* not specify any.
*/
@Nullable
public static TmfEventsTable getEventTable(ITmfTrace trace, Composite parent, int cacheSize) {
final String traceType = getTraceType(trace);
if (traceType == null) {
return null;
}
TraceElementType elType = (trace instanceof TmfExperiment) ? TraceElementType.EXPERIMENT : TraceElementType.TRACE;
for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements(elType)) {
if (ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR).equals(traceType)) {
final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceTypeUIUtils.EVENTS_TABLE_TYPE_ELEM);
if (eventsTableTypeCE.length != 1) {
break;
}
final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.CLASS_ATTR);
final boolean useTraceAspects = Boolean.parseBoolean(eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.USE_TRACE_ASPECTS_ATTR));
if ((eventsTableType == null) || eventsTableType.isEmpty()) {
break;
}
try {
final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
final Class<?> c = bundle.loadClass(eventsTableType);
Class<?>[] constructorArgs = null;
Object[] args = null;
if (useTraceAspects) {
args = new Object[] { parent, cacheSize, trace.getEventAspects() };
constructorArgs = new Class[] { Composite.class, int.class, Iterable.class };
} else {
args = new Object[] { parent, cacheSize };
constructorArgs = new Class[] { Composite.class, int.class };
}
final Constructor<?> constructor = c.getConstructor(constructorArgs);
return (TmfEventsTable) constructor.newInstance(args);
} catch (NoSuchMethodException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
return null;
}
}
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment in project tracecompass by tracecompass.
the class EventMatchingTest method testEventMatching.
private void testEventMatching(String trace1File, String trace2File) throws TmfTraceException {
ITmfTrace trace1 = null;
ITmfTrace trace2 = null;
TmfExperiment experiment = null;
try {
trace1 = getKernelXmlTrace("testfiles/network/" + trace1File);
trace2 = getKernelXmlTrace("testfiles/network/" + trace2File);
ITmfTrace[] traces = { trace1, trace2 };
experiment = new TmfExperiment(ITmfEvent.class, "experiment", traces, 1000, null);
experiment.traceOpened(new TmfTraceOpenedSignal(this, experiment, null));
TestMatchPu testMatchPu = new TestMatchPu();
TmfEventMatching twoTraceMatch = new TmfEventMatching(Collections.singleton(experiment), testMatchPu);
assertTrue(twoTraceMatch.matchEvents());
List<TmfEventDependency> matches = testMatchPu.getMatches();
assertEquals(4, matches.size());
// Test the 3 matches
validateMatch(matches.get(0), trace1File, trace1File, 15, 20);
validateMatch(matches.get(1), trace1File, trace2File, 30, 50);
validateMatch(matches.get(2), trace2File, trace1File, 70, 100);
validateMatch(matches.get(3), trace1File, trace1File, 105, 115);
} finally {
if (experiment != null) {
experiment.dispose();
}
if (trace1 != null) {
trace1.dispose();
}
if (trace2 != null) {
trace2.dispose();
}
}
}
Aggregations