Search in sources :

Example 11 with SelectionTimeQueryFilter

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

the class ThreadStatusDataProviderTest method assertRows.

private static void assertRows(ThreadStatusDataProvider provider, Map<Long, String> idsToNames) throws IOException {
    TmfModelResponse<TimeGraphModel> rowResponse = provider.fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(new SelectionTimeQueryFilter(1, 80, 80, idsToNames.keySet())), null);
    assertNotNull(rowResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, rowResponse.getStatus());
    TimeGraphModel rowModel = rowResponse.getModel();
    assertNotNull(rowModel);
    List<@NonNull ITimeGraphRowModel> rows = rowModel.getRows();
    // ensure row order
    rows.sort(Comparator.comparingLong(ITimeGraphRowModel::getEntryID));
    List<String> expectedStrings = Files.readAllLines(Paths.get("testfiles/kernel_analysis/expectedThreadStatusRows"));
    assertEquals(expectedStrings.size(), rows.size());
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        String[] split = expectedString.split(":");
        ITimeGraphRowModel row = rows.get(i);
        assertEquals(split[0], idsToNames.get(row.getEntryID()));
        assertEqualsStates(split[1], row.getStates(), split[0]);
    }
}
Also used : ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)

Example 12 with SelectionTimeQueryFilter

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

Example 13 with SelectionTimeQueryFilter

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

the class DisksIODataProvider method getYSeriesModels.

@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();
    List<DiskBuilder> builders = initBuilders(ss, filter);
    if (builders.isEmpty()) {
        // this would return an empty map even if we did the queries.
        return Collections.emptyList();
    }
    long currentEnd = ss.getCurrentEndTime();
    long prevTime = filter.getStart();
    if (prevTime >= ss.getStartTime() && prevTime <= currentEnd) {
        // reuse the results from the full query
        List<ITmfStateInterval> states = ss.queryFullState(prevTime);
        for (DiskBuilder entry : builders) {
            entry.setPrevCount(Disk.extractCount(entry.fSectorQuark, ss, states, prevTime));
        }
    }
    for (int i = 1; i < xValues.length; i++) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        long time = xValues[i];
        if (time > currentEnd) {
            break;
        } else if (time >= ss.getStartTime()) {
            // reuse the results from the full query
            List<ITmfStateInterval> states = ss.queryFullState(time);
            for (DiskBuilder entry : builders) {
                double count = Disk.extractCount(entry.fSectorQuark, ss, states, time);
                entry.updateValue(i, count, time - prevTime);
            }
        }
        prevTime = time;
    }
    return ImmutableList.copyOf(Iterables.transform(builders, DiskBuilder::build));
}
Also used : SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 14 with SelectionTimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter 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 15 with SelectionTimeQueryFilter

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

SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)37 NonNull (org.eclipse.jdt.annotation.NonNull)21 HashMap (java.util.HashMap)13 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)12 ITimeGraphRowModel (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel)10 ArrayList (java.util.ArrayList)9 LinkedHashMap (java.util.LinkedHashMap)9 Map (java.util.Map)9 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)7 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)7 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)7 IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)7 Nullable (org.eclipse.jdt.annotation.Nullable)6 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)6 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)6 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)6 ImmutableList (com.google.common.collect.ImmutableList)5 YModel (org.eclipse.tracecompass.tmf.core.model.YModel)5