use of org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub in project tracecompass by tracecompass.
the class ExperimentBenchmark method init.
/**
* Initialization
*
* @param maxTraces
* maximum number of traces to open
*/
private void init(int maxTraces) {
try {
File parentDir = new File(TRACES_ROOT_PATH);
File[] traceFiles = parentDir.listFiles();
ITmfTrace[] traces = new CtfTmfTrace[Math.min(maxTraces, traceFiles.length)];
for (int i = 0; i < traces.length; i++) {
traces[i] = new CtfTmfTrace();
}
int j = 0;
for (int i = 0; i < (traces.length) && (j < traces.length); i++) {
String absolutePath = traceFiles[j].getAbsolutePath();
if (traces[i].validate(null, absolutePath).isOK()) {
traces[i].initTrace(null, absolutePath, ITmfEvent.class);
} else {
i--;
}
j++;
}
fExperiment = new TmfExperimentStub("MegaExperiment", traces, BLOCK_SIZE);
if (traces[traces.length - 1].getPath() == null) {
throw new TmfTraceException("Insufficient valid traces in directory");
}
} catch (TmfTraceException e) {
System.out.println(e.getMessage());
}
}
use of org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub in project tracecompass by tracecompass.
the class TmfExperimentTest method testExperimentInitialization.
// ------------------------------------------------------------------------
// Experiment setup
// ------------------------------------------------------------------------
@Test
public void testExperimentInitialization() {
/*
* Calling default constructor, then init should be equivalent to
* calling the full constructor
*/
TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, 5000);
experiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
assertEquals("GetId", EXPERIMENT, fExperiment.getName());
assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
final long nbExperimentEvents = fExperiment.getNbEvents();
assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents);
final long nbTraceEvents = fExperiment.getTraces().get(0).getNbEvents();
assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
final TmfTimeRange timeRange = fExperiment.getTimeRange();
assertEquals("getStartTime", 1, timeRange.getStartTime().getValue());
assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue());
experiment.dispose();
}
use of org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub in project tracecompass by tracecompass.
the class TmfExperimentTest method testWithSingleHostClockOffset.
/**
* Tests that experiment with traces from the same host and a clock offset
* are well synchronized
*/
@Test
public void testWithSingleHostClockOffset() {
// Data for this specific test
String hostId = "Test Host 1";
long minOffset = 2000;
long offset = 1000;
String clockOffset = "clock_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));
}
};
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));
}
};
TmfExperiment exp = new TmfExperimentStub(EXPERIMENT, new ITmfTrace[] { t1, t2 }, BLOCK_SIZE);
try {
assertEquals(TimestampTransformFactory.createWithOffset(offset / 2), t1.getTimestampTransform());
assertEquals(TimestampTransformFactory.createWithOffset(-offset / 2), t2.getTimestampTransform());
} finally {
exp.dispose();
}
}
use of org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub 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.tests.stubs.trace.TmfExperimentStub in project tracecompass by tracecompass.
the class TmfMultiTraceExperimentTest method testInitialRangeOffset.
@Test
public void testInitialRangeOffset() {
ITmfTrace[] traces = setupTraces();
((TmfTraceStub) traces[0]).setInitialRangeOffset(TmfTimestamp.fromMillis(5));
((TmfTraceStub) traces[1]).setInitialRangeOffset(TmfTimestamp.fromMillis(2));
TmfExperimentStub exp = new TmfExperimentStub(EXPERIMENT, traces, BLOCK_SIZE);
ITmfTimestamp initRange = TmfTimestamp.fromMillis(2);
assertEquals("getInitialRangeOffset", initRange, exp.getInitialRangeOffset());
exp.dispose();
}
Aggregations