Search in sources :

Example 26 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphView method zoomEntries.

@Override
protected void zoomEntries(@NonNull Iterable<@NonNull TimeGraphEntry> entries, long zoomStartTime, long zoomEndTime, long resolution, boolean fullSearch, @NonNull IProgressMonitor monitor) {
    if (resolution < 0) {
        // StateSystemUtils.getTimes would throw an illegal argument exception.
        return;
    }
    long start = Long.min(zoomStartTime, zoomEndTime);
    long end = Long.max(zoomStartTime, zoomEndTime);
    Sampling sampling = new Sampling(start, end, resolution);
    Multimap<ITimeGraphDataProvider<? extends TimeGraphEntryModel>, Long> providersToModelIds = filterGroupEntries(entries, zoomStartTime, zoomEndTime);
    // $NON-NLS-1$
    SubMonitor subMonitor = SubMonitor.convert(monitor, getClass().getSimpleName() + "#zoomEntries", providersToModelIds.size());
    for (Entry<ITimeGraphDataProvider<? extends TimeGraphEntryModel>, Collection<Long>> entry : providersToModelIds.asMap().entrySet()) {
        ITimeGraphDataProvider<? extends TimeGraphEntryModel> dataProvider = entry.getKey();
        Map<@NonNull String, @NonNull Object> parameters = getFetchRowModelParameters(start, end, resolution, fullSearch, entry.getValue());
        TmfModelResponse<TimeGraphModel> response = dataProvider.fetchRowModel(parameters, monitor);
        TimeGraphModel model = response.getModel();
        if (model != null) {
            zoomEntries(fEntries.row(dataProvider), model.getRows(), response.getStatus() == ITmfResponse.Status.COMPLETED, sampling);
        }
        subMonitor.worked(1);
    }
}
Also used : ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) SubMonitor(org.eclipse.core.runtime.SubMonitor) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) Collection(java.util.Collection) Sampling(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry.Sampling)

Example 27 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphView method getViewMarkerList.

@Override
@NonNull
protected List<IMarkerEvent> getViewMarkerList(Iterable<@NonNull TimeGraphEntry> entries, long startTime, long endTime, long resolution, @NonNull IProgressMonitor monitor) {
    List<IMarkerEvent> viewMarkerList = super.getViewMarkerList(startTime, endTime, resolution, monitor);
    List<@NonNull TimeGraphEntry> traceEntries = getEntryList(getTrace());
    if (traceEntries == null) {
        return viewMarkerList;
    }
    List<@NonNull Long> times = StateSystemUtils.getTimes(startTime, endTime, resolution);
    Multimap<ITimeGraphDataProvider<? extends TimeGraphEntryModel>, Long> providersToModelIds = filterGroupEntries(entries, startTime, endTime);
    for (ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider : providersToModelIds.keySet()) {
        if (provider instanceof IOutputAnnotationProvider) {
            List<String> categories = new ArrayList<>(fMarkerCategories.get(provider));
            categories.removeIf(category -> !getTimeGraphViewer().isMarkerCategoryVisible(category));
            if (categories.isEmpty()) {
                continue;
            }
            Map<@NonNull String, @NonNull Object> parameters = getFetchAnnotationsParameters(times, providersToModelIds.get(provider));
            parameters.put(DataProviderParameterUtils.REQUESTED_MARKER_CATEGORIES_KEY, categories);
            TmfModelResponse<@NonNull AnnotationModel> response = ((IOutputAnnotationProvider) provider).fetchAnnotations(parameters, new NullProgressMonitor());
            AnnotationModel model = response.getModel();
            if (model != null) {
                for (Entry<String, Collection<Annotation>> entry : model.getAnnotations().entrySet()) {
                    String category = entry.getKey();
                    for (Annotation annotation : entry.getValue()) {
                        if (annotation.getType() == AnnotationType.CHART) {
                            // If the annotation entry ID is -1 we want the
                            // marker to span across all entries
                            ITimeGraphEntry markerEntry = null;
                            if (annotation.getEntryId() != -1) {
                                synchronized (fEntries) {
                                    markerEntry = fEntries.get(provider, annotation.getEntryId());
                                }
                            }
                            MarkerEvent markerEvent = new MarkerEvent(annotation, markerEntry, category, true);
                            viewMarkerList.add(markerEvent);
                        }
                    }
                }
            }
        }
    }
    return viewMarkerList;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) ArrayList(java.util.ArrayList) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 28 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphView method getViewMarkerCategories.

