Search in sources :

Example 1 with TimeQueryFilter

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

the class CPUAnalysisBenchmark method benchmarkCPUModule.

@SuppressWarnings("restriction")
private static void benchmarkCPUModule(String testName, @NonNull LttngKernelTrace trace, int loopCount) throws TmfAnalysisException {
    Performance perf = Performance.getDefault();
    PerformanceMeter pmAnalysisExecution = perf.createPerformanceMeter(TEST_ID + testName + ": " + TEST_ANALYSIS_EXECUTION);
    perf.tagAsSummary(pmAnalysisExecution, TEST_ANALYSIS_EXECUTION + '(' + testName + ')', Dimension.CPU_TIME);
    PerformanceMeter pmQueryUsage = perf.createPerformanceMeter(TEST_ID + testName + ": " + TEST_ANALYSIS_QUERY);
    perf.tagAsSummary(pmQueryUsage, TEST_ANALYSIS_QUERY + '(' + testName + ')', Dimension.CPU_TIME);
    for (int i = 0; i < loopCount; i++) {
        KernelCpuUsageAnalysis module = getModule(trace);
        try {
            pmAnalysisExecution.start();
            TmfTestHelper.executeAnalysis(module);
            pmAnalysisExecution.stop();
            CpuUsageDataProvider dataProvider = CpuUsageDataProvider.create(trace);
            assertNotNull(dataProvider);
            // Query all CPU Usage for full time range, then 10 times 10%
            // smaller ranges
            int resolution = 1500;
            long startTime = trace.getStartTime().toNanos();
            long endTime = trace.getEndTime().toNanos();
            pmQueryUsage.start();
            for (int j = 0; j < 10; j++) {
                // Query the tree for that range
                TimeQueryFilter filter = new SelectedCpuQueryFilter(startTime, endTime, 2, Collections.emptyList(), Collections.emptySet());
                @NonNull Map<@NonNull String, @NonNull Object> parameters = new HashMap<>();
                parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
                parameters.put(DataProviderParameterUtils.REQUESTED_ITEMS_KEY, Collections.emptyList());
                parameters.put("cpus", Collections.emptySet());
                TmfModelResponse<@NonNull TmfTreeModel<@NonNull CpuUsageEntryModel>> response = dataProvider.fetchTree(parameters, NULL_MONITOR);
                TmfTreeModel<@NonNull CpuUsageEntryModel> model = response.getModel();
                assertNotNull(model);
                List<CpuUsageEntryModel> entries = model.getEntries();
                assertNotNull(entries);
                // Add all entries to the list of selected
                List<Long> selected = new ArrayList<>();
                for (CpuUsageEntryModel entry : entries) {
                    selected.add(entry.getId());
                }
                // Get the usage for all threads
                filter = new SelectedCpuQueryFilter(startTime, endTime, resolution, selected, Collections.emptySet());
                parameters = new HashMap<>();
                parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
                parameters.put(DataProviderParameterUtils.REQUESTED_ITEMS_KEY, selected);
                parameters.put("cpus", Collections.emptySet());
                TmfModelResponse<@NonNull ITmfXyModel> fetchXY = dataProvider.fetchXY(parameters, NULL_MONITOR);
                ITmfXyModel model2 = fetchXY.getModel();
                assertNotNull(model2);
                // Reduce the time range
                long step = (endTime - startTime) / 20;
                startTime += step;
                endTime -= step;
            }
            pmQueryUsage.stop();
        } finally {
            module.dispose();
        }
    }
    pmAnalysisExecution.commit();
    pmQueryUsage.commit();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KernelCpuUsageAnalysis(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis) SelectedCpuQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter) CpuUsageDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider) NonNull(org.eclipse.jdt.annotation.NonNull) PerformanceMeter(org.eclipse.test.performance.PerformanceMeter) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Performance(org.eclipse.test.performance.Performance) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 2 with TimeQueryFilter

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

the class XmlXyDataProviderTest method assertAndGetTree.

private static Map<Long, String> assertAndGetTree(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, ITmfTrace trace, List<String> expectedStrings) {
    TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> treeResponse = xyProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), MONITOR);
    assertNotNull(treeResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
    TmfTreeModel<@NonNull ITmfTreeDataModel> treeModel = treeResponse.getModel();
    assertNotNull(treeModel);
    List<@NonNull ITmfTreeDataModel> treeEntries = treeModel.getEntries();
    Map<Long, String> map = new HashMap<>();
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        assertTrue("actual entry absent at " + i + ": " + expectedString, treeEntries.size() > i);
        String[] split = expectedString.split(",");
        ITmfTreeDataModel xmlXyEntry = treeEntries.get(i);
        assertEquals("Checking entry name at " + i, split[0], xmlXyEntry.getName());
        // Check the parent
        long parentId = xmlXyEntry.getParentId();
        if (parentId < 0) {
            assertEquals("Checking empty parent at " + i, split[1], "null");
        } else {
            String parentName = map.get(parentId);
            assertEquals("Checking parent at " + i, split[1], parentName);
        }
        map.put(xmlXyEntry.getId(), xmlXyEntry.getName());
    }
    assertEquals("Extra actual entries", expectedStrings.size(), treeEntries.size());
    return map;
}
Also used : HashMap(java.util.HashMap) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 3 with TimeQueryFilter

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

the class XmlXYDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    DataDrivenStateSystemPath display = fDisplay;
    XmlXYEntry entry = fXmlEntry;
    ITmfStateSystem ss = entry.getStateSystem();
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long[] xValues = filter.getTimesRequested();
    Map<Integer, IYModel> map = initSeries(fetchParameters);
    if (map.isEmpty()) {
        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<Integer, IYModel> series : map.entrySet()) {
                    int attributeQuark = display.getQuark(series.getKey(), entry);
                    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<Integer, IYModel> series : map.entrySet()) {
            if (entry.getType().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, map.values(), complete);
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) 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 4 with TimeQueryFilter

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

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

Aggregations

TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)28 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)16 NonNull (org.eclipse.jdt.annotation.NonNull)14 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)14 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)3 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)3 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)3 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)3 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)3