Search in sources :

Example 11 with ITimeGraphState

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

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

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

the class ThreadStatusDataProviderTest method assertEqualsStates.

private static void assertEqualsStates(String string, @NonNull List<@NonNull ITimeGraphState> states, String element) {
    String[] stringStates = string.split(",");
    for (int i = 0; i < stringStates.length / 4; i++) {
        ITimeGraphState state = states.get(i);
        assertEquals(element + ": start time at position " + i, Long.parseLong(stringStates[i * 4]), state.getStartTime());
        assertEquals(element + ": duration at position " + i, Long.parseLong(stringStates[i * 4 + 1]), state.getDuration());
        OutputElementStyle style = state.getStyle();
        if (style == null) {
            // Expected a value of Long
            try {
                assertEquals(element + ": value at position " + i, Long.parseLong(stringStates[i * 4 + 2]), state.getValue());
            } catch (NumberFormatException e) {
                fail(element + ": value at position " + i + ": did not expect a null style");
            }
        } else {
            assertEquals(element + ": value at position " + i, stringStates[i * 4 + 2], style.getParentKey());
        }
        assertEquals(element + ": label at position " + i, stringStates[i * 4 + 3], String.valueOf(state.getLabel()));
    }
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 14 with ITimeGraphState

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

the class ResourcesStatusDataProvider method getSyscalls.

/**
 * Get a list of all the system call states over the duration of the current
 * syscall interval, as several threads can be scheduled over that interval
 *
 * @param ss
 *            backing state system
 * @param syscallInterval
 *            current syscall interval
 * @param currentThreadIntervals
 *            sampled current thread intervals for the CPU
 * @return a List of intervals with the system call name label.
 */
private static List<@NonNull ITimeGraphState> getSyscalls(@NonNull ITmfStateSystem ss, ITmfStateInterval syscallInterval, @NonNull NavigableSet<ITmfStateInterval> currentThreadIntervals) throws StateSystemDisposedException {
    List<@NonNull ITimeGraphState> list = new ArrayList<>();
    for (ITmfStateInterval currentThread : currentThreadIntervals) {
        // filter the current thread intervals which overlap the syscall interval
        if (currentThread.getStartTime() <= syscallInterval.getEndTime() && currentThread.getEndTime() >= syscallInterval.getStartTime()) {
            long start = Long.max(syscallInterval.getStartTime(), currentThread.getStartTime());
            long end = Long.min(syscallInterval.getEndTime(), currentThread.getEndTime());
            long duration = end - start + 1;
            Object tid = currentThread.getValue();
            if (tid instanceof Integer) {
                int syscallQuark = ss.optQuarkAbsolute(Attributes.THREADS, String.valueOf(tid), Attributes.SYSTEM_CALL);
                if (syscallQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
                    Object syscallName = ss.querySingleState(start, syscallQuark).getValue();
                    if (syscallName instanceof String) {
                        list.add(new TimeGraphState(start, duration, String.valueOf(syscallName), STYLE_MAP.computeIfAbsent(LinuxStyle.SYSCALL.getLabel(), style -> new OutputElementStyle(style))));
                        continue;
                    }
                }
            }
            list.add(new TimeGraphState(start, duration, null, STYLE_MAP.computeIfAbsent(LinuxStyle.SYSCALL.getLabel(), style -> new OutputElementStyle(style))));
        }
    }
    return list;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 15 with ITimeGraphState

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

the class ThreadStatusDataProvider method createTimeGraphState.

@NonNull
private static ITimeGraphState createTimeGraphState(ITmfStateInterval interval, NavigableSet<ITmfStateInterval> syscalls) {
    long startTime = interval.getStartTime();
    long duration = interval.getEndTime() - startTime + 1;
    Object status = interval.getValue();
    if (status instanceof Integer) {
        int s = (int) status;
        if (s == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
            // intervals are sorted by start time
            ITmfStateInterval syscall = syscalls.floor(new TmfStateInterval(startTime, startTime + 1, 0, 0));
            if (syscall != null) {
                Object value = syscall.getValue();
                if (value instanceof String) {
                    return new TimeGraphState(startTime, duration, String.valueOf(value), getElementStyle(s));
                }
            }
        }
        return new TimeGraphState(startTime, duration, null, getElementStyle(s));
    }
    return new TimeGraphState(startTime, duration, Integer.MIN_VALUE);
}
Also used : TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) 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) NonNull(org.eclipse.jdt.annotation.NonNull)

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