Search in sources :

Example 6 with IYModel

use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.

the class DataDrivenXYDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long[] xValues = filter.getTimesRequested();
    filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    Map<DisplayElement, IYModel> map = initSeries(filter);
    if (map.isEmpty()) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    ITmfStateSystem ss = null;
    for (DisplayElement de : map.keySet()) {
        ss = de.fStateSystem;
    }
    if (ss == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    long currentEnd = ss.getCurrentEndTime();
    try {
        for (int i = 0; i < xValues.length; i++) {
            if (monitor != null && monitor.isCanceled()) {
                return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
            }
            long time = xValues[i];
            if (time > currentEnd) {
                break;
            } else if (ss.getStartTime() <= time) {
                List<@NonNull ITmfStateInterval> full = ss.queryFullState(time);
                for (Entry<DisplayElement, IYModel> series : map.entrySet()) {
                    int attributeQuark = series.getKey().fQuark;
                    if (attributeQuark >= 0 && attributeQuark < full.size()) {
                        Object value = full.get(attributeQuark).getValue();
                        series.getValue().getData()[i] = extractValue(value);
                    }
                }
            }
        }
        // Update the series value if delta is requested
        for (Entry<DisplayElement, IYModel> series : map.entrySet()) {
            if (series.getKey().fDisplayType.equals(DisplayType.DELTA)) {
                getSeriesDelta(series.getValue().getData());
            }
        }
    } catch (StateSystemDisposedException e) {
        return TmfXyResponseFactory.createFailedResponse(e.getMessage());
    }
    boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
    return TmfXyResponseFactory.create(TITLE, xValues, ImmutableList.copyOf(map.values()), complete);
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 7 with IYModel

use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.

the class HistogramDataProvider method fetchXY.

@Override
@NonNull
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fModule.waitForInitialization();
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    long[] xValues = new long[0];
    if (filter == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    xValues = filter.getTimesRequested();
    Collection<Long> selected = filter.getSelectedItems();
    int n = xValues.length;
    ImmutableList.Builder<IYModel> builder = ImmutableList.builder();
    final ITmfStatistics stats = Objects.requireNonNull(fModule.getStatistics());
    if (selected.contains(fTotalId)) {
        List<Long> values = stats.histogramQuery(filter.getTimesRequested());
        double[] y = new double[n];
        Arrays.setAll(y, values::get);
        String totalName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Total;
        builder.add(new YModel(fTotalId, totalName, y));
    }
    ITmfStateSystem eventsSs = fModule.getStateSystem(TmfStatisticsEventTypesModule.ID);
    if (selected.contains(fLostId) && eventsSs != null) {
        try {
            YModel series = getLostEvents(eventsSs, xValues);
            builder.add(series);
        } catch (StateSystemDisposedException e) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.STATE_SYSTEM_FAILED);
        }
    }
    boolean completed = eventsSs != null ? eventsSs.waitUntilBuilt(0) || eventsSs.getCurrentEndTime() >= filter.getEnd() : false;
    return TmfXyResponseFactory.create(TITLE, xValues, builder.build(), completed);
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) ImmutableList(com.google.common.collect.ImmutableList) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 8 with IYModel

use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.

the class AbstractTreeCommonXDataProvider method fetchXY.

@Override
public final TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    A module = getAnalysisModule();
    // 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 TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    TmfModelResponse<ITmfXyModel> res = verifyParameters(module, filter, monitor);
    if (res != null) {
        return res;
    }
    ITmfStateSystem ss = Objects.requireNonNull(module.getStateSystem(), // $NON-NLS-1$
    "Statesystem should have been verified by verifyParameters");
    long currentEnd = ss.getCurrentEndTime();
    boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
    try (FlowScopeLog scope = // $NON-NLS-1$
    new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeXyDataProvider#fetchXY").setCategory(getClass().getSimpleName()).build()) {
        Collection<IYModel> yModels = getYSeriesModels(ss, fetchParameters, monitor);
        if (yModels == null) {
            // getModels returns null if the query was cancelled.
            return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
        }
        return TmfXyResponseFactory.create(getTitle(), filter.getTimesRequested(), ImmutableList.copyOf(yModels), complete);
    } catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
        return TmfXyResponseFactory.createFailedResponse(String.valueOf(e.getMessage()));
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 9 with IYModel