@Override
@NonNull
protected List<String> getViewMarkerCategories() {
    List<String> viewMarkerCategories = super.getViewMarkerCategories();
    Collection<ITimeGraphDataProvider<? extends @NonNull TimeGraphEntryModel>> providers = getProviders(getTrace());
    if (providers.isEmpty()) {
        return viewMarkerCategories;
    }
    for (ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider : providers) {
        if (provider instanceof IOutputAnnotationProvider) {
            Map<@NonNull String, @NonNull Object> parameters = getFetchAnnotationCategoriesParameters();
            TmfModelResponse<@NonNull AnnotationCategoriesModel> response = ((IOutputAnnotationProvider) provider).fetchAnnotationCategories(parameters, new NullProgressMonitor());
            AnnotationCategoriesModel model = response.getModel();
            if (model != null) {
                List<@NonNull String> categories = model.getAnnotationCategories();
                viewMarkerCategories.addAll(categories);
                fMarkerCategories.put(provider, categories);
            }
        }
    }
    return viewMarkerCategories;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 29 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphView method buildEntryList.

@Override
protected void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor) {
    ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> dataProvider = DataProviderManager.getInstance().getDataProvider(trace, getProviderId(), ITimeGraphDataProvider.class);
    if (dataProvider == null) {
        return;
    }
    ITimeGraphPresentationProvider presentationProvider = getPresentationProvider();
    if (presentationProvider instanceof BaseDataProviderTimeGraphPresentationProvider) {
        ((BaseDataProviderTimeGraphPresentationProvider) presentationProvider).addProvider(dataProvider, getTooltipResolver(dataProvider));
    }
    boolean complete = false;
    while (!complete && !monitor.isCanceled()) {
        Map<@NonNull String, @NonNull Object> parameters = getFetchTreeParameters();
        TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = dataProvider.fetchTree(parameters, monitor);
        if (response.getStatus() == ITmfResponse.Status.FAILED) {
            // $NON-NLS-1$
            Activator.getDefault().logError(getClass().getSimpleName() + " Data Provider failed: " + response.getStatusMessage());
            return;
        } else if (response.getStatus() == ITmfResponse.Status.CANCELLED) {
            return;
        }
        complete = response.getStatus() == ITmfResponse.Status.COMPLETED;
        double factor = 1.0;
        TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
        if (model != null) {
            synchronized (fEntries) {
                Object scope = (model.getScope() == null) ? dataProvider : model.getScope();
                fProviders.put(parentTrace, dataProvider);
                fScopes.put(parentTrace, scope);
                /*
                     * The provider may send entries unordered and parents may
                     * not exist when child is constructor, we'll re-unite
                     * families at the end
                     */
                List<TimeGraphEntry> orphaned = new ArrayList<>();
                Map<Long, AtomicInteger> indexMap = new HashMap<>();
                for (TimeGraphEntryModel entry : model.getEntries()) {
                    TimeGraphEntry uiEntry = fScopedEntries.get(scope, entry.getId());
                    if (entry.getParentId() != -1) {
                        if (uiEntry == null) {
                            uiEntry = new TimeGraphEntry(entry);
                            TimeGraphEntry parent = fScopedEntries.get(scope, entry.getParentId());
                            if (parent != null) {
                                // TODO: the order of children from different data providers is undefined
                                int index = indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                                parent.addChild(index, uiEntry);
                            } else {
                                orphaned.add(uiEntry);
                            }
                            fScopedEntries.put(scope, entry.getId(), uiEntry);
                        } else {
                            indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                            uiEntry.updateModel(entry);
                        }
                    } else {
                        if (entry.getStartTime() != Long.MIN_VALUE) {
                            setStartTime(Long.min(getStartTime(), entry.getStartTime()));
                        }
                        setEndTime(Long.max(getEndTime(), entry.getEndTime() + 1));
                        if (uiEntry != null) {
                            uiEntry.updateModel(entry);
                        } else {
                            // Do not assume that parentless entries are
                            // trace entries
                            uiEntry = new TraceEntry(entry, trace, dataProvider);
                            fScopedEntries.put(scope, entry.getId(), uiEntry);
                            addToEntryList(parentTrace, Collections.singletonList(uiEntry));
                        }
                    }
                    fEntries.put(dataProvider, entry.getId(), uiEntry);
                    fEntryIds.put(uiEntry, dataProvider, entry.getId());
                }
                // Find missing parents
                // Orphans should be inserted before non-orphans
                indexMap.clear();
                for (TimeGraphEntry orphanedEntry : orphaned) {
                    TimeGraphEntry parent = fScopedEntries.get(scope, orphanedEntry.getEntryModel().getParentId());
                    if (parent != null) {
                        int index = indexMap.computeIfAbsent(parent.getEntryModel().getId(), l -> new AtomicInteger()).getAndIncrement();
                        parent.addChild(index, orphanedEntry);
                    }
                }
            }
            long start = getStartTime();
            long end = getEndTime();
            final long resolution = Long.max(1, (end - start) / getDisplayWidth());
            @NonNull Iterable<@NonNull TimeGraphEntry> entries;
            synchronized (fEntries) {
                entries = ImmutableList.copyOf(fEntries.values());
            }
            zoomEntries(entries, start, end, resolution, monitor);
        }
        if (monitor.isCanceled()) {
            return;
        }
        if (parentTrace.equals(getTrace())) {
            synchingToTime(getTimeGraphViewer().getSelectionBegin());
            refresh();
        }
        monitor.worked(1);
        if (!complete && !monitor.isCanceled()) {
            try {
                Thread.sleep((long) (BUILD_UPDATE_TIMEOUT * factor));
                factor = Math.min(20, factor + 1);
            } catch (InterruptedException e) {
                // $NON-NLS-1$
                Activator.getDefault().logError("Failed to wait for data provider", e);
                Thread.currentThread().interrupt();
            }
        }
    }
}
Also used : IFilterProperty(org.eclipse.tracecompass.tmf.core.model.timegraph.IFilterProperty) DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) BiFunction(java.util.function.BiFunction) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) NamedTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NamedTimeEvent) HashBasedTable(com.google.common.collect.HashBasedTable) TimeGraphPresentationProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider) Matcher(java.util.regex.Matcher) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Nullable(org.eclipse.jdt.annotation.Nullable) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent) Composite(org.eclipse.swt.widgets.Composite) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent) Map(java.util.Map) TmfStrings(org.eclipse.tracecompass.tmf.core.TmfStrings) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TimeGraphControl(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) Collection(java.util.Collection) MenuManager(org.eclipse.jface.action.MenuManager) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) ViewFilterDialog(org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.ViewFilterDialog) Messages(org.eclipse.tracecompass.internal.tmf.ui.views.timegraph.Messages) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GroupMarker(org.eclipse.jface.action.GroupMarker) Objects(java.util.Objects) List(java.util.List) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) StateSystemUtils(org.eclipse.tracecompass.statesystem.core.StateSystemUtils) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) Pattern(java.util.regex.Pattern) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) NonNull(org.eclipse.jdt.annotation.NonNull) AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) NullTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent) Iterables(com.google.common.collect.Iterables) AnnotationType(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation.AnnotationType) ITimeGraphPresentationProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider) SubMonitor(org.eclipse.core.runtime.SubMonitor) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) HashMap(java.util.HashMap) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) BaseDataProviderTimeGraphPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.BaseDataProviderTimeGraphPresentationProvider) ImmutableList(com.google.common.collect.ImmutableList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) ITmfResponse(org.eclipse.tracecompass.tmf.core.response.ITmfResponse) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) TmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite) Activator(org.eclipse.tracecompass.internal.tmf.ui.Activator) IOutputElement(org.eclipse.tracecompass.tmf.core.model.IOutputElement) OpenSourceCodeAction(org.eclipse.tracecompass.tmf.ui.actions.OpenSourceCodeAction) Sampling(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry.Sampling) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IMenuManager(org.eclipse.jface.action.IMenuManager) IContributionItem(org.eclipse.jface.action.IContributionItem) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) Table(com.google.common.collect.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITimeGraphPresentationProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider) NonNull(org.eclipse.jdt.annotation.NonNull) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) BaseDataProviderTimeGraphPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.BaseDataProviderTimeGraphPresentationProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)

Aggregations

TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)29 NonNull (org.eclipse.jdt.annotation.NonNull)16 ArrayList (java.util.ArrayList)12 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)11 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)10 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)10 ITimeGraphDataProvider (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider)8 Element (org.w3c.dom.Element)8 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)7 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)7 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 List (java.util.List)6 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)6 Collection (java.util.Collection)5 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)5 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)5 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)5 Status (org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status)4