Search in sources :

Example 1 with ITmfXyModel

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

the class InputOutputDataProviderTest method testDiskActivity.

/**
 * Test the data provider
 */
@Test
public void testDiskActivity() {
    DisksIODataProvider provider = getProvider();
    Collection<@NonNull DiskActivity> diskActivity = fTestCase.getDiskActivity();
    for (DiskActivity test : diskActivity) {
        Map<@NonNull String, @NonNull Object> parameters = test.getTimeQuery();
        TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> response = provider.fetchTree(parameters, PROGRESS_MONITOR);
        assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus());
        TmfTreeModel<@NonNull TmfTreeDataModel> model = response.getModel();
        assertNotNull(model);
        parameters = test.getTimeQueryForModel(model);
        TmfModelResponse<@NonNull ITmfXyModel> yResponse = provider.fetchXY(parameters, PROGRESS_MONITOR);
        assertEquals(ITmfResponse.Status.COMPLETED, yResponse.getStatus());
        ITmfXyModel yModel = yResponse.getModel();
        assertNotNull(yModel);
        Collection<@NonNull ISeriesModel> data = yModel.getSeriesData();
        assertEquals(1, data.size());
        ISeriesModel ySeries = data.iterator().next();
        double[] expected = test.getActivity();
        double[] actual = ySeries.getData();
        for (int i = 0; i < expected.length; i++) {
            assertTrue(String.format("No actual value at position %d for %s", i, test), actual.length > i);
            assertEquals(String.format("Value at position %d for %s", i, test), expected[i], actual[i], 0.001);
        }
        assertEquals(String.format("More values than expected for %s", test), expected.length, actual.length);
    }
}
Also used : ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) DisksIODataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.inputoutput.DisksIODataProvider) DiskActivity(org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.inputoutput.IoTestCase.DiskActivity) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) Test(org.junit.Test)

Example 2 with ITmfXyModel

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

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

the class XmlXyDataProviderTest method assertRows.

private static void assertRows(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, Map<Long, String> tree, List<String> expectedStrings) {
    TmfModelResponse<@NonNull ITmfXyModel> rowResponse = xyProvider.fetchXY(FetchParametersUtils.selectionTimeQueryToMap(new SelectionTimeQueryFilter(1, 20, 20, tree.keySet())), null);
    assertNotNull(rowResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, rowResponse.getStatus());
    ITmfXyModel rowModel = rowResponse.getModel();
    assertNotNull(rowModel);
    Collection<@NonNull ISeriesModel> series = rowModel.getSeriesData();
    ImmutableMap<Long, @NonNull ISeriesModel> data = Maps.uniqueIndex(series, ISeriesModel::getId);
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        String[] split = expectedString.split(":");
        String rowName = split[0];
        Long rowId = null;
        for (Entry<Long, String> entry : tree.entrySet()) {
            if (entry.getValue().equals(rowName)) {
                rowId = entry.getKey();
                break;
            }
        }
        assertNotNull(rowId);
        ISeriesModel row = data.get(rowId);
        assertNotNull(row);
        String[] expectedData = split[1].split(",");
        double[] actualData = row.getData();
        for (int j = 0; j < expectedData.length; j++) {
            assertTrue("Presence of data at position " + j + " for row " + rowName, actualData.length > j);
            double expectedValue = Double.parseDouble(expectedData[j]);
            assertEquals("Data at position " + j + " for row " + rowName, expectedValue, actualData[j], 0.001);
        }
    }
    assertEquals("Same number of data", expectedStrings.size(), data.size());
}
Also used : ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 4 with ITmfXyModel

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

the class TmfXyResponseFactory method create.

/**
 * Create a {@link TmfModelResponse} for values with a common X axis values,
 * with a either RUNNING or COMPLETED status. Model is not null, it's either
 * partial or full.
 *
 * @param title
 *            Chart title
 * @param xValues
 *            The x values requested by the viewer
 * @param yModels
 *            Collection of IYModel
 * @param isComplete
 *            Tells whether the computed model is complete or partial
 * @return A {@link TmfModelResponse} with either a running status or a
 *         completed status
 */
public static TmfModelResponse<ITmfXyModel> create(String title, long[] xValues, Collection<IYModel> yModels, boolean isComplete) {
    List<ISeriesModel> series = Lists.transform(new ArrayList<>(yModels), model -> {
        SeriesModelBuilder builder = new SeriesModelBuilder(model.getId(), model.getName(), xValues, model.getData());
        TmfXYAxisDescription yAxis = model.getYAxisDescription();
        if (yAxis != null) {
            builder.yAxisDescription(yAxis);
        }
        return builder.build();
    });
    ITmfXyModel model = new TmfXyModel(title, series);
    if (isComplete) {
        return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, Objects.requireNonNull(CommonStatusMessage.COMPLETED));
    }
    return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, Objects.requireNonNull(CommonStatusMessage.RUNNING));
}
Also used : ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) TmfXYAxisDescription(org.eclipse.tracecompass.tmf.core.model.xy.TmfXYAxisDescription) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SeriesModelBuilder(org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) TmfXyModel(org.eclipse.tracecompass.tmf.core.model.TmfXyModel) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 5 with ITmfXyModel

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

Aggregations

ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)7 ISeriesModel (org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)3 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)3 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)3 TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)2 IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)2 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Performance (org.eclipse.test.performance.Performance)1 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)1 CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)1 KernelCpuUsageAnalysis (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis)1 DiskActivity (org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.inputoutput.IoTestCase.DiskActivity)1 FlowScopeLog (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog)1 FlowScopeLogBuilder (org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder)1