Search in sources :

Example 21 with TmfEventRequest

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

the class TextTraceTest method setUp.

// ------------------------------------------------------------------------
// Housekeeping
// ------------------------------------------------------------------------
@BeforeClass
public static void setUp() throws Exception {
    IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss");
    defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT);
    defaultPreferences.put(ITmfTimePreferencesConstants.LOCALE, Locale.US.toLanguageTag());
    TmfTimestampFormat.updateDefaultFormats();
    if (fTrace == null) {
        try {
            URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(PATH), null);
            URI uri = FileLocator.toFileURL(location).toURI();
            fTestFile = new File(uri);
            fTrace = new SyslogTrace();
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(PATH));
            fTrace.initTrace(resource, uri.getPath(), SyslogEvent.class);
            // Dummy request to force the trace indexing
            TmfEventRequest request = new TmfEventRequest(SyslogEvent.class, TmfTimeRange.ETERNITY, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {
            };
            fTrace.sendRequest(request);
            request.waitForCompletion();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) SyslogTrace(org.eclipse.tracecompass.tmf.tests.stubs.trace.text.SyslogTrace) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) BeforeClass(org.junit.BeforeClass)

Example 22 with TmfEventRequest

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

the class TmfEventTableDataProvider method fetchIndex.

/**
 * Find the index in the table of an event using the rank in the trace or
 * the timestamp value. It will take any filter into consideration.
 *
 * @param fetchParameters
 *            Map of parameters that contain the filter applied to the
 *            table, if any. Everything else is ignored.
 * @param traceRank
 *            Rank of the event in the trace
 * @param timeBegin
 *            Timestamp of the event
 * @param monitor
 *            Progress monitor
 * @return Index in the table
 */
public TmfModelResponse<List<Long>> fetchIndex(Map<String, Object> fetchParameters, long traceRank, long timeBegin, @Nullable IProgressMonitor monitor) {
    @Nullable ITmfFilter filter = extractFilter(fetchParameters);
    long rank;
    if (traceRank == -1) {
        ITmfContext context = getTrace().seekEvent(TmfTimestamp.fromNanos(timeBegin));
        rank = context.getRank();
    } else {
        rank = traceRank;
    }
    if (filter == null) {
        return new TmfModelResponse<>(Collections.singletonList(rank), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    applyFilter(filter);
    Entry<Long, Long> nearestEntry = fRankToIndexMap.floorEntry(rank);
    long startingIndex = nearestEntry != null ? nearestEntry.getValue() : 0L;
    long startingRank = nearestEntry != null ? nearestEntry.getKey() : 0L;
    List<Long> foundIndex = new ArrayList<>();
    TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startingRank, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {

        private long currentIndex = startingIndex;

        private long fRank = startingRank;

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (monitor != null && monitor.isCanceled()) {
                cancel();
                return;
            }
            if (fRank >= rank) {
                foundIndex.add(currentIndex);
                done();
                return;
            }
            if (filter.matches(event)) {
                currentIndex++;
            }
            fRank++;
        }
    };
    getTrace().sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
    }
    return new TmfModelResponse<>(foundIndex, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 23 with TmfEventRequest

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

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

the class TmfUml2SDSyncLoader method moveToPage.

/**
 * Moves to a certain page.
 *
 * @param notifyAll
 *            true to broadcast time range signal to other signal handlers
 *            else false
 */
protected void moveToPage(boolean notifyAll) {
    TmfTimeRange window = null;
    fLock.lock();
    try {
        // Safety check
        if (fCurrentPage > fCheckPoints.size()) {
            return;
        }
        window = fCheckPoints.get(fCurrentPage);
    } finally {
        fLock.unlock();
    }
    if (window == null) {
        window = TmfTimeRange.ETERNITY;
    }
    fPageRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.FOREGROUND) {

        private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<>();

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
            if (sdEvent != null) {
                fSdEvent.add(sdEvent);
            }
        }

        @Override
        public void handleSuccess() {
            fillCurrentPage(fSdEvent);
            super.handleSuccess();
        }
    };
    fTrace.sendRequest(fPageRequest);
    if (notifyAll) {
        TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime());
        broadcast(new TmfWindowRangeUpdatedSignal(this, timeRange, fTrace));
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 25 with TmfEventRequest

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

the class TmfUml2SDSyncLoader method loadTrace.

/**
 * Method for loading the current selected trace into the view. Sub-class
 * need to override this method to add the view specific implementation.
 */
protected void loadTrace() {
    ITmfEventRequest indexRequest = null;
    fLock.lock();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        final Job job = new IndexingJob("Indexing " + getName() + "...");
        job.setUser(false);
        job.schedule();
        indexRequest = fIndexRequest;
        cancelOngoingRequests();
        TmfTimeRange window = TmfTimeRange.ETERNITY;
        fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {

            private ITmfTimestamp fFirstTime = null;

            private ITmfTimestamp fLastTime = null;

            private int fNbSeqEvents = 0;

            private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<>(MAX_NUM_OF_MSG);

            @Override
            public void handleData(ITmfEvent event) {
                super.handleData(event);
                ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
                ITmfTimestamp firstTime = fFirstTime;
                ITmfTimestamp lastTime = fLastTime;
                if (sdEvent != null) {
                    ++fNbSeqEvents;
                    if (firstTime == null) {
                        firstTime = event.getTimestamp();
                        fFirstTime = firstTime;
                    }
                    lastTime = event.getTimestamp();
                    fLastTime = lastTime;
                    if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
                        fLock.lock();
                        try {
                            fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                            if (fView != null) {
                                fView.updateCoolBar();
                            }
                        } finally {
                            fLock.unlock();
                        }
                        fFirstTime = null;
                    }
                    if (fNbSeqEvents > MAX_NUM_OF_MSG) {
                        // page is full
                        return;
                    }
                    fSdEvents.add(sdEvent);
                    if (fNbSeqEvents == MAX_NUM_OF_MSG) {
                        fillCurrentPage(fSdEvents);
                    }
                }
            }

            @Override
            public void handleSuccess() {
                final ITmfTimestamp firstTime = fFirstTime;
                final ITmfTimestamp lastTime = fLastTime;
                if ((firstTime != null) && (lastTime != null)) {
                    fLock.lock();
                    try {
                        fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                        if (fView != null) {
                            fView.updateCoolBar();
                        }
                    } finally {
                        fLock.unlock();
                    }
                }
                if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
                    fillCurrentPage(fSdEvents);
                }
                super.handleSuccess();
            }

            @Override
            public void handleCompleted() {
                if (fEvents.isEmpty()) {
                    fFrame = new Frame();
                    // make sure that view is not null when setting frame
                    SDView sdView;
                    fLock.lock();
                    try {
                        sdView = fView;
                    } finally {
                        fLock.unlock();
                    }
                    if (sdView != null) {
                        sdView.setFrameSync(fFrame);
                    }
                }
                super.handleCompleted();
                job.cancel();
            }
        };
    } finally {
        fLock.unlock();
    }
    if (indexRequest != null && !indexRequest.isCompleted()) {
        indexRequest.cancel();
    }
    resetLoader();
    fTrace.sendRequest(fIndexRequest);
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Job(org.eclipse.core.runtime.jobs.Job) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

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