Search in sources :

Example 11 with IYModel

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

the class KernelMemoryUsageDataProvider method getYSeriesModels.

/**
 * @since 2.5
 */
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return null;
    }
    long[] xValues = filter.getTimesRequested();
    long currentEnd = ss.getCurrentEndTime();
    /**
     * For a given time range, we plot lines representing the memory allocation for
     * the total and the selected entries.
     */
    double[] totalKernelMemoryValues = new double[xValues.length];
    Map<Integer, IYModel> selectedSeries = initSeries(ss, filter);
    List<Integer> threadQuarkList = ss.getSubAttributes(-1, false);
    if (threadQuarkList.isEmpty()) {
        return Collections.emptyList();
    }
    Collection<Long> times = getTimes(filter, ss.getStartTime(), currentEnd);
    for (ITmfStateInterval interval : ss.query2D(threadQuarkList, times)) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        Object object = interval.getValue();
        if (object instanceof Number) {
            double value = ((Number) object).doubleValue();
            int from = Arrays.binarySearch(xValues, interval.getStartTime());
            from = (from >= 0) ? from : -1 - from;
            int to = Arrays.binarySearch(xValues, from, xValues.length, interval.getEndTime());
            to = (to >= 0) ? to + 1 : -1 - to;
            /* We add the value of each thread to the total quantity */
            for (int i = from; i < to; i++) {
                totalKernelMemoryValues[i] += value;
            }
            IYModel selectedThreadValues = selectedSeries.get(interval.getAttribute());
            if (selectedThreadValues != null) {
                Arrays.fill(selectedThreadValues.getData(), from, to, value);
            }
        }
    }
    /**
     * We shift the series up.
     */
    List<ITmfStateInterval> endState = ss.queryFullState(Long.min(filter.getEnd(), currentEnd));
    double d = extractTotalValueShift(ss, endState);
    Arrays.setAll(totalKernelMemoryValues, i -> totalKernelMemoryValues[i] + d);
    for (Entry<Integer, IYModel> entry : selectedSeries.entrySet()) {
        int lowestMemoryQuark = ss.optQuarkRelative(entry.getKey(), KernelMemoryAnalysisModule.THREAD_LOWEST_MEMORY_VALUE);
        if (lowestMemoryQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
            Object value = endState.get(lowestMemoryQuark).getValue();
            if (value instanceof Number) {
                double[] threadValues = entry.getValue().getData();
                double shift = ((Number) value).doubleValue();
                Arrays.setAll(threadValues, i -> threadValues[i] - shift);
            }
        }
    }
    ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
    String total = getTrace().getName() + MemoryUsageTreeModel.TOTAL_SUFFIX;
    ySeries.add(new YModel(getId(ITmfStateSystem.ROOT_ATTRIBUTE), total, totalKernelMemoryValues));
    ySeries.addAll(selectedSeries.values());
    return ySeries.build();
}
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) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 12 with IYModel

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

the class KernelMemoryUsageDataProvider method initSeries.

/**
 * Initialize a map of quark to primitive double array
 *
 * @param filter
 *            the query object
 * @return a Map of quarks for the entries which exist for this provider to
 *         newly initialized primitive double arrays of the same length as the
 *         number of requested timestamps.
 */
private Map<Integer, IYModel> initSeries(ITmfStateSystem ss, SelectionTimeQueryFilter filter) {
    int length = filter.getTimesRequested().length;
    Map<Integer, IYModel> map = new HashMap<>();
    for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
        String selectedThreadName = getTrace().getName() + ':' + ss.getAttributeName(entry.getValue());
        map.put(entry.getValue(), new YModel(entry.getKey(), selectedThreadName, new double[length]));
    }
    return map;
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) HashMap(java.util.HashMap) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel)

Example 13 with IYModel

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

the class XYDataProviderBaseTest method extractModelFromChart.

/**
 * From a SWT Chart, this method extract a {@link TmfCommonXAxisModel} that
 * represents the chart. Since, we unfortunately have no mecanism to deserialize
 * with GSON, we have to compare strings. So, once the model is extract from the
 * Chart, we serialize it and compare with a string
 *
 * @param chart
 *            A SWT Chart
 * @param otherSeries
 *            Name of other series to extract from Chart
 * @return A {@link TmfCommonXAxisModel}
 */
