Search in sources :

Example 26 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class TmfMipmapStateProviderTest method testQueryMipAvg.

/**
 * Test a single query to the state system for an average
 *
 * Make sure the state system has data.
 *
 * Hint: the value read should always be more or less(t / 1000)
 */
@Test
public void testQueryMipAvg() {
    assertNotNull(ssq);
    try {
        List<ITmfStateInterval> intervals = ssq.queryFullState(TEST_TIMESTAMP);
        int mipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.AVG_STRING);
        assertEquals("avg nblevels", NB_LEVELS, intervals.get(mipmapQuark).getStateValue().unboxInt());
        for (int level = 1; level < NB_LEVELS; level++) {
            long width = (long) Math.pow(RESOLUTION, level);
            int levelQuark = ssq.getQuarkRelative(mipmapQuark, String.valueOf(level));
            ITmfStateInterval interval = intervals.get(levelQuark);
            double valueDouble = interval.getStateValue().unboxDouble();
            assertEquals("avg value @ level " + level, 0.5 + (width / 2) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width, valueDouble, DELTA);
            assertEquals("avg start time @ level " + level, START_TIME + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getStartTime());
            assertEquals("avg end time @ level " + level, START_TIME + (INTERVAL * width) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getEndTime() + 1);
        }
    } catch (TimeRangeException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
    assertTrue(true);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) Test(org.junit.Test)

Example 27 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class CallsiteIterator method getCallsite.

@Nullable
private TimeCallsite getCallsite(@Nullable ITmfStateInterval fileInterval, @Nullable ITmfStateInterval lineInterval) {
    ITmfStateSystem ss = fSS;
    if (ss == null || fileInterval == null || lineInterval == null) {
        return null;
    }
    try {
        Object value = fileInterval.getValue();
        if (value instanceof Integer) {
            long fileId = (Integer) value + ss.getStartTime();
            // Query line number
            Object lineValue = lineInterval.getValue();
            if (lineValue instanceof Integer) {
                long line = (Integer) lineValue;
                String fileName = fInterner.resolve(ss, fileId, fSourceQuark);
                if (fileName != null) {
                    long time = Math.max(fileInterval.getStartTime(), lineInterval.getStartTime());
                    return new TimeCallsite(new TmfCallsite(fileName, line == -1 ? null : line), time);
                }
            }
        }
    } catch (StateSystemDisposedException e) {
    // Skip
    }
    return null;
}
Also used : TmfCallsite(org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TimeCallsite(org.eclipse.tracecompass.tmf.core.analysis.callsite.TimeCallsite) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 28 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class LostEventsOutputAnnotationProvider method fetchAnnotations.

@SuppressWarnings("null")
@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    IProgressMonitor progressMonitor = monitor;
    if (progressMonitor == null) {
        progressMonitor = new NullProgressMonitor();
    }
    ITmfStateSystem ss = getStateSystem();
    if (ss == null) {
        return NO_DATA;
    }
    int lostEventsQuark = getLostEventsQuark(ss);
    if (lostEventsQuark == -1) {
        return NO_DATA;
    }
    List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    @Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
    if (timeRequested == null || timeRequested.size() < 2 || (categories != null && !categories.contains(LOST_EVENTS))) {
        return NO_DATA;
    }
    if (timeRequested.equals(fLastRequest)) {
        // $NON-NLS-1$
        return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
    }
    fLastRequest = new ArrayList<>(timeRequested);
    TreeMultimap<String, Annotation> markers = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(Annotation::getStartTime));
    try {
        long start = Math.max(timeRequested.get(0), ss.getStartTime());
        long end = Math.min(timeRequested.get(timeRequested.size() - 1), ss.getCurrentEndTime());
        if (start <= end) {
            List<Long> times = new ArrayList<>(getTimes(ss, timeRequested));
            /* Update start to ensure that the previous marker is included. */
            start = Math.max(start - 1, ss.getStartTime());
            /* Update end to ensure that the next marker is included. */
            long nextStartTime = ss.querySingleState(end, lostEventsQuark).getEndTime() + 1;
            end = Math.min(nextStartTime, ss.getCurrentEndTime());
            times.set(0, start);
            times.set(times.size() - 1, end);
            for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(lostEventsQuark), times)) {
                if (progressMonitor.isCanceled()) {
                    fLastRequest = Collections.emptyList();
                    fLastAnnotationModel = new AnnotationModel(Collections.emptyMap());
                    // $NON-NLS-1$
                    return new TmfModelResponse<>(fLastAnnotationModel, Status.CANCELLED, "");
                }
                if (interval.getStateValue().isNull()) {
                    continue;
                }
                long lostEventsStartTime = interval.getStartTime();
                /*
                     * The end time of the lost events range is the value of the
                     * attribute, not the end time of the interval.
                     */
                long lostEventsEndTime = interval.getStateValue().unboxLong();
                long duration = lostEventsEndTime - lostEventsStartTime;
                Map<String, Object> style = new HashMap<>();
                style.put(StyleProperties.COLOR, COLOR);
                style.put(StyleProperties.OPACITY, OPACITY);
                markers.put(LOST_EVENTS, new Annotation(lostEventsStartTime, duration, -1, AnnotationType.CHART, null, new OutputElementStyle(LOST_EVENTS, style)));
            }
        }
    } catch (StateSystemDisposedException e) {
    /* ignored */
    }
    fLastAnnotationModel = new AnnotationModel(markers.asMap());
    // $NON-NLS-1$
    return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 29 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class HistogramDataProvider method fetchXY.

