Search in sources :

Example 16 with ITimeGraphState

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

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

the class FlameChartView method createPartControl.

// ------------------------------------------------------------------------
// ViewPart
// ------------------------------------------------------------------------
@Override
public void createPartControl(@Nullable Composite parent) {
    super.createPartControl(parent);
    getTimeGraphViewer().addTimeListener(event -> synchingToTime(event.getBeginTime()));
    getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(@Nullable MouseEvent event) {
            ITimeGraphEntry selection = getTimeGraphViewer().getSelection();
            if (!(selection instanceof TimeGraphEntry)) {
                // also null checks
                return;
            }
            ITimeGraphState function = fFunctions.get(((TimeGraphEntry) selection).getEntryModel().getId());
            if (function != null) {
                long entryTime = function.getStartTime();
                long exitTime = entryTime + function.getDuration();
                TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(entryTime), TmfTimestamp.fromNanos(exitTime));
                broadcast(new TmfWindowRangeUpdatedSignal(FlameChartView.this, range, getTrace()));
                getTimeGraphViewer().setStartFinishTime(entryTime, exitTime);
                startZoomThread(entryTime, exitTime);
            }
        }
    });
    getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(@Nullable MouseEvent e) {
            TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
            ISelection selection = timeGraphControl.getSelection();
            if (selection instanceof IStructuredSelection) {
                for (Object object : ((IStructuredSelection) selection).toList()) {
                    if (object instanceof NamedTimeEvent) {
                        NamedTimeEvent event = (NamedTimeEvent) object;
                        long startTime = event.getTime();
                        long endTime = startTime + event.getDuration();
                        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
                        broadcast(new TmfWindowRangeUpdatedSignal(FlameChartView.this, range, getTrace()));
                        getTimeGraphViewer().setStartFinishTime(startTime, endTime);
                        startZoomThread(startTime, endTime);
                        break;
                    }
                }
            }
        }
    });
    IEditorPart editor = getSite().getPage().getActiveEditor();
    if (editor instanceof ITmfTraceEditor) {
        ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
        if (trace != null) {
            traceSelected(new TmfTraceSelectedSignal(this, trace));
        }
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) NamedTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NamedTimeEvent) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) ISelection(org.eclipse.jface.viewers.ISelection) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) TimeGraphControl(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl) ITmfTraceEditor(org.eclipse.tracecompass.tmf.ui.editors.ITmfTraceEditor)

Example 18 with ITimeGraphState

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

Example 19 with ITimeGraphState

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

Example 20 with ITimeGraphState

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

the class BaseDataProviderTimeGraphView method createTimeEvents.

/**
 * Create {@link ITimeEvent}s for an entry from the list of
 * {@link ITimeGraphState}s, filling in the gaps.
 *
 * @param entry
 *            the {@link TimeGraphEntry} on which we are working
 * @param values
 *            the list of {@link ITimeGraphState}s from the
 *            {@link ITimeGraphDataProvider}.
 * @return a contiguous List of {@link ITimeEvent}s
 */
protected List<ITimeEvent> createTimeEvents(TimeGraphEntry entry, List<ITimeGraphState> values) {
    List<ITimeEvent> events = new ArrayList<>(values.size());
    ITimeEvent prev = null;
    for (ITimeGraphState state : values) {
        ITimeEvent event = createTimeEvent(entry, state);
        if (prev != null) {
            long prevEnd = prev.getTime() + prev.getDuration();
            ViewFilterDialog viewFilterDialog = getViewFilterDialog();
            if (prevEnd < event.getTime() && (viewFilterDialog == null || !viewFilterDialog.hasActiveSavedFilters())) {
                // fill in the gap.
                TimeEvent timeEvent = new TimeEvent(entry, prevEnd, event.getTime() - prevEnd);
                if (viewFilterDialog != null && viewFilterDialog.isFilterActive()) {
                    timeEvent.setProperty(IFilterProperty.DIMMED, true);
                }
                events.add(timeEvent);
            }
        }
        prev = event;
        events.add(event);
    }
    return events;
}
Also used : ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) ViewFilterDialog(org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.ViewFilterDialog) ArrayList(java.util.ArrayList) NamedTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NamedTimeEvent) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) NullTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Aggregations

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