Search in sources :

Example 16 with TimeQueryFilter

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

the class SegmentStoreScatterDataProvider method fetchTree.

/**
 * @since 4.0
 */
@Override
public TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ISegmentStoreProvider provider = fProvider;
    if (provider instanceof IAnalysisModule) {
        IAnalysisModule module = (IAnalysisModule) provider;
        IProgressMonitor mon = monitor != null ? monitor : new NullProgressMonitor();
        module.waitForCompletion(mon);
        if (mon.isCanceled()) {
            return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
    }
    ISegmentStore<ISegment> segStore = provider.getSegmentStore();
    if (segStore == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long start = filter.getStart();
    long end = filter.getEnd();
    final Iterable<ISegment> intersectingElements = Iterables.filter(segStore.getIntersectingElements(start, end), s -> s.getStart() >= start);
    Map<String, INamedSegment> segmentTypes = new HashMap<>();
    IAnalysisModule module = (provider instanceof IAnalysisModule) ? (IAnalysisModule) provider : null;
    boolean complete = module == null ? true : module.isQueryable(filter.getEnd());
    // Create the list of segment types that will each create a series
    for (INamedSegment segment : Iterables.filter(intersectingElements, INamedSegment.class)) {
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        segmentTypes.put(segment.getName(), segment);
    }
    Builder<TmfTreeDataModel> nodes = new ImmutableList.Builder<>();
    nodes.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(String.valueOf(getTrace().getName()))));
    Map<IGroupingSegmentAspect, Map<String, Long>> names = new HashMap<>();
    for (Entry<String, INamedSegment> series : segmentTypes.entrySet()) {
        long parentId = fTraceId;
        /*
             * Create a tree sorting aspects by "Grouping aspect" much like
             * counter analyses
             */
        for (IGroupingSegmentAspect aspect : fGroupingAspects) {
            names.putIfAbsent(aspect, new HashMap<>());
            Map<String, Long> map = names.get(aspect);
            if (map == null) {
                break;
            }
            String name = String.valueOf(aspect.resolve(series.getValue()));
            String key = GROUP_PREFIX + name;
            Long uniqueId = map.get(key);
            if (uniqueId == null) {
                uniqueId = getUniqueId(key);
                map.put(key, uniqueId);
                nodes.add(new TmfTreeDataModel(uniqueId, parentId, name));
            }
            parentId = uniqueId;
        }
        long seriesId = getUniqueId(series.getKey());
        nodes.add(new TmfTreeDataModel(seriesId, parentId, series.getKey()));
    }
    return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), nodes.build()), complete ? ITmfResponse.Status.COMPLETED : ITmfResponse.Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) SeriesModelBuilder(org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder) Builder(com.google.common.collect.ImmutableList.Builder) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) INamedSegment(org.eclipse.tracecompass.segmentstore.core.segment.interfaces.INamedSegment) IGroupingSegmentAspect(org.eclipse.tracecompass.analysis.timing.core.segmentstore.IGroupingSegmentAspect) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) HashBiMap(com.google.common.collect.HashBiMap)

Example 17 with TimeQueryFilter

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

Example 18 with TimeQueryFilter

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

the class HistogramDataProviderTest method testHelloLost.

/**
 * Test the {@link HistogramDataProvider} with the
 * {@link CtfTestTrace#HELLO_LOST} trace. Ensure that the expected tree and xy
 * models are returned
 *
 * @throws TmfAnalysisException
 *             if the trace is set more that once
 */
