Search in sources :

Example 51 with TmfEventRequest

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

the class EventAnnotationProvider method fetchAnnotations.

@Override
public TmfModelResponse<@NonNull AnnotationModel> fetchAnnotations(Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    List<@NonNull Long> entries = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    @Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
    if (timeRequested == null || entries == null) {
        return NO_DATA;
    }
    TmfModelResponse<@NonNull TmfTreeModel<M>> tree = Objects.requireNonNull(fTreeResolver.apply(fetchParameters, monitor));
    TmfTreeModel<M> model = tree.getModel();
    if (model == null) {
        return NO_DATA;
    }
    Function<M, Integer> keyMapper = entry -> (Integer) Iterables.get(entry.getMetadata().get(fMetadataKey), 0);
    Predicate<M> predicate = entry -> {
        Collection<@NonNull Object> collection = entry.getMetadata().get(fMetadataKey);
        return !collection.isEmpty() && !Objects.equals(Iterables.get(collection, 0), -1);
    };
    Map<Integer, TimeGraphEntryModel> rowMap = new LinkedHashMap<>();
    List<@NonNull M> entries2 = model.getEntries();
    entries2.stream().filter(predicate).filter(fAdditionalPredicate).forEach(element -> rowMap.put(keyMapper.apply(element), element));
    Map<String, Collection<Annotation>> markers = new LinkedHashMap<>();
    TmfTimeRange tr = new TmfTimeRange(TmfTimestamp.fromNanos(timeRequested.get(0)), TmfTimestamp.fromNanos(timeRequested.get(timeRequested.size() - 1)));
    EventAnnotationProvider<@NonNull M> lock = this;
    synchronized (lock) {
        for (ITmfTrace source : fMarkerTraces) {
            TmfEventRequest old = fRunningRequests.remove(source);
            if (old != null && old.isRunning()) {
                old.cancel();
            }
        }
        for (ITmfTrace source : fMarkerTraces) {
            if (categories != null && !categories.contains(source.getName())) {
                // marker category is filtered out
                continue;
            }
            TmfEventRequest req = new TmfEventRequest(ITmfEvent.class, tr, 0, Integer.MAX_VALUE, ExecutionType.FOREGROUND) {

                private int timesliceIndex = 0;

                private Set<Object> values = new HashSet<>();

                private long next() {
                    if (timeRequested.size() > timesliceIndex + 1) {
                        return timeRequested.get(timesliceIndex + 1);
                    }
                    return Long.MAX_VALUE;
                }

                @Override
                public void handleData(ITmfEvent event) {
                    super.handleData(event);
                    while (event.getTimestamp().toNanos() > next()) {
                        timesliceIndex++;
                        values.clear();
                        if (timesliceIndex >= timeRequested.size() - 1) {
                            done();
                            return;
                        }
                    }
                    Object value = TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), fAspect, event);
                    if (value != null && !values.contains(value)) {
                        values.add(value);
                        synchronized (markers) {
                            Collection<Annotation> markerList = markers.computeIfAbsent(String.valueOf(event.getTrace().getName()), string -> new ArrayList<>());
                            TimeGraphEntryModel entryModel = rowMap.get(value);
                            if (entryModel != null) {
                                String name = event.getName();
                                Map<String, Object> style = new HashMap<>();
                                style.put(StyleProperties.SYMBOL_TYPE, SymbolType.INVERTED_TRIANGLE);
                                style.put(StyleProperties.COLOR, getMarkerColor(name));
                                style.put(StyleProperties.HEIGHT, 0.3);
                                style.put(StyleProperties.VERTICAL_ALIGN, StyleProperties.VerticalAlign.TOP);
                                markerList.add(new Annotation(event.getTimestamp().toNanos(), 0L, entryModel.getId(), AnnotationType.CHART, name, new OutputElementStyle(name, style)));
                            }
                        }
                    }
                }

                private String getMarkerColor(String name) {
                    // $NON-NLS-1$
                    return Objects.requireNonNull(fMarkerColorCache.computeIfAbsent(name, label -> Objects.requireNonNull(String.format("#%6x", label.hashCode() & 0xffffff))));
                }
            };
            fRunningRequests.put(source, req);
            source.sendRequest(req);
        }
        try {
            for (ITmfTrace source : fMarkerTraces) {
                TmfEventRequest req = null;
                synchronized (lock) {
                    req = fRunningRequests.get(source);
                }
                if (req != null) {
                    req.waitForCompletion();
                    fRunningRequests.remove(source);
                }
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    // $NON-NLS-1$
    return new TmfModelResponse<>(new AnnotationModel(markers), Status.COMPLETED, "");
}
Also used : Iterables(com.google.common.collect.Iterables) AnnotationType(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation.AnnotationType) TmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp) BiFunction(java.util.function.BiFunction) ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) HashMap(java.util.HashMap) Function(java.util.function.Function) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) StyleProperties(org.eclipse.tracecompass.tmf.core.model.StyleProperties) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) TmfTraceUtils(org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ExecutionType(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) Status(org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) SymbolType(org.eclipse.tracecompass.tmf.core.model.StyleProperties.SymbolType) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) LinkedHashMap(java.util.LinkedHashMap) NonNull(org.eclipse.jdt.annotation.NonNull) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) Collection(java.util.Collection) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable)

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