Search in sources :

Example 1 with ITimeGraphState

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

the class XmlTimeGraphDataProviderTest method assertEqualsStates.

private static void assertEqualsStates(String name, String string, @NonNull List<@NonNull ITimeGraphState> states) {
    String[] stringStates = string.split(",");
    for (int i = 0; i < stringStates.length / 4; i++) {
        ITimeGraphState state = states.get(i);
        assertNotNull("State " + i + " for " + name, state);
        assertEquals("Start time of state " + i + " for " + name, Long.parseLong(stringStates[i * 4]), state.getStartTime());
        assertEquals("Duration of state " + i + " for " + name, Long.parseLong(stringStates[i * 4 + 1]), state.getDuration());
        assertEquals("Value of state " + i + " for " + name, Long.parseLong(stringStates[i * 4 + 2]), state.getValue());
        assertEquals("Label of state " + i + " for " + name, stringStates[i * 4 + 3], String.valueOf(state.getLabel()));
    }
    assertEquals("Expected number of states", stringStates.length / 4, states.size());
}
Also used : ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 2 with ITimeGraphState

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

the class XmlTimeGraphDataProvider method createRows.

@NonNull
private Collection<@NonNull ITimeGraphRowModel> createRows(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, long[] timesRequested, @NonNull Map<@NonNull String, @NonNull Object> parameters, @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(parameters);
    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<>()));
    }
    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) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 3 with ITimeGraphState

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

the class StateSystemDataProvider method getModuleRowModels.

private static ITimeGraphRowModel getModuleRowModels(ModuleEntryModel module) {
    TimeGraphRowModel moduleRow = new TimeGraphRowModel(module.getId(), new ArrayList<>());
    List<@NonNull ITimeGraphState> states = moduleRow.getStates();
    states.add(new TimeGraphState(module.getStartTime(), module.getEndTime() - module.getStartTime(), Integer.MAX_VALUE));
    return moduleRow;
}
Also used : ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 4 with ITimeGraphState

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

the class StateSystemDataProvider method getRowModels.

private List<@NonNull ITimeGraphRowModel> getRowModels(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, @Nullable List<Long> times, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    // Create predicates
    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));
    }
    // Create quark to row
    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<>()));
    }
    for (ITmfStateInterval interval : ss.query2D(idToDisplayQuark.keySet(), getTimes(ss, times))) {
        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, ss.getCurrentEndTime());
            applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
        }
    }
    // sort every row model so their states can be in chronological order
    for (ITimeGraphRowModel model : quarkToRow.values()) {
        model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
    }
    return new ArrayList<>(quarkToRow.values());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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 5 with ITimeGraphState

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

the class StateSystemDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
    // Get the quarks to display
    Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    synchronized (fEntryBuilder) {
        if (selectedItems == null) {
            // No selected items, take them all
            selectedItems = fIDToDisplayQuark.keySet();
        }
        for (Long id : selectedItems) {
            Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
            if (pair != null) {
                table.put(pair.getFirst(), pair.getSecond(), id);
            }
        }
    }
    List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
    try {
        List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
        for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
            ITmfStateSystem ss = Objects.requireNonNull(ssEntry.getKey());
            List<@NonNull ITimeGraphRowModel> rows = getRowModels(ss, ssEntry.getValue(), times, fetchParameters, monitor);
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
            synchronized (fEntryBuilder) {
                // Add the SS
                Long ssId = fSsToId.get(ss);
                if (ssId != null && selectedItems.contains(ssId)) {
                    TimeGraphRowModel ssRow = new TimeGraphRowModel(ssId, new ArrayList<>());
                    List<@NonNull ITimeGraphState> states = ssRow.getStates();
                    states.add(new TimeGraphState(ss.getStartTime(), ss.getCurrentEndTime() - ss.getStartTime(), Integer.MAX_VALUE));
                    rows.add(ssRow);
                }
            }
            allRows.addAll(rows);
        }
        synchronized (fEntryBuilder) {
            for (ModuleEntryModel module : fModuleEntryModelList) {
                if (selectedItems.contains(module.getId())) {
                    allRows.add(getModuleRowModels(module));
                }
            }
        }
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
}
Also used : 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) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) 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) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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