Search in sources :

Example 1 with YModel

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

the class CounterDataProvider method internalFetch.

@Nullable
private Collection<IYModel> internalFetch(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    SelectedCounterQueryFilter filter = createCounterQuery(fetchParameters);
    if (filter == null) {
        return null;
    }
    long stateSystemEndTime = ss.getCurrentEndTime();
    Collection<Long> times = extractRequestedTimes(ss, filter, stateSystemEndTime);
    Map<Long, Integer> entries = Maps.filterValues(getSelectedEntries(filter), q -> ss.getSubAttributes(q, false).isEmpty());
    TreeMultimap<Integer, ITmfStateInterval> countersIntervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparingLong(ITmfStateInterval::getStartTime));
    Iterable<@NonNull ITmfStateInterval> query2d = ss.query2D(entries.values(), times);
    for (ITmfStateInterval interval : query2d) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        countersIntervals.put(interval.getAttribute(), interval);
    }
    ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
    for (Entry<Long, Integer> entry : entries.entrySet()) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        int quark = entry.getValue();
        double[] yValues = buildYValues(countersIntervals.get(quark), filter);
        String seriesName = getTrace().getName() + '/' + ss.getFullAttributePath(quark);
        ySeries.add(new YModel(entry.getKey(), seriesName, yValues));
    }
    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) SelectedCounterQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCounterQueryFilter) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with YModel

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

the class UstMemoryUsageDataProvider method initYModels.

/**
 * Get map of UST_MEMORY_MEMORY_ATTRIBUTE to relevant model
 *
 * @param ss
 *            the queried {@link ITmfStateSystem}
 * @param filter
 *            the {@link TimeQueryFilter}
 * @return a map of the UST_MEMORY_MEMORY_ATTRIBUTE attributes to the
 *         initialized model
 */
private Map<Integer, IYModel> initYModels(ITmfStateSystem ss, SelectionTimeQueryFilter filter) {
    Map<Integer, IYModel> selectedSeries = new HashMap<>();
    int length = filter.getTimesRequested().length;
    for (Entry<Long, Integer> entry : getSelectedEntries(filter).entrySet()) {
        int tidQuark = entry.getValue();
        int memoryAttribute = ss.optQuarkRelative(tidQuark, UstMemoryStrings.UST_MEMORY_MEMORY_ATTRIBUTE);
        if (memoryAttribute != ITmfStateSystem.INVALID_ATTRIBUTE) {
            String name = getTrace().getName() + ':' + ss.getAttributeName(tidQuark);
            selectedSeries.put(memoryAttribute, new YModel(entry.getKey(), name, new double[length]));
        }
    }
    return selectedSeries;
}
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 3 with YModel

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

the class XmlXYDataProvider method initSeries.

private Map<Integer, IYModel> initSeries(Map<String, Object> parameters) {
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(parameters);
    if (filter == null) {
        return Collections.emptyMap();
    }
    fLock.readLock().lock();
    try {
        Map<Integer, IYModel> map = new HashMap<>();
        int length = filter.getTimesRequested().length;
        for (Long id : filter.getSelectedItems()) {
            Integer quark = fIdToQuark.get(id);
            if (quark != null) {
                String name = String.valueOf(fQuarkToString.get(quark));
                map.put(quark, 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)

Example 4 with YModel

use of org.eclipse.tracecompass.tmf.core.model.YModel 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 5 with YModel

use of org.eclipse.tracecompass.tmf.core.model.YModel 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

YModel (org.eclipse.tracecompass.tmf.core.model.YModel)11 IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)11 HashMap (java.util.HashMap)6 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)5 ImmutableList (com.google.common.collect.ImmutableList)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)4 Nullable (org.eclipse.jdt.annotation.Nullable)3 ArrayList (java.util.ArrayList)2 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)2 TmfCommonXAxisModel (org.eclipse.tracecompass.tmf.core.model.TmfCommonXAxisModel)2 LinkedHashMap (java.util.LinkedHashMap)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)1 SelectedCounterQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectedCounterQueryFilter)1 SelectedCpuQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1 ITmfStatistics (org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics)1