Search in sources :

Example 1 with TmfExperimentStub

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());
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) File(java.io.File) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)

Example 2 with TmfExperimentStub

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();
}
Also used : TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 3 with TmfExperimentStub

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();
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) 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 4 with TmfExperimentStub

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();
    }
}
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 5 with TmfExperimentStub

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();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) TmfTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub) TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) Test(org.junit.Test)

Aggregations

TmfExperimentStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub)14 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)10 Test (org.junit.Test)7 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)3 Before (org.junit.Before)3 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)2 TmfTraceOpenedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal)2 TmfTestTrace (org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace)2 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)2 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)2 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)2 TmfTraceStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub)2 BeforeClass (org.junit.BeforeClass)2 File (java.io.File)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 SyncAlgorithmFullyIncremental (org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental)1 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)1 ITmfTimestampTransform (org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1