protected TmfCommonXAxisModel extractModelFromChart(final Chart chart, String... otherSeries) {
    String mainSeriesName = getMainSeriesName();
    ISeries<Integer> mainSeries = chart.getSeriesSet().getSeries(mainSeriesName);
    if (mainSeries == null) {
        System.out.println("Main Series " + mainSeriesName + " not found in chart");
        return null;
    }
    /* X and Y Values shown in chart */
    double[] xMain = getXSeries(mainSeries);
    double[] yMain = getYSeries(mainSeries);
    Map<@NonNull String, @NonNull IYModel> yModels = new LinkedHashMap<>();
    yModels.put(mainSeriesName, new YModel(-1, mainSeriesName, Objects.requireNonNull(yMain)));
    for (String other : otherSeries) {
        if (other != null) {
            ISeries<Integer> series = chart.getSeriesSet().getSeries(other);
            if (series == null) {
                System.out.println("Series " + other + " not found in chart");
                return null;
            }
            /* X and Y Values shown in chart */
            double[] xSeries = getXSeries(series);
            double[] ySeries = getYSeries(series);
            /* Series should have the same x axis values, not finished updating all series*/
            if (!Arrays.equals(xMain, xSeries)) {
                System.out.println("Series don't currently have the same x axis values");
                return null;
            }
            yModels.put(other, new YModel(-1, other, Objects.requireNonNull(ySeries)));
        }
    }
    long[] x = Longs.toArray(Doubles.asList(xMain));
    assertNotNull(x);
    return new TmfCommonXAxisModel(getTitle(), x, yModels.values());
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) YModel(org.eclipse.tracecompass.tmf.core.model.YModel) TmfCommonXAxisModel(org.eclipse.tracecompass.tmf.core.model.TmfCommonXAxisModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with IYModel

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

the class ExampleXYDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ITmfStateSystem ss = getAnalysisModule().getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    Map<Integer, double[]> quarkToValues = 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();
    }
    List<Long> times = getTimes(ss, DataProviderParameterUtils.extractTimeRequested(fetchParameters));
    for (Long id : selectedItems) {
        Integer quark = fIDToDisplayQuark.get(id);
        if (quark != null) {
            quarkToValues.put(quark, new double[times.size()]);
        }
    }
    long[] nativeTimes = new long[times.size()];
    for (int i = 0; i < times.size(); i++) {
        nativeTimes[i] = times.get(i);
    }
    // Query the state system to fill the array of values
    try {
        for (ITmfStateInterval interval : ss.query2D(quarkToValues.keySet(), times)) {
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
            double[] row = quarkToValues.get(interval.getAttribute());
            Object value = interval.getValue();
            if (row != null && (value instanceof Number)) {
                Double dblValue = ((Number) value).doubleValue();
                for (int i = 0; i < times.size(); i++) {
                    Long time = times.get(i);
                    if (interval.getStartTime() <= time && interval.getEndTime() >= time) {
                        row[i] = dblValue;
                    }
                }
            }
        }
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    List<IYModel> models = new ArrayList<>();
    for (Entry<Integer, double[]> values : quarkToValues.entrySet()) {
        models.add(new YModel(fIDToDisplayQuark.inverse().getOrDefault(values.getKey(), -1L), values.getValue()));
    }
    // $NON-NLS-1$
    return new TmfModelResponse<>(new TmfCommonXAxisModel("Example XY data provider", nativeTimes, models), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) HashMap(java.util.HashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TmfCommonXAxisModel(org.eclipse.tracecompass.tmf.core.model.TmfCommonXAxisModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 15 with IYModel

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

the class DataDrivenXYDataProvider method initSeries.

private Map<DisplayElement, IYModel> initSeries(TimeQueryFilter filter) {
    if (!(filter instanceof SelectionTimeQueryFilter)) {
        return Collections.emptyMap();
    }
    fLock.readLock().lock();
    try {
        Map<DisplayElement, IYModel> map = new HashMap<>();
        int length = filter.getTimesRequested().length;
        for (Long id : ((SelectionTimeQueryFilter) filter).getSelectedItems()) {
            DisplayElement displayElement = fIDToDisplayQuark.get(id);
            if (displayElement != null) {
                String name = String.valueOf(fIdToTitle.get(id));
                map.put(displayElement, new YModel(id, name, new double[length]));
            }
        }
        return map;
    } finally {
        fLock.readLock().unlock();
    }
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel)

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