Search in sources :

Example 16 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class TmfTreeCompositeDataProvider method fetchAnnotations.

@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    boolean isComplete = true;
    AnnotationModel model = new AnnotationModel(Collections.emptyMap());
    for (P dataProvider : getProviders()) {
        if (dataProvider instanceof IOutputAnnotationProvider) {
            TmfModelResponse<AnnotationModel> response = ((IOutputAnnotationProvider) dataProvider).fetchAnnotations(fetchParameters, monitor);
            isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
            model = AnnotationModel.of(model, response.getModel());
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
        }
    }
    if (isComplete) {
        return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 17 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class TmfTreeXYCompositeDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    /**
     * <pre>
     * Response status according to the provider's reponse statuses:
     *
     * * Cancelled -> The monitor is cancelled
     * * Failed -> At least one provider has failed
     * * Running -> At least one of the providers is running
     * * Completed -> All providers have completed
     * </pre>
     */
    List<P> providers = getProviders();
    // Get all the responses
    Collection<TmfModelResponse<ITmfXyModel>> responses = getXyResponses(fetchParameters, monitor, providers);
    if (monitor != null && monitor.isCanceled()) {
        return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
    }
    // If one response is failed, return a failed response with a concatenation of the messages
    String failedMsg = handleFailedStatus(responses);
    if (failedMsg != null) {
        return TmfXyResponseFactory.createFailedResponse(failedMsg);
    }
    boolean allCommon = Iterables.all(providers, ITmfCommonXAxisModel.class::isInstance);
    // The query is considered complete if all providers are completed
    boolean isComplete = Iterables.all(responses, response -> response.getStatus() == ITmfResponse.Status.COMPLETED);
    if (allCommon) {
        ImmutableList.Builder<IYModel> series = ImmutableList.builder();
        responses.forEach(response -> {
            ITmfCommonXAxisModel model = (ITmfCommonXAxisModel) response.getModel();
            if (model != null) {
                series.addAll(model.getYSeriesData());
            }
        });
        TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
        if (filter == null) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
        }
        return TmfXyResponseFactory.create(fTitle, filter.getTimesRequested(), series.build(), isComplete);
    }
    ImmutableList.Builder<ISeriesModel> series = ImmutableList.builder();
    responses.forEach(response -> {
        ITmfXyModel model = response.getModel();
        if (model != null) {
            series.addAll(model.getSeriesData());
        }
    });
    return TmfXyResponseFactory.create(fTitle, series.build(), isComplete);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ITmfCommonXAxisModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfCommonXAxisModel) ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 18 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class StateSystemDataProvider method fetchTooltip.

@Override
public TmfModelResponse<Map<String, String>> fetchTooltip(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Map<Long, Pair<ITmfStateSystem, Integer>> entries = getSelectedEntries(fetchParameters);
    if (entries.size() != 1) {
        // Not the expected size of tooltip, just return empty
        return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    Entry<@NonNull Long, @NonNull Pair<ITmfStateSystem, Integer>> entry = entries.entrySet().iterator().next();
    Map<String, String> tooltip = new HashMap<>();
    Integer quark = Objects.requireNonNull(entry.getValue()).getSecond();
    ITmfStateSystem ss = Objects.requireNonNull(entry.getValue()).getFirst();
    tooltip.put(String.valueOf(Messages.QuarkColumnLabel), Integer.toString(quark));
    tooltip.put(String.valueOf(Messages.AttributePathColumnLabel), ss.getFullAttributePath(quark));
    tooltip.put(String.valueOf(Messages.ValueColumnLabel), getQuarkValue(fetchParameters, ss, quark));
    return new TmfModelResponse<>(tooltip, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 19 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse 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)

Example 20 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class ResourcesStatusDataProvider method fetchTooltip.

@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ITmfStateSystem ss = getAnalysisModule().getStateSystem();
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Collection<@NonNull Integer> quarks = getSelectedEntries(filter).values();
    boolean isACopy = false;
    if (quarks.size() != 1) {
        Map<Long, Integer> selectedEntries = new HashMap<>();
        for (Long selectedItem : filter.getSelectedItems()) {
            Integer quark = fTwinIdsToQuark.get(selectedItem);
            if (quark != null && quark >= 0) {
                selectedEntries.put(selectedItem, quark);
                isACopy = true;
            }
        }
        quarks = selectedEntries.values();
    }
    long start = filter.getStart();
    if (ss == null || quarks.size() != 1 || !getAnalysisModule().isQueryable(start)) {
        /*
             * We need the ss to query, we should only be querying one attribute and the
             * query times should be valid.
             */
        return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    int quark = quarks.iterator().next();
    // assert that it is a CPU quark
    String attributeName = ss.getAttributeName(quark);
    Integer cpuNumber = Ints.tryParse(attributeName);
    String parent = ss.getAttributeName(ss.getParentAttributeQuark(quark));
    if (cpuNumber == null && !(attributeName.equals(Attributes.CURRENT_THREAD) || attributeName.equals(Attributes.CURRENT_FREQUENCY))) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    try {
        Map<String, String> retMap = new LinkedHashMap<>(1);
        List<ITmfStateInterval> full = ss.queryFullState(start);
        Object object = full.get(quark).getValue();
        if (object instanceof Integer) {
            int status = (int) object;
            if (isACopy) {
                retMap.put(parent.equals(Attributes.IRQS) ? Messages.ResourcesStatusDataProvider_attributeIrqName : Messages.ResourcesStatusDataProvider_attributeSoftIrqName, attributeName);
            } else if (parent.equals(Attributes.IRQS) || parent.equals(Attributes.SOFT_IRQS)) {
                putCpus(ss, quark, retMap, full, parent, status);
            } else if (status == StateValues.CPU_STATUS_IRQ) {
                putIrq(ss, attributeName, retMap, full, Attributes.IRQS, status);
            } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
                putIrq(ss, attributeName, retMap, full, Attributes.SOFT_IRQS, status);
            } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL) {
                putCpuTooltip(ss, attributeName, retMap, full, status);
            } else if (attributeName.equals(Attributes.CURRENT_THREAD)) {
                putCurrentThreadTooltip(ss, retMap, full, status);
            }
        } else if (object instanceof Long && attributeName.equals(Attributes.CURRENT_FREQUENCY)) {
            // $NON-NLS-1$
            retMap.put("Frequency", FREQUENCY_FORMATTER.format(object));
        }
        return new TmfModelResponse<>(retMap, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    } catch (StateSystemDisposedException e) {
    }
    return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) LinkedHashMap(java.util.LinkedHashMap) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)44 ArrayList (java.util.ArrayList)23 NonNull (org.eclipse.jdt.annotation.NonNull)21 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)21 HashMap (java.util.HashMap)16 AtomicLong (java.util.concurrent.atomic.AtomicLong)14 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)14 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)10 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)9 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)9 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)9 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)8 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)6 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)6