Search in sources :

Example 1 with ITmfEventProvider

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

the class TmfTraceTest method testProcessEventRequestForOtherEvents.

@Test
public void testProcessEventRequestForOtherEvents() throws InterruptedException {
    final int startIndex = 99;
    final long startTime = 100;
    final int nbEvents = 1000;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.create(startTime, SCALE), TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, nbEvents, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
    providers[0].sendRequest(request);
    request.waitForCompletion();
    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; i++) {
        assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue());
    }
}
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 2 with ITmfEventProvider

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

the class TmfTraceTest method testCancel.

// ------------------------------------------------------------------------
// cancel
// ------------------------------------------------------------------------
@Test
public void testCancel() throws InterruptedException {
    final int limit = 500;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        int nbRead = 0;

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
            if (++nbRead == limit) {
                cancel();
            }
        }
    };
    final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
    providers[0].sendRequest(request);
    request.waitForCompletion();
    assertEquals("nbEvents", limit, requestedEvents.size());
    assertTrue("isCompleted", request.isCompleted());
    assertTrue("isCancelled", request.isCancelled());
}
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 3 with ITmfEventProvider

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

the class TmfTraceTest method testProcessEventRequestForNbEvents.

@Test
public void testProcessEventRequestForNbEvents() throws InterruptedException {
    final int nbEvents = 1000;
    final Vector<ITmfEvent> requestedEvents = new Vector<>();
    final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
    final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, 0, nbEvents, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(final ITmfEvent event) {
            super.handleData(event);
            requestedEvents.add(event);
        }
    };
    final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class);
    providers[0].sendRequest(request);
    request.waitForCompletion();
    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; i++) {
        assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue());
    }
}
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 4 with ITmfEventProvider

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

the class TmfEventsCache method getFilteredEventIndex.

/**
 * Get the cache index of an event from his rank in the trace. This will
 * take in consideration any filter that might be applied.
 *
 * @param rank
 *            The rank of the event in the trace
 * @return The position (index) this event should use once cached
 */
public int getFilteredEventIndex(final long rank) {
    int current;
    int startRank;
    TmfEventRequest request;
    final ITmfFilter filter = fFilter;
    synchronized (this) {
        int start = 0;
        int end = fFilterIndex.size();
        if ((fCacheEndIndex - fCacheStartIndex) > 1) {
            if (rank < fCache[0].rank) {
                end = (fCacheStartIndex / fCacheSize) + 1;
            } else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) {
                start = fCacheEndIndex / fCacheSize;
            } else {
                for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) {
                    if (fCache[i].rank >= rank) {
                        return fCacheStartIndex + i;
                    }
                }
                return fCacheEndIndex;
            }
        }
        current = (start + end) / 2;
        while (current != start) {
            if (rank < fFilterIndex.get(current)) {
                end = current;
                current = (start + end) / 2;
            } else {
                start = current;
                current = (start + end) / 2;
            }
        }
        startRank = fFilterIndex.isEmpty() ? 0 : fFilterIndex.get(current);
    }
    final int index = current * fCacheSize;
    class DataRequest extends TmfEventRequest {

        ITmfFilter requestFilter;

        TmfCollapseFilter requestCollapsedFilter;

        int requestRank;

        int requestIndex;

        DataRequest(Class<? extends ITmfEvent> dataType, ITmfFilter reqFilter, int start, int nbRequested) {
            super(dataType, TmfTimeRange.ETERNITY, start, nbRequested, TmfEventRequest.ExecutionType.FOREGROUND);
            requestFilter = reqFilter;
            requestRank = start;
            requestIndex = index;
            requestCollapsedFilter = fCollapseFilterEnabled ? new TmfCollapseFilter() : null;
        }

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (isCancelled()) {
                return;
            }
            if (requestRank >= rank) {
                cancel();
                return;
            }
            requestRank++;
            if (requestFilter.matches(event)) {
                if (requestCollapsedFilter == null || requestCollapsedFilter.matches(event)) {
                    requestIndex++;
                }
            }
        }

        public int getFilteredIndex() {
            return requestIndex;
        }
    }
    request = new DataRequest(ITmfEvent.class, filter, startRank, ITmfEventRequest.ALL_DATA);
    ((ITmfEventProvider) fTrace).sendRequest(request);
    try {
        request.waitForCompletion();
        return ((DataRequest) request).getFilteredIndex();
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Filter request interrupted!", e);
        Thread.currentThread().interrupt();
    }
    return 0;
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) TmfCollapseFilter(org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)

Example 5 with ITmfEventProvider

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

the class TmfEventProviderTest method testCancelRequests.

/**
 * Test canceling requests.
 */
@Test
public void testCancelRequests() {
    final int NB_EVENTS = 1000;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ1 = 10;
    final int NUMBER_EVENTS_BEFORE_CANCEL_REQ2 = 800;
    final Vector<ITmfEvent> requestedEventsReq1 = new Vector<>();
    final Vector<ITmfEvent> requestedEventsReq2 = 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);
    // Create first request
    final TmfEventRequest request1 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq1.add(event);
            // cancel sub request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ1) {
                cancel();
            }
        }
    };
    // Synchronize requests
    ((TmfEventProviderStub) provider).startSynch(new TmfStartSynchSignal(0));
    // Additionally, notify provider for up-coming requests
    provider.notifyPendingRequest(true);
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request1 yet
    provider.sendRequest(request1);
    // Check if request1 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    // Create second request
    final TmfEventRequest request2 = new TmfEventRequest(ITmfEvent.class, range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            requestedEventsReq2.add(event);
            // cancel sub request which will cancel also main request
            if (getNbRead() == NUMBER_EVENTS_BEFORE_CANCEL_REQ2) {
                cancel();
            }
        }
    };
    // Call sendRequest, which will create a coalescing request, but it
    // doesn't send request2 yet
    provider.sendRequest(request2);
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Send end synch signal, however requests won't be sent
    ((TmfEventProviderStub) provider).endSynch(new TmfEndSynchSignal(0));
    // Check if request1/2 is not running yet.
    assertFalse("isRunning", request1.isRunning());
    assertFalse("isRunning", request2.isRunning());
    // Finally, trigger sending of requests
    provider.notifyPendingRequest(false);
    try {
        // Wait until requests start
        request1.waitForStart();
        request2.waitForStart();
        // // Verify that the requests are running
        // assertTrue("isRunning", request1.isRunning());
        // assertTrue("isRunning", request2.isRunning());
        request1.waitForCompletion();
        // // Check if request2 is still running
        // assertTrue("isRunning",  request2.isRunning());
        // Verify result (request1)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ1, requestedEventsReq1.size());
        assertTrue("isCompleted", request1.isCompleted());
        assertTrue("isCancelled", request1.isCancelled());
        request2.waitForCompletion();
        // Verify result (request2)
        assertEquals("nbEvents", NUMBER_EVENTS_BEFORE_CANCEL_REQ2, requestedEventsReq2.size());
        assertTrue("isCompleted", request2.isCompleted());
        assertTrue("isCancelled", request2.isCancelled());
    } catch (InterruptedException e) {
        fail();
    }
}
Also used : ITmfEventProvider(org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider) TmfEventProviderStub(org.eclipse.tracecompass.tmf.tests.stubs.component.TmfEventProviderStub) TmfStartSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfStartSynchSignal) 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) TmfEndSynchSignal(org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal) Test(org.junit.Test)

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