Search in sources :

Example 26 with TmfEventRequest

use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.

the class CopyToClipboardOperation method copy.

private IStatus copy(final StringBuilder sb, final IProgressMonitor monitor) {
    ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, fStartRank, (int) (fEndRank - fStartRank + 1), ExecutionType.FOREGROUND) {

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (monitor.isCanceled()) {
                cancel();
                return;
            }
            monitor.worked(1);
            if (fFilter == null || fFilter.matches(event)) {
                try {
                    boolean needTab = false;
                    for (TmfEventTableColumn column : fColumns) {
                        if (needTab) {
                            sb.append('\t');
                        }
                        sb.append(column.getItemString(event));
                        needTab = true;
                    }
                    sb.append(LINE_SEPARATOR);
                } catch (OutOfMemoryError e) {
                    sb.setLength(0);
                    sb.trimToSize();
                    showErrorDialog();
                    cancel();
                }
            }
        }
    };
    fTrace.sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Wait for completion interrupted for copy to clipboard ", e);
        Thread.currentThread().interrupt();
    }
    return Status.OK_STATUS;
}
Also used : ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 27 with TmfEventRequest

use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.

the class StreamListAnalysis method executeAnalysis.

@Override
protected boolean executeAnalysis(@Nullable IProgressMonitor monitor) throws TmfAnalysisException {
    IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
    ITmfTrace trace = getTrace();
    if (trace == null) {
        /* This analysis was cancelled in the meantime */
        return false;
    }
    ITmfEventRequest request = fRequest;
    if ((request != null) && (!request.isCompleted())) {
        request.cancel();
    }
    request = new TmfEventRequest(PcapEvent.class, TmfTimeRange.ETERNITY, 0L, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {

        @Override
        public void handleData(ITmfEvent data) {
            // Called for each event
            super.handleData(data);
            if (!(data instanceof PcapEvent)) {
                return;
            }
            PcapEvent event = (PcapEvent) data;
            for (Map.Entry<TmfPcapProtocol, TmfPacketStreamBuilder> entry : fBuilders.entrySet()) {
                entry.getValue().addEventToStream(event);
            }
        }
    };
    trace.sendRequest(request);
    fRequest = request;
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        // Request was canceled.
        return false;
    }
    return !mon.isCanceled() && !request.isCancelled() && !request.isFailed();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) PcapEvent(org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 28 with TmfEventRequest

use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest 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)

Example 29 with TmfEventRequest

use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest 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 30 with TmfEventRequest

use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest 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)

Aggregations

TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)51 Test (org.junit.Test)36 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)31 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)29 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)24 Vector (java.util.Vector)15 TmfEventRequestStub (org.eclipse.tracecompass.tmf.tests.stubs.request.TmfEventRequestStub)15 ITmfEventProvider (org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider)11 TmfCoalescedEventRequest (org.eclipse.tracecompass.internal.tmf.core.request.TmfCoalescedEventRequest)8 ArrayList (java.util.ArrayList)5 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NonNull (org.eclipse.jdt.annotation.NonNull)3 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 TmfCollapseFilter (org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)2 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)2 TmfSignalHandler (org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)2 ITmfSyncSequenceDiagramEvent (org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent)2