Search in sources :

Example 16 with TimeRangeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException 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)

Example 17 with TimeRangeException

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

the class AbstractTmfMipmapStateProvider method getFeatureSet.

// ------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------
private Set<ITmfMipmapFeature> getFeatureSet(int baseQuark, long ts, ITmfStateValue value, int mipmapFeatureBits, int resolution) {
    ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
    Set<ITmfMipmapFeature> features = featureMap.get(baseQuark);
    if (features != null) {
        return features;
    }
    features = new LinkedHashSet<>();
    if (value.isNull()) {
        return features;
    }
    featureMap.put(baseQuark, features);
    if (resolution > 1) {
        try {
            if ((mipmapFeatureBits & MAX) != 0) {
                int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MAX_STRING);
                ss.modifyAttribute(ts, 0, featureQuark);
                MaxMipmapFeature mf = new MaxMipmapFeature(baseQuark, featureQuark, resolution, ss);
                features.add(mf);
            }
            if ((mipmapFeatureBits & MIN) != 0) {
                int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MIN_STRING);
                ss.modifyAttribute(ts, 0, featureQuark);
                MinMipmapFeature mf = new MinMipmapFeature(baseQuark, featureQuark, resolution, ss);
                features.add(mf);
            }
            if ((mipmapFeatureBits & AVG) != 0) {
                int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, AVG_STRING);
                ss.modifyAttribute(ts, 0, featureQuark);
                AvgMipmapFeature mf = new AvgMipmapFeature(baseQuark, featureQuark, resolution, ss);
                features.add(mf);
            }
        } catch (TimeRangeException e) {
            // $NON-NLS-1$
            Activator.logError("MipMapProvider : Time stamp outside of time range of state system", e);
        } catch (StateValueTypeException e) {
            // $NON-NLS-1$
            Activator.logError("MipMapProvider : Wrong state value type", e);
        }
    }
    return features;
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)

Example 18 with TimeRangeException

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

the class StateSystemDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
    // Get the quarks to display
    Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    synchronized (fEntryBuilder) {
        if (selectedItems == null) {
            // No selected items, take them all
            selectedItems = fIDToDisplayQuark.keySet();
        }
        for (Long id : selectedItems) {
            Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
            if (pair != null) {
                table.put(pair.getFirst(), pair.getSecond(), id);
            }
        }
    }
    List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
    try {
        List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
        for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
            ITmfStateSystem ss = Objects.requireNonNull(ssEntry.getKey());
            List<@NonNull ITimeGraphRowModel> rows = getRowModels(ss, ssEntry.getValue(), times, fetchParameters, monitor);
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
            synchronized (fEntryBuilder) {
                // Add the SS
                Long ssId = fSsToId.get(ss);
                if (ssId != null && selectedItems.contains(ssId)) {
                    TimeGraphRowModel ssRow = new TimeGraphRowModel(ssId, new ArrayList<>());
                    List<@NonNull ITimeGraphState> states = ssRow.getStates();
                    states.add(new TimeGraphState(ss.getStartTime(), ss.getCurrentEndTime() - ss.getStartTime(), Integer.MAX_VALUE));
                    rows.add(ssRow);
                }
            }
            allRows.addAll(rows);
        }
        synchronized (fEntryBuilder) {
            for (ModuleEntryModel module : fModuleEntryModelList) {
                if (selectedItems.contains(module.getId())) {
                    allRows.add(getModuleRowModels(module));
                }
            }
        }
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
}
Also used : ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 19 with TimeRangeException

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

the class KernelContextSwitchAnalysis method getContextSwitchesRange.

/**
 * Get a map of the number of context switch per CPU during a time range.
 *
 * @param startParam
 *            Start time of requested range
 * @param endParam
 *            End time of requested range
 * @return A map of CPU# -> nb of context switch in the [start, end]
 *         interval. CPU# == -1 represents the total number of context
 *         switch
 * @throws TimeRangeException
 *             if one or more of the parameters is outside the range the
 *             state history
 */
