Search in sources :

Example 1 with ISeriesModel

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

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

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

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

Example 5 with ISeriesModel

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

the class SegmentStoreScatterDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ISegmentStoreProvider provider = fProvider;
    // segment store is available.
    if ((provider instanceof IAnalysisModule) && !((IAnalysisModule) provider).waitForCompletion()) {
        return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    final ISegmentStore<ISegment> segStore = provider.getSegmentStore();
    if (segStore == null) {
        return TmfXyResponseFactory.createFailedResponse(Objects.requireNonNull(Messages.SegmentStoreDataProvider_SegmentNotAvailable));
    }
    // 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.
    TimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        filter = FetchParametersUtils.createTimeQuery(fetchParameters);
        if (filter == null) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
        }
    }
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(fetchParameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    long start = filter.getStart();
    long end = filter.getEnd();
    // The types in the tree do not contain the trace name for sake of readability,
    // but
    // the name of the series in XY model should be unique per trace
    String prefix = getTrace().getName() + '/';
    Map<String, Series> types = initTypes(prefix, filter);
    if (types.isEmpty()) {
        // this would return an empty map even if we did the queries.
        return TmfXyResponseFactory.create(Objects.requireNonNull(Messages.SegmentStoreScatterGraphViewer_title), Collections.emptyList(), true);
    }
    long pixelSize = Math.max(1, (end - start) / filter.getTimesRequested().length);
    final Iterable<ISegment> intersectingElements = Iterables.filter(segStore.getIntersectingElements(start, end, SegmentComparators.INTERVAL_START_COMPARATOR), (segment) -> {
        CheckSegmentType cs = new CheckSegmentType(prefix, types.keySet());
        return cs.test(segment);
    });
    final Iterable<ISegment> displayData = compactList(start, intersectingElements, pixelSize);
    IAnalysisModule module = (fProvider instanceof IAnalysisModule) ? (IAnalysisModule) fProvider : null;
    boolean complete = module == null ? true : module.isQueryable(filter.getEnd());
    // For each visible segments, add start time to x value and duration for y value
    for (ISegment segment : displayData) {
        if (monitor != null && monitor.isCanceled()) {
            return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
        }
        String name = prefix + getSegmentName(segment);
        Series thisSeries = types.get(name);
        if (thisSeries == null) {
            // This shouldn't be, log an error and continue
            // $NON-NLS-1$//$NON-NLS-2$
            Activator.getInstance().logError("Series " + thisSeries + " should exist");
            continue;
        }
        addPoint(thisSeries, segment, predicates, monitor);
    }
    List<ISeriesModel> seriesModelMap = new ArrayList<>();
    for (Entry<String, Series> entry : types.entrySet()) {
        SeriesModel seriesModel = entry.getValue().build();
        seriesModelMap.add(seriesModel);
    }
    return TmfXyResponseFactory.create(Objects.requireNonNull(Messages.SegmentStoreScatterGraphViewer_title), seriesModelMap, complete);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) SeriesModel(org.eclipse.tracecompass.tmf.core.model.SeriesModel) Predicate(java.util.function.Predicate) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) NonNull(org.eclipse.jdt.annotation.NonNull) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Aggregations

ISeriesModel (org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel)5 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)4 NonNull (org.eclipse.jdt.annotation.NonNull)2 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)2 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)2 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Predicate (java.util.function.Predicate)1 DiskActivity (org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.inputoutput.IoTestCase.DiskActivity)1 ISegmentStoreProvider (org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider)1 DisksIODataProvider (org.eclipse.tracecompass.internal.analysis.os.linux.core.inputoutput.DisksIODataProvider)1 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)1 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)1 SeriesModel (org.eclipse.tracecompass.tmf.core.model.SeriesModel)1 SeriesModelBuilder (org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder)1 TmfXyModel (org.eclipse.tracecompass.tmf.core.model.TmfXyModel)1 TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)1 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)1