Search in sources :

Example 11 with ITimeGraphRowModel

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

the class ThreadStatusDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, IProgressMonitor monitor) {
    ITmfStateSystem ss = fModule.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    TreeMultimap<Integer, ITmfStateInterval> intervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(ITmfStateInterval::getStartTime));
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    Map<Long, Integer> selectedIdsToQuarks = getSelectedIdsToQuarks(filter);
    Collection<Integer> stateAndSyscallQuarks = addSyscall(selectedIdsToQuarks.values(), ss);
    Collection<Long> times = getTimes(ss, filter);
    try {
        /* Do the actual query */
        for (ITmfStateInterval interval : ss.query2D(stateAndSyscallQuarks, times)) {
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
            intervals.put(interval.getAttribute(), interval);
        }
    } catch (TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, String.valueOf(e.getMessage()));
    }
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(fetchParameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    @NonNull List<@NonNull ITimeGraphRowModel> rows = new ArrayList<>();
    for (Entry<Long, Integer> entry : selectedIdsToQuarks.entrySet()) {
        int quark = entry.getValue();
        NavigableSet<ITmfStateInterval> states = intervals.get(quark);
        NavigableSet<ITmfStateInterval> syscalls = intervals.get(ss.optQuarkRelative(quark, Attributes.SYSTEM_CALL));
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        List<ITimeGraphState> eventList = new ArrayList<>();
        states.forEach(i -> {
            ITimeGraphState timegraphState = createTimeGraphState(i, syscalls);
            Long key = Objects.requireNonNull(entry.getKey());
            applyFilterAndAddState(eventList, timegraphState, key, predicates, monitor);
        });
        rows.add(new TimeGraphRowModel(entry.getKey(), eventList));
    }
    return new TmfModelResponse<>(new TimeGraphModel(rows), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) Predicate(java.util.function.Predicate) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) AtomicLong(java.util.concurrent.atomic.AtomicLong) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 12 with ITimeGraphRowModel

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

the class ControlFlowView method synchingToTime.

@Override
protected void synchingToTime(long time) {
    List<TimeGraphEntry> traceEntries = getEntryList(getTrace());
    if (traceEntries == null) {
        return;
    }
    for (TraceEntry traceEntry : Iterables.filter(traceEntries, TraceEntry.class)) {
        Iterable<TimeGraphEntry> unfiltered = Utils.flatten(traceEntry);
        Map<Long, TimeGraphEntry> map = Maps.uniqueIndex(unfiltered, e -> e.getEntryModel().getId());
        // use time -1 as a lower bound for the end of Time events to be included.
        SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(time - 1, time, 2, map.keySet());
        TmfModelResponse<@NonNull TimeGraphModel> response = traceEntry.getProvider().fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
        TimeGraphModel model = response.getModel();
        if (model == null) {
            continue;
        }
        for (ITimeGraphRowModel row : model.getRows()) {
            if (syncToRow(row, time, map)) {
                return;
            }
        }
    }
}
Also used : ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)

Example 13 with ITimeGraphRowModel

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

the class FlameChartView method synchingToTime.

/**
 * @since 1.2
 */
@Override
protected void synchingToTime(final long time) {
    List<TimeGraphEntry> traceEntries = getEntryList(getTrace());
    if (traceEntries != null) {
        for (TraceEntry traceEntry : Iterables.filter(traceEntries, TraceEntry.class)) {
            Iterable<TimeGraphEntry> unfiltered = Utils.flatten(traceEntry);
            Map<Long, TimeGraphEntry> map = Maps.uniqueIndex(unfiltered, e -> e.getEntryModel().getId());
            // use time -1 as a lower bound for the end of Time events to be included.
            SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(time - 1, time, 2, map.keySet());
            TmfModelResponse<@NonNull TimeGraphModel> response = traceEntry.getProvider().fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
            TimeGraphModel model = response.getModel();
            if (model != null) {
                for (ITimeGraphRowModel row : model.getRows()) {
                    syncToRow(row, time, map);
                }
            }
        }
    }
    fSyncSelection = false;
    if (Display.getCurrent() != null) {
        getTimeGraphViewer().refresh();
    }
}
Also used : ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)

