Search in sources :

Example 6 with ITmfEventProvider

use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.

the class TmfEventProviderTest method testGetPlainEvents.

// ------------------------------------------------------------------------
// getSyntheticEvent
// ------------------------------------------------------------------------
/**
 * Test getPlainEvents
 */
@Test
public void testGetPlainEvents() {
    final int NB_EVENTS = 1000;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    // Get the TmfSyntheticEventStub provider
    ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
    ITmfEventProvider provider = eventProviders[0];
    TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    provider.sendRequest(request);
    try {
        request.waitForCompletion();
        assertEquals("nbEvents", NB_EVENTS, requestedEvents.size());
        assertTrue("isCompleted", request.isCompleted());
        assertFalse("isCancelled", request.isCancelled());
        // Don't go overboard: we are not validating the stub!
        for (int i = 0; i < NB_EVENTS; i++) {
            assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue());
        }
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

Example 7 with ITmfEventProvider

use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.

the class TmfEventProviderTest method getSyntheticData.

private static void getSyntheticData(final TmfTimeRange range, final int nbEvents) throws InterruptedException {
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    // Get the event provider
    ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(TmfSyntheticEventStub.class);
    ITmfEventProvider provider = eventProviders[0];
    final TmfEventRequest request = new TmfEventRequest(TmfSyntheticEventStub.class, range, 0, nbEvents, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    provider.sendRequest(request);
    request.waitForCompletion();
    if (nbEvents != -1) {
        assertEquals("nbEvents", nbEvents, requestedEvents.size());
    }
    assertTrue("isCompleted", request.isCompleted());
    assertFalse("isCancelled", request.isCancelled());
    // Don't go overboard: we are not validating the stub!
    for (int i = 0; i < (nbEvents / 2); i++) {
        assertEquals("Distinct events", i + 1, requestedEvents.get(2 * i + 0).getTimestamp().getValue());
        assertEquals("Distinct events", i + 1, requestedEvents.get(2 * i + 1).getTimestamp().getValue());
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Vector(java.util.Vector) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)

Example 8 with ITmfEventProvider

use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.

the class TmfSyntheticEventProviderStub method armRequest.

@Override
public ITmfContext armRequest(final ITmfEventRequest request) {
    // Get the TmfSyntheticEventStub provider
    final ITmfEventProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class, TmfEventProviderStub.class);
    final ITmfEventProvider provider = eventProviders[0];
    final TmfTimeRange range = request.getRange();
    final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            handleIncomingData(event);
        }
    };
    provider.sendRequest(subRequest);
    // Return a dummy context
    return new TmfContext();
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)

Example 9 with ITmfEventProvider

use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.

the class ITmfTrace method getUUID.

/**
 * Get the trace {@link UUID}, a unique identifier that should always be the
 * same if the trace and the children do not change.
 *
 * The default implementation relies on the trace name, the length of the file
 * and the last modified date.
 *
 * @return A {@link UUID} that when it changes is a good indication that the
 *         trace files have changed. An unchanged {@link UUID} may or may not
 *         indicate that the trace has changed.
 * @since 3.1
 */
@Nullable
default UUID getUUID() {
    /*
         * Best effort get UUID, if an implementation has more info, it should override
         * this.
         */
    StringBuilder sb = new StringBuilder();
    File file = new File(getPath());
    if (file.isDirectory()) {
        for (File childFile : file.listFiles()) {
            sb.append(childFile.getName());
            sb.append(childFile.length());
            sb.append(childFile.lastModified());
        }
    } else if (file.exists()) {
        sb.append(file.getName());
        sb.append(file.length());
        sb.append(file.lastModified());
    }
    for (ITmfEventProvider child : getChildren()) {
        if (child instanceof ITmfTrace) {
            sb.append(String.valueOf(((ITmfTrace) child).getUUID()));
        }
    }
    return UUID.nameUUIDFromBytes(Objects.requireNonNull(sb.toString().getBytes(Charset.defaultCharset())));
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 10 with ITmfEventProvider

use of org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider in project tracecompass by tracecompass.

the class TmfTraceUtils method getAnalysisModulesOfClass.

/**
 * Return the analysis modules that are of a given class. The modules will be
 * cast to the requested class. If the trace has children, the childrens modules
 * are also returned.
 *
 * @param trace
 *            The trace for which you want the modules, the children trace
 *            modules are added as well.
 * @param moduleClass
 *            Returned modules must extend this class
 * @return List of modules of class moduleClass
 */
public static <T> Iterable<@NonNull T> getAnalysisModulesOfClass(ITmfTrace trace, Class<T> moduleClass) {
    Iterable<IAnalysisModule> analysisModules = trace.getAnalysisModules();
    List<@NonNull T> modules = new ArrayList<>();
    for (IAnalysisModule module : analysisModules) {
        if (moduleClass.isAssignableFrom(module.getClass())) {
            modules.add(checkNotNull(moduleClass.cast(module)));
        }
    }
    for (ITmfEventProvider child : trace.getChildren()) {
        if (child instanceof ITmfTrace) {
            ITmfTrace childTrace = (ITmfTrace) child;
            Iterables.addAll(modules, getAnalysisModulesOfClass(childTrace, moduleClass));
        }
    }
    return modules;
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) ArrayList(java.util.ArrayList)

Aggregations

ITmfEventProvider (org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider)14 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)11 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)11 Vector (java.util.Vector)9 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)9 Test (org.junit.Test)8 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IStatus (org.eclipse.core.runtime.IStatus)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 TmfCollapseFilter (org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)1 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)1 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)1 TmfEndSynchSignal (org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal)1 TmfSignalHandler (org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)1 TmfStartSynchSignal (org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal)1 TmfTraceRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal)1 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)1