@Override
@NonNull
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fModule.waitForInitialization();
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    long[] xValues = new long[0];
    if (filter == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    xValues = filter.getTimesRequested();
    Collection<Long> selected = filter.getSelectedItems();
    int n = xValues.length;
    ImmutableList.Builder<IYModel> builder = ImmutableList.builder();
    final ITmfStatistics stats = Objects.requireNonNull(fModule.getStatistics());
    if (selected.contains(fTotalId)) {
        List<Long> values = stats.histogramQuery(filter.getTimesRequested());
        double[] y = new double[n];
        Arrays.setAll(y, values::get);
        String totalName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Total;
        builder.add(new YModel(fTotalId, totalName, y));
    }
    ITmfStateSystem eventsSs = fModule.getStateSystem(TmfStatisticsEventTypesModule.ID);
    if (selected.contains(fLostId) && eventsSs != null) {
        try {
            YModel series = getLostEvents(eventsSs, xValues);
            builder.add(series);
        } catch (StateSystemDisposedException e) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.STATE_SYSTEM_FAILED);
        }
    }
    boolean completed = eventsSs != null ? eventsSs.waitUntilBuilt(0) || eventsSs.getCurrentEndTime() >= filter.getEnd() : false;
    return TmfXyResponseFactory.create(TITLE, xValues, builder.build(), completed);
}
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) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) 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) AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 30 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class AbstractTreeDataProvider method fetchTree.

@Override
public final TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fLock.readLock().lock();
    try {
        if (fCached != null) {
            /*
                 * If the tree depends on the filter, isCacheable should return false (by
                 * contract). If the tree is not cacheable, fCached will always be null, and we
                 * will never enter this block.
                 */
            return fCached;
        }
    } finally {
        fLock.readLock().unlock();
    }
    fLock.writeLock().lock();
    fAnalysisModule.waitForInitialization();
    ITmfStateSystem ss = fAnalysisModule.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    boolean complete = ss.waitUntilBuilt(0);
    try (FlowScopeLog scope = // $NON-NLS-1$
    new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeDataProvider#fetchTree").setCategory(getClass().getSimpleName()).build()) {
        TmfTreeModel<M> tree = null;
        /* Don't query empty state system */
        if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
            tree = getTree(ss, fetchParameters, monitor);
            for (M model : tree.getEntries()) {
                if (model instanceof ICoreElementResolver) {
                    fEntryMetadata.put(model.getId(), ((ICoreElementResolver) model).getMetadata());
                }
            }
        }
        if (complete) {
            TmfModelResponse<TmfTreeModel<M>> response = new TmfModelResponse<>(tree, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
            if (isCacheable()) {
                fCached = response;
            }
            return response;
        }
        return new TmfModelResponse<>(tree, ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
    } catch (StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    } finally {
        fLock.writeLock().unlock();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) ICoreElementResolver(org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)96 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)78 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)51 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)40 Test (org.junit.Test)38 NonNull (org.eclipse.jdt.annotation.NonNull)25 ArrayList (java.util.ArrayList)24 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)16 HashMap (java.util.HashMap)15 Nullable (org.eclipse.jdt.annotation.Nullable)15 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)11 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)9 Map (java.util.Map)7