Search in sources :

Example 16 with ITimeGraphRowModel

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

the class CallStackDataProvider method getRowModel.

@Override
protected TimeGraphModel getRowModel(ITmfStateSystem ss, @NonNull Map<@NonNull String, @NonNull Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(parameters);
    if (filter == null) {
        return null;
    }
    Map<@NonNull Long, @NonNull Integer> entries = getSelectedEntries(filter);
    if (entries.size() == 1 && filter.getTimesRequested().length == 2) {
        // this is a request for a follow event.
        Entry<@NonNull Long, @NonNull Integer> entry = entries.entrySet().iterator().next();
        if (filter.getStart() == Long.MIN_VALUE) {
            return new TimeGraphModel(getFollowEvent(ss, entry, filter.getEnd(), false));
        } else if (filter.getEnd() == Long.MAX_VALUE) {
            return new TimeGraphModel(getFollowEvent(ss, entry, filter.getStart(), true));
        }
    }
    // $NON-NLS-1$
    SubMonitor subMonitor = SubMonitor.convert(monitor, "CallStackDataProvider#fetchRowModel", 2);
    ArrayListMultimap<Integer, ITmfStateInterval> intervals = ArrayListMultimap.create();
    Collection<Long> times = getTimes(filter, ss.getStartTime(), ss.getCurrentEndTime());
    /* Do the actual query */
    for (ITmfStateInterval interval : ss.query2D(entries.values(), times)) {
        if (subMonitor.isCanceled()) {
            return null;
        }
        intervals.put(interval.getAttribute(), interval);
    }
    subMonitor.worked(1);
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(parameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    List<@NonNull ITimeGraphRowModel> rows = new ArrayList<>();
    for (Map.Entry<Long, Integer> entry : entries.entrySet()) {
        if (subMonitor.isCanceled()) {
            return null;
        }
        Collection<ITmfStateInterval> states = intervals.get(entry.getValue());
        Long key = Objects.requireNonNull(entry.getKey());
        List<ITimeGraphState> eventList = new ArrayList<>(states.size());
        states.forEach(state -> {
            ITimeGraphState timeGraphState = createTimeGraphState(state);
            applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
        });
        eventList.sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
        rows.add(new TimeGraphRowModel(entry.getKey(), eventList));
    }
    subMonitor.worked(1);
    return new TimeGraphModel(rows);
}
Also used : HashMap(java.util.HashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) Predicate(java.util.function.Predicate) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) SubMonitor(org.eclipse.core.runtime.SubMonitor) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with ITimeGraphRowModel

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

the class CallStackDataProvider method getFollowEvent.

/**
 * Get the next or previous interval for a call stack entry ID, time and
 * direction
 *
 * @param ss
 *            this data provider's state system
 * @param entry
 *            whose key is the ID and value is the quark for the entry whose
 *            next / previous state we are searching for
 * @param time
 *            selection start time
 * @param forward
 *            if going to next or previous
 * @return the next / previous state encapsulated in a row if it exists,
 *         else null
 * @throws StateSystemDisposedException
 */
private static List<ITimeGraphRowModel> getFollowEvent(ITmfStateSystem ss, Entry<Long, Integer> entry, long time, boolean forward) throws StateSystemDisposedException {
    int parentQuark = ss.getParentAttributeQuark(entry.getValue());
    ITmfStateInterval current = ss.querySingleState(Long.max(ss.getStartTime(), Long.min(time, ss.getCurrentEndTime())), parentQuark);
    ITmfStateInterval interval = null;
    if (forward && current.getEndTime() + 1 <= ss.getCurrentEndTime()) {
        interval = ss.querySingleState(current.getEndTime() + 1, parentQuark);
    } else if (!forward && current.getStartTime() - 1 >= ss.getStartTime()) {
        interval = ss.querySingleState(current.getStartTime() - 1, parentQuark);
    }
    if (interval != null && interval.getValue() instanceof Number) {
        Object object = interval.getValue();
        if (object instanceof Number) {
            int value = ((Number) object).intValue();
            TimeGraphState state = new TimeGraphState(interval.getStartTime(), interval.getEndTime() - interval.getStartTime(), value);
            TimeGraphRowModel row = new TimeGraphRowModel(entry.getKey(), Collections.singletonList(state));
            return Collections.singletonList(row);
        }
    }
    return null;
}
Also used : ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) 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)

Example 18 with ITimeGraphRowModel

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

the class DataDrivenTimeGraphDataProvider method createRows.

private Collection<ITimeGraphRowModel> createRows(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    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));
    }
    long currentEndTime = ss.getCurrentEndTime();
    Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>(idToDisplayQuark.size());
    for (Entry<Integer, Long> entry : idToDisplayQuark.entrySet()) {
        quarkToRow.put(entry.getKey(), new TimeGraphRowModel(entry.getValue(), new ArrayList<>()));
    }
    List<Long> timesRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    for (ITmfStateInterval interval : ss.query2D(idToDisplayQuark.keySet(), getTimes(ss, timesRequested))) {
        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);
            applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
        }
    }
    for (ITimeGraphRowModel model : quarkToRow.values()) {
        model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
    }
    return 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)

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