@Test
public void testHelloLost() throws TmfAnalysisException {
    CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.HELLO_LOST);
    TmfStatisticsModule module = new TmfStatisticsModule();
    module.setName("Statistics");
    assertTrue("Statistics Analysis should apply to this trace", module.setTrace(trace));
    assertEquals("Statistics Analysis shouls be schedulable", Status.OK_STATUS, module.schedule());
    assertTrue("Statistics Analysis should run successfully", module.waitForCompletion());
    try {
        HistogramDataProvider provider = new HistogramDataProvider(trace, module);
        TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> treeResponse = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(START, END, 2)), null);
        assertEquals("Response Status should be COMPLETED, as we waited for the analysis to complete", ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
        TmfTreeModel<@NonNull TmfTreeDataModel> treeModel = treeResponse.getModel();
        assertNotNull(treeModel);
        assertEquals(EXPECTED_FULL_PATHS, getFullPaths(treeModel.getEntries()));
        List<Long> ids = Lists.transform(treeModel.getEntries(), TmfTreeDataModel::getId);
        SelectionTimeQueryFilter selectionFilter = new SelectionTimeQueryFilter(START, END, 100, ids);
        TmfModelResponse<@NonNull ITmfXyModel> xyResponse = provider.fetchXY(FetchParametersUtils.selectionTimeQueryToMap(selectionFilter), null);
        assertEquals("Response Status should be COMPLETED, as we waited for the analysis to complete", ITmfResponse.Status.COMPLETED, xyResponse.getStatus());
        ITmfXyModel xyModel = xyResponse.getModel();
        assertNotNull(xyModel);
        assertEquals(EXPECTED_YDATA, Maps.uniqueIndex(xyModel.getSeriesData(), ISeriesModel::getId));
    } finally {
        module.dispose();
        CtfTmfTestTraceUtils.dispose(CtfTestTrace.HELLO_LOST);
    }
}
Also used : TmfStatisticsModule(org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule) HistogramDataProvider(org.eclipse.tracecompass.internal.tmf.core.histogram.HistogramDataProvider) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) Test(org.junit.Test)

Example 19 with TimeQueryFilter

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

the class TmfStatisticsTest method testHistogramQueryFull.

/**
 * Test the {@link ITmfStatistics#histogramQuery} method over the whole
 * trace.
 */
@Test
public void testHistogramQueryFull() {
    final int NB_REQ = 10;
    TimeQueryFilter histogramFilter = new TimeQueryFilter(tStart, tEnd, NB_REQ);
    List<@NonNull Long> results = backend.histogramQuery(histogramFilter.getTimesRequested());
    /* Make sure the returned array has the right size */
    assertEquals(NB_REQ, results.size());
    /* Check the total number of events */
    long count = 0;
    for (long val : results) {
        count += val;
    }
    assertEquals(totalNbEvents, count);
    /* Check the contents of each "bucket" */
    assertEquals(1, results.get(0).longValue());
    assertEquals(98663, results.get(1).longValue());
    assertEquals(99506, results.get(2).longValue());
    assertEquals(62165, results.get(3).longValue());
    assertEquals(66797, results.get(4).longValue());
    assertEquals(80895, results.get(5).longValue());
    assertEquals(71439, results.get(6).longValue());
    assertEquals(73656, results.get(7).longValue());
    assertEquals(71792, results.get(8).longValue());
    assertEquals(70405, results.get(9).longValue());
}
Also used : TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Test(org.junit.Test)

Example 20 with TimeQueryFilter

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

the class TmfStatisticsTest method testHistogramQuerySmall.

// ------------------------------------------------------------------------
// Tests for histogramQuery()
// ------------------------------------------------------------------------
/**
 * Test the {@link ITmfStatistics#histogramQuery} method for the small known
 * interval.
 */
@Test
public void testHistogramQuerySmall() {
    final int NB_REQ = 10;
    TimeQueryFilter histogramFilter = new TimeQueryFilter(t1, t6, NB_REQ);
    List<@NonNull Long> results = backend.histogramQuery(histogramFilter.getTimesRequested());
    /* Make sure the returned array has the right size */
    assertEquals(NB_REQ, results.size());
    /* Check the contents of each "bucket" */
    assertEquals(0, results.get(0).longValue());
    assertEquals(0, results.get(1).longValue());
    assertEquals(0, results.get(2).longValue());
    assertEquals(0, results.get(3).longValue());
    assertEquals(0, results.get(4).longValue());
    assertEquals(1, results.get(5).longValue());
    assertEquals(0, results.get(6).longValue());
    assertEquals(0, results.get(7).longValue());
    assertEquals(0, results.get(8).longValue());
    assertEquals(1, results.get(9).longValue());
}
Also used : TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Test(org.junit.Test)

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