use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel 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 10 with IYModel

use of org.eclipse.tracecompass.tmf.core.model.xy.IYModel in project tracecompass by tracecompass.

the class CpuUsageDataProvider method getYSeriesModels.

/**
 * @since 2.5
 */
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Set<Integer> cpus = Collections.emptySet();
    SelectionTimeQueryFilter filter = createCpuQuery(fetchParameters);
    if (filter == null) {
        filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
        if (filter == null) {
            return null;
        }
    }
    if (filter instanceof SelectedCpuQueryFilter) {
        cpus = ((SelectedCpuQueryFilter) filter).getSelectedCpus();
    }
    long[] xValues = filter.getTimesRequested();
    /* CPU usage values for total and selected thread */
    double[] totalValues = new double[xValues.length];
    Map<String, IYModel> selectedThreadValues = new HashMap<>();
    for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
        String name = Integer.toString(entry.getValue());
        selectedThreadValues.put(name, new YModel(entry.getKey(), getTrace().getName() + ':' + name, new double[xValues.length]));
    }
    long prevTime = Math.max(getInitialPrevTime(filter), ss.getStartTime());
    long currentEnd = ss.getCurrentEndTime();
    for (int i = 0; i < xValues.length; i++) {
        long time = xValues[i];
        if (time < ss.getStartTime() || time > currentEnd) {
            /* Leave empty if time xValue is out of bounds */
            prevTime = time;
            continue;
        }
        if (prevTime < time) {
            Map<String, Long> cpuUsageMap = Maps.filterKeys(getAnalysisModule().getCpuUsageInRange(cpus, prevTime, time), key -> key.startsWith(KernelCpuUsageAnalysis.TOTAL));
            /*
                 * Calculate the sum of all total entries, and add a data point to the selected
                 * one
                 */
            long totalCpu = 0;
            for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
                String threadName = extractThreadName(entry.getKey());
                if (threadName != null) {
                    long cpuTime = entry.getValue();
                    totalCpu += cpuTime;
                    IYModel values = selectedThreadValues.get(threadName);
                    if (values != null) {
                        values.getData()[i] = normalize(prevTime, time, cpuTime);
                    }
                }
            }
            totalValues[i] = normalize(prevTime, time, totalCpu);
        } else if (i > 0) {
            /* In case of duplicate time xValue copy previous yValues */
            for (IYModel values : selectedThreadValues.values()) {
                values.getData()[i] = values.getData()[i - 1];
            }
            totalValues[i] = totalValues[i - 1];
        }
        prevTime = time;
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
    }
    ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
    String key = TOTAL + getTrace().getName();
    ySeries.add(new YModel(getId(ITmfStateSystem.ROOT_ATTRIBUTE), key, totalValues));
    for (IYModel entry : selectedThreadValues.values()) {
        ySeries.add(entry);
    }
    return ySeries.build();
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) SelectedCpuQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)15 YModel (org.eclipse.tracecompass.tmf.core.model.YModel)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)9 ImmutableList (com.google.common.collect.ImmutableList)7 HashMap (java.util.HashMap)6 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)5 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Nullable (org.eclipse.jdt.annotation.Nullable)4 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)4 ArrayList (java.util.ArrayList)3 NonNull (org.eclipse.jdt.annotation.NonNull)3 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)2 TmfCommonXAxisModel (org.eclipse.tracecompass.tmf.core.model.TmfCommonXAxisModel)2 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)2 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)2 LinkedHashMap (java.util.LinkedHashMap)1