Example 14 with ITimeGraphRowModel

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

the class ExampleTimeGraphDataProvider method getDefaultRowModels.

@Nullable
private List<ITimeGraphRowModel> getDefaultRowModels(Map<String, Object> fetchParameters, ITmfStateSystem ss, @Nullable IProgressMonitor monitor) throws IndexOutOfBoundsException, TimeRangeException, StateSystemDisposedException {
    Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>();
    // Prepare the quarks to display
    Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    if (selectedItems == null) {
        // No selected items, take them all
        selectedItems = fIDToDisplayQuark.keySet();
    }
    for (Long id : selectedItems) {
        Integer quark = fIDToDisplayQuark.get(id);
        if (quark != null) {
            quarkToRow.put(quark, new TimeGraphRowModel(id, new ArrayList<>()));
        }
    }
    // This regex map automatically filters or highlights the entry
    // according to the global filter entered by the user
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(fetchParameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    // Query the state system to fill the states
    long currentEndTime = ss.getCurrentEndTime();
    for (ITmfStateInterval interval : ss.query2D(quarkToRow.keySet(), getTimes(ss, DataProviderParameterUtils.extractTimeRequested(fetchParameters)))) {
        if (monitor != null && monitor.isCanceled()) {
            return Collections.emptyList();
        }
        ITimeGraphRowModel row = quarkToRow.get(interval.getAttribute());
        if (row != null) {
            List<@NonNull ITimeGraphState> states = row.getStates();
            ITimeGraphState timeGraphState = getStateFromInterval(interval, currentEndTime);
            // This call will compare the state with the filter predicate
            applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
        }
    }
    for (ITimeGraphRowModel model : quarkToRow.values()) {
        model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
    }
    return new ArrayList<>(quarkToRow.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) Predicate(java.util.function.Predicate) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) NonNull(org.eclipse.jdt.annotation.NonNull) AtomicLong(java.util.concurrent.atomic.AtomicLong) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 15 with ITimeGraphRowModel

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

the class CriticalPathDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    IGraphWorker graphWorker = getCurrent();
    if (graphWorker == null) {
        return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    CriticalPathVisitor visitor = fHorizontalVisitorCache.getIfPresent(graphWorker);
    if (visitor == null) {
        return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    // TODO server: Parameters validation should be handle separately. It
    // can be either in the data provider itself or before calling it. It
    // will avoid the creation of filters and the content of the map can be
    // use directly.
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(fetchParameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    List<@NonNull ITimeGraphRowModel> rowModels = new ArrayList<>();
    for (Long id : filter.getSelectedItems()) {
        /*
             * need to use asMap, so that we don't return a row for an ID that does not
             * belong to this provider, else fStates.get(id) might return an empty
             * collection for an id from another data provider.
             */
        Collection<ITimeGraphState> states = visitor.fStates.asMap().get(id);
        if (states != null) {
            List<ITimeGraphState> filteredStates = new ArrayList<>();
            for (ITimeGraphState state : states) {
                if (overlaps(state.getStartTime(), state.getDuration(), filter.getTimesRequested())) {
                    // Reset the properties for this state before filtering
                    state.setActiveProperties(0);
                    applyFilterAndAddState(filteredStates, state, id, predicates, monitor);
                }
            }
            rowModels.add(new TimeGraphRowModel(id, filteredStates));
        }
    }
    return new TmfModelResponse<>(new TimeGraphModel(rowModels), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) IGraphWorker(org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) Predicate(java.util.function.Predicate) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull) AtomicLong(java.util.concurrent.atomic.AtomicLong) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

ITimeGraphRowModel (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel)18 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 NonNull (org.eclipse.jdt.annotation.NonNull)11 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)11 TimeGraphRowModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel)11 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 Predicate (java.util.function.Predicate)8 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)8 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)7 Map (java.util.Map)5 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)5 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)5 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)4 TimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState)4 LinkedHashMap (java.util.LinkedHashMap)3 ImmutableList (com.google.common.collect.ImmutableList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2