Search in sources :

Example 11 with TmfExperiment

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();
    }
}
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 12 with TmfExperiment

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);
}
Also used : TestAnalysis(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis) TestAnalysis2(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis2) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 13 with TmfExperiment

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 14 with TmfExperiment

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;
}
Also used : TraceElementType(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType) Bundle(org.osgi.framework.Bundle) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TmfEventsTable(org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 15 with TmfExperiment

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();
        }
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TmfEventMatching(org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) TmfEventDependency(org.eclipse.tracecompass.tmf.core.event.matching.TmfEventDependency)

Aggregations

TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)55 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)33 Test (org.junit.Test)31 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)11 TmfTraceOpenedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal)9 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)8 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)7 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)7 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)7 Nullable (org.eclipse.jdt.annotation.Nullable)5 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)3 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)3 TmfTraceSelectedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal)3 ITmfTimestampTransform (org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)3 SynchronizationAlgorithm (org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm)3 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)3 CtfTmfEvent (org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent)3 Before (org.junit.Before)3