@NonNullByDefault({})
@NonNull
public Map<Integer, Long> getContextSwitchesRange(final long startParam, final long endParam) {
    @Nullable final ITmfStateSystem stateSystem = getStateSystem();
    ITmfTrace trace = getTrace();
    if (trace == null || stateSystem == null) {
        return Collections.<Integer, Long>emptyMap();
    }
    long start = Math.max(startParam, stateSystem.getStartTime());
    long end = Math.min(endParam, stateSystem.getCurrentEndTime());
    ITmfStateSystem contextSwitchStateSystem = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelContextSwitchAnalysis.ID);
    if (contextSwitchStateSystem == null) {
        return Collections.<Integer, Long>emptyMap();
    }
    /*
         * Make sure the start/end times are within the state history, so we
         * don't get TimeRange exceptions.
         */
    long startTime = contextSwitchStateSystem.getStartTime();
    long endTime = contextSwitchStateSystem.getCurrentEndTime();
    if (endTime < startTime) {
        return Collections.<Integer, Long>emptyMap();
    }
    Map<Integer, Long> map = new HashMap<>();
    try {
        /* Get the list of quarks for each CPU */
        int cpusNode = contextSwitchStateSystem.getQuarkAbsolute(Attributes.CPUS);
        List<Integer> cpuQuarks = contextSwitchStateSystem.getSubAttributes(cpusNode, false);
        /* Query full states at start and end times */
        List<ITmfStateInterval> kernelEndState = contextSwitchStateSystem.queryFullState(end);
        List<ITmfStateInterval> kernelStartState = contextSwitchStateSystem.queryFullState(start);
        Long totalNbCxtSwt = 0l;
        for (Integer cpuQuark : cpuQuarks) {
            int cpuNb = Integer.parseInt(contextSwitchStateSystem.getAttributeName(cpuQuark.intValue()));
            Long nbCxtSwtForCore = kernelEndState.get(cpuQuark).getStateValue().unboxLong() - kernelStartState.get(cpuQuark).getStateValue().unboxLong();
            map.put(cpuNb, nbCxtSwtForCore);
            totalNbCxtSwt += nbCxtSwtForCore;
        }
        /* Put the total number of context switches in the interval */
        map.put(TOTAL, totalNbCxtSwt);
    } catch (TimeRangeException | AttributeNotFoundException e) {
    /*
             * Assume there is no events or the attribute does not exist yet,
             * nothing will be put in the map.
             */
    } catch (StateValueTypeException | StateSystemDisposedException e) {
        /*
             * These other exception types would show a logic problem, so they
             * should not happen.
             */
        // $NON-NLS-1$
        Activator.getDefault().logError("Error getting CPU context switches in a time range", e);
    }
    return map;
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) HashMap(java.util.HashMap) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 20 with TimeRangeException

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

the class ThreadPriorityAspect method resolve.

@Override
@Nullable
public Integer resolve(ITmfEvent event) {
    @NonNull final ITmfTrace trace = event.getTrace();
    KernelAnalysisModule kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID);
    if (kernelAnalysis == null) {
        return null;
    }
    ITmfStateSystem ss = kernelAnalysis.getStateSystem();
    if (ss == null) {
        return null;
    }
    Integer tid = KernelTidAspect.INSTANCE.resolve(event);
    if (tid == null) {
        return null;
    }
    final long ts = event.getTimestamp().getValue();
    Integer execPrio = null;
    try {
        Integer cpu = 0;
        if (tid == 0) {
            /* Find the CPU this event is run on */
            cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TmfCpuAspect.class, event);
        }
        int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, Attributes.buildThreadAttributeName(tid, cpu), Attributes.PRIO);
        ITmfStateInterval interval = ss.querySingleState(ts, execPrioQuark);
        ITmfStateValue prioValue = interval.getStateValue();
        /* We know the prio must be an Integer */
        execPrio = prioValue.unboxInt();
    } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
    }
    return execPrio;
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) KernelAnalysisModule(org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)55 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)41 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)40 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)22 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)20 Test (org.junit.Test)17 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)15 NonNull (org.eclipse.jdt.annotation.NonNull)13 ArrayList (java.util.ArrayList)12 Nullable (org.eclipse.jdt.annotation.Nullable)11 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)10 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)9 HashMap (java.util.HashMap)8 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)8 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)6 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)6 List (java.util.List)5 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)5