Search in sources :

Example 11 with TimeGraphModel

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

the class FlameChartView method getPreviousEventAction.

/**
 * Get the previous event action.
 *
 * @return The Action object
 */
private Action getPreviousEventAction() {
    Action prevAction = fPrevEventAction;
    if (prevAction == null) {
        Action superPrevAction = getTimeGraphViewer().getPreviousEventAction();
        prevAction = new Action() {

            @Override
            public void run() {
                TimeGraphViewer viewer = getTimeGraphViewer();
                ITimeGraphEntry entry = viewer.getSelection();
                if (entry instanceof TimeGraphEntry) {
                    TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
                    ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
                    long selectionBegin = viewer.getSelectionBegin();
                    SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(Lists.newArrayList(Long.MIN_VALUE, selectionBegin), Collections.singleton(callStackEntry.getEntryModel().getId()));
                    TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
                    TimeGraphModel model = response.getModel();
                    if (model == null || model.getRows().size() != 1) {
                        return;
                    }
                    List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
                    if (row.size() != 1) {
                        return;
                    }
                    ITimeGraphState stackInterval = row.get(0);
                    viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
                    int stackLevel = stackInterval.getValue();
                    ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
                    viewer.setSelection(selectedEntry, true);
                    viewer.getTimeGraphControl().fireSelectionChanged();
                    startZoomThread(viewer.getTime0(), viewer.getTime1());
                }
            }
        };
        prevAction.setText(superPrevAction.getText());
        prevAction.setToolTipText(superPrevAction.getToolTipText());
        prevAction.setImageDescriptor(superPrevAction.getImageDescriptor());
        fPrevEventAction = prevAction;
    }
    return prevAction;
}
Also used : Action(org.eclipse.jface.action.Action) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull) TimeGraphViewer(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with TimeGraphModel

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

the class AbstractTimeGraphDataProvider method fetchRowModel.

@Override
public final TmfModelResponse<TimeGraphModel> fetchRowModel(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
    A module = getAnalysisModule();
    if (!module.waitForInitialization()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    ITmfStateSystem ss = module.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    long currentEnd = ss.getCurrentEndTime();
    Object times = parameters.get(DataProviderParameterUtils.REQUESTED_TIME_KEY);
    Object items = parameters.get(DataProviderParameterUtils.REQUESTED_ITEMS_KEY);
    if (!(times instanceof List<?>) || ((List<?>) times).isEmpty() || !(items instanceof Collection<?>)) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Object end = Iterables.getLast(((List<?>) times));
    if (!(end instanceof Number)) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    boolean complete = ss.waitUntilBuilt(0) || ((Number) end).longValue() <= currentEnd;
    try (FlowScopeLog scope = // $NON-NLS-1$
    new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTimeGraphDataProvider#fetchRowModel").setCategory(getClass().getSimpleName()).build()) {
        TimeGraphModel models = getRowModel(ss, parameters, monitor);
        if (models == null) {
            // getRowModel returns null if the query was cancelled.
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        return new TmfModelResponse<>(models, complete ? Status.COMPLETED : Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
    } catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
        return new TmfModelResponse<>(null, Status.FAILED, String.valueOf(e.getMessage()));
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) List(java.util.List) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 13 with TimeGraphModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel 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)

Example 14 with TimeGraphModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel 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 15 with TimeGraphModel

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

the class FlameChartView method getNextEventAction.

/**
 * Get the the next event action.
 *
 * @return The action object
 */
private Action getNextEventAction() {
    Action nextAction = fNextEventAction;
    if (nextAction == null) {
        Action superNextAction = getTimeGraphViewer().getNextEventAction();
        nextAction = new Action() {

            @Override
            public void run() {
                TimeGraphViewer viewer = getTimeGraphViewer();
                ITimeGraphEntry entry = viewer.getSelection();
                if (entry instanceof TimeGraphEntry) {
                    TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
                    ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
                    long selectionBegin = viewer.getSelectionBegin();
                    SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(selectionBegin, Long.MAX_VALUE, 2, Collections.singleton(callStackEntry.getEntryModel().getId()));
                    TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
                    TimeGraphModel model = response.getModel();
                    if (model == null || model.getRows().size() != 1) {
                        return;
                    }
                    List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
                    if (row.size() != 1) {
                        return;
                    }
                    ITimeGraphState stackInterval = row.get(0);
                    if (stackInterval.getStartTime() <= selectionBegin && selectionBegin <= stackInterval.getStartTime() + stackInterval.getDuration()) {
                        viewer.setSelectedTimeNotify(stackInterval.getStartTime() + stackInterval.getDuration() + 1, true);
                    } else {
                        viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
                    }
                    int stackLevel = stackInterval.getValue();
                    ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
                    viewer.setSelection(selectedEntry, true);
                    viewer.getTimeGraphControl().fireSelectionChanged();
                    startZoomThread(viewer.getTime0(), viewer.getTime1());
                }
            }
        };
        nextAction.setText(superNextAction.getText());
        nextAction.setToolTipText(superNextAction.getToolTipText());
        nextAction.setImageDescriptor(superNextAction.getImageDescriptor());
        fNextEventAction = nextAction;
    }
    return nextAction;
}
Also used : Action(org.eclipse.jface.action.Action) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull) TimeGraphViewer(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)16 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)12 ITimeGraphRowModel (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel)12 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)10 ArrayList (java.util.ArrayList)9 NonNull (org.eclipse.jdt.annotation.NonNull)9 HashMap (java.util.HashMap)7 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)7 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)6 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)6 Map (java.util.Map)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)5 TimeGraphRowModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel)5 List (java.util.List)4 Predicate (java.util.function.Predicate)4 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)4 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)4 LinkedHashMap (java.util.LinkedHashMap)3 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)3