Search in sources :

Example 31 with TmfEventRequest

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

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

the class TmfEventsCache method populateCache.

private synchronized void populateCache(final int index) {
    /* Check if the current job will fetch the requested event:
         * 1. The job must exist
         * 2. It must be running (i.e. not completed)
         * 3. The requested index must be within the cache range
         *
         * If the job meets these conditions, we simply exit.
         * Otherwise, we create a new job but we might have to cancel
         * an existing job for an obsolete range.
         */
    if (job != null) {
        if (job.getState() != Job.NONE) {
            if ((index >= fCacheStartIndex) && (index < (fCacheStartIndex + fCache.length))) {
                return;
            }
            // The new index is out of the requested range
            // Kill the job and start a new one
            job.cancel();
        }
    }
    // Populate the cache starting at the index that is one block less
    // of cache size than the requested index. The cache will hold two
    // consecutive blocks of cache size, centered on the requested index.
    fCacheStartIndex = Math.max(0, index - fCacheSize);
    fCacheEndIndex = fCacheStartIndex;
    job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Fetching Events") {

        private int startIndex = fCacheStartIndex;

        private int skipCount = 0;

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            int nbRequested;
            if (fFilter == null) {
                nbRequested = fCache.length;
            } else {
                nbRequested = ITmfEventRequest.ALL_DATA;
                int i = startIndex / fCacheSize;
                if (i < fFilterIndex.size()) {
                    skipCount = startIndex - (i * fCacheSize);
                    startIndex = fFilterIndex.get(i);
                }
            }
            TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startIndex, nbRequested, TmfEventRequest.ExecutionType.FOREGROUND) {

                private int count = 0;

                private long rank = startIndex;

                private TmfCollapseFilter collapseFilter = fCollapseFilterEnabled ? new TmfCollapseFilter() : null;

                @Override
                public void handleData(ITmfEvent event) {
                    // If the job is canceled, cancel the request so waitForCompletion() will unlock
                    if (monitor.isCanceled()) {
                        cancel();
                        return;
                    }
                    super.handleData(event);
                    if ((fFilter == null) || fFilter.matches(event)) {
                        if (collapseFilter == null || collapseFilter.matches(event)) {
                            if (skipCount-- <= 0) {
                                synchronized (TmfEventsCache.this) {
                                    if (monitor.isCanceled()) {
                                        return;
                                    }
                                    fCache[count] = new CachedEvent(event, rank);
                                    count++;
                                    fCacheEndIndex++;
                                }
                                if (fFilter != null) {
                                    fTable.cacheUpdated(false);
                                }
                            }
                        } else if ((count > 0) && (skipCount <= 0)) {
                            fCache[count - 1].repeatCount++;
                        }
                    }
                    if (count >= fCache.length) {
                        cancel();
                    } else if ((fFilter != null) && (count >= (fTable.getTable().getItemCount() - 3))) {
                        // -1 for header row, -2 for top and bottom filter status rows
                        cancel();
                    }
                    rank++;
                }
            };
            ((ITmfEventProvider) fTrace).sendRequest(request);
            try {
                request.waitForCompletion();
            } catch (InterruptedException e) {
                // $NON-NLS-1$
                Activator.getDefault().logError("Wait for completion interrupted for populateCache ", e);
                Thread.currentThread().interrupt();
            }
            fTable.cacheUpdated(true);
            // Flag the UI thread that the cache is ready
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    // job.setSystem(true);
    job.setPriority(Job.SHORT);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) 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 33 with TmfEventRequest

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

the class TmfEventRequestTest method testWaitForStartAfterCancel.

/**
 * Test calling waitForStart() after the request has beend cancelled. It
 * should not block.
 */
@Test
public void testWaitForStartAfterCancel() throws InterruptedException {
    final boolean[] flags = new boolean[4];
    TmfEventRequest request = setupTestRequest(flags);
    request.start();
    request.cancel();
    request.waitForStart();
    assertTrue("isCompleted", request.isCompleted());
    assertFalse("isFailed", request.isFailed());
    assertTrue("isCancelled", request.isCancelled());
    assertTrue("handleCompleted", flags[0]);
    assertFalse("handleSuccess", flags[1]);
    assertFalse("handleFailure", flags[2]);
    assertTrue("handleCancel", flags[3]);
}
Also used : ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

Example 34 with TmfEventRequest

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

the class TmfEventRequestTest method testTmfEventRequestTimeRangeNbRequested.

@Test
public void testTmfEventRequestTimeRangeNbRequested() {
    TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromSeconds(0), TmfTimestamp.BIG_CRUNCH);
    TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range, 100);
    assertEquals("getDataType", ITmfEvent.class, request.getDataType());
    assertEquals("StartTime", TmfTimestamp.fromSeconds(0), request.getRange().getStartTime());
    assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime());
    assertEquals("getIndex", 0, request.getIndex());
    assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
    assertFalse("isCompleted", request.isCompleted());
    assertFalse("isFailed", request.isFailed());
    assertFalse("isCancelled", request.isCancelled());
    assertEquals("getNbRead", 0, request.getNbRead());
    assertEquals("getDependencyLevel", 0, request.getDependencyLevel());
}
Also used : TmfEventRequestStub(org.eclipse.tracecompass.tmf.tests.stubs.request.TmfEventRequestStub) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

Example 35 with TmfEventRequest

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

the class TmfEventRequestTest method testCancel.

// ------------------------------------------------------------------------
// cancel
// ------------------------------------------------------------------------
@Test
public void testCancel() {
    final boolean[] flags = new boolean[4];
    TmfEventRequest request = setupTestRequest(flags);
    request.cancel();
    assertTrue("isCompleted", request.isCompleted());
    assertFalse("isFailed", request.isFailed());
    assertTrue("isCancelled", request.isCancelled());
    assertTrue("handleCompleted", flags[0]);
    assertFalse("handleSuccess", flags[1]);
    assertFalse("handleFailure", flags[2]);
    assertTrue("handleCancel", flags[3]);
}
Also used : ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Test(org.junit.Test)

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