Search in sources :

Example 26 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class DataDrivenScenarioHistoryBuilder method getStoredFieldValue.

/**
 * Get the value of a special field in the state system
 *
 * @param container
 *            The state system container this class use
 * @param attributeName
 *            The attribute name of the special field
 * @param info
 *            The scenario details
 * @param event
 *            The current event
 *
 * @return The value of a special field saved into the state system
 */
public ITmfStateValue getStoredFieldValue(IAnalysisDataContainer container, String attributeName, DataDrivenScenarioInfo info, ITmfEvent event) {
    ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
    long ts = event.getTimestamp().toNanos();
    ITmfStateInterval state = null;
    try {
        int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
        state = ss.querySingleState(ts, attributeQuark);
    } catch (StateSystemDisposedException e) {
        // $NON-NLS-1$
        Activator.logError("failed to get the value of the stored field " + attributeName, e);
    }
    return (state != null) ? NonNullUtils.checkNotNull(state.getStateValue()) : TmfStateValue.nullValue();
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)

Example 27 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class DataDrivenScenarioHistoryBuilder method getSpecificStateStartTime.

/**
 * Get the start time of a specific state of the scenario
 *
 * @param container
 *            The state system container this class use
 * @param stateName
 *            The name of the current state of the scenario
 * @param info
 *            The scenario details
 * @param event
 *            The current event
 *
 * @return The start time for the specified state
 */
public long getSpecificStateStartTime(IXmlStateSystemContainer container, String stateName, DataDrivenScenarioInfo info, ITmfEvent event) {
    long ts = event.getTimestamp().getValue();
    ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
    try {
        int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STATE, stateName, START_TIME);
        ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
        return state.getStartTime();
    } catch (StateSystemDisposedException e) {
        // $NON-NLS-1$
        Activator.logError("failed the start time of the state " + stateName, e);
    }
    return -1l;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)

Example 28 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class DataDrivenValueStackPeek method resolveValue.

@Override
@Nullable
protected Object resolveValue(ITmfEvent event, int baseQuark, DataDrivenScenarioInfo scenarioInfo, IAnalysisDataContainer container) {
    final long ts = event.getTimestamp().toNanos();
    /* Query the state system for the value */
    Object value = null;
    ITmfStateSystem ss = container.getStateSystem();
    int quarkQuery = fPath.getQuark(event, baseQuark, scenarioInfo, container);
    /*
         * the query can fail : for example, if a value is requested but has not been
         * set yet
         */
    if (quarkQuery >= 0) {
        try {
            @Nullable ITmfStateInterval stackTopInterval = StateSystemUtils.querySingleStackTop(ss, ts, quarkQuery);
            return (stackTopInterval != null ? stackTopInterval.getStateValue().unboxValue() : null);
        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
            // $NON-NLS-1$
            throw new DataDrivenException("Resolving stack peek: " + e.getMessage(), event);
        }
    }
    return value;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) DataDrivenException(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenException) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 29 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method processEntry.

private Builder processEntry(@NonNull Element entryElement, DataDrivenStateSystemPath displayPath, @NonNull Builder parentEntry, int quark, ITmfStateSystem ss, long currentEnd) {
    /*
         * Get the start time and end time of this entry from the display attribute
         */
    int displayQuark = displayPath.getQuark(quark, parentEntry);
    long id = fBaseQuarkToId.row(ss).computeIfAbsent(quark, s -> sfAtomicId.getAndIncrement());
    if (displayQuark < 0) {
        return new Builder(id, parentEntry.getId(), Collections.singletonList(String.format("Unknown display quark for %s", ss.getAttributeName(quark))), ss.getStartTime(), ss.getCurrentEndTime(), null, ss, quark, // $NON-NLS-1$
        fCompilationData);
    }
    fIDToDisplayQuark.put(id, new Pair<>(ss, displayQuark));
    long entryStart = ss.getStartTime();
    long entryEnd = currentEnd;
    try {
        ITmfStateInterval oneInterval = ss.querySingleState(entryStart, displayQuark);
        /* The entry start is the first non-null interval */
        while (oneInterval.getStateValue().isNull()) {
            long ts = oneInterval.getEndTime() + 1;
            if (ts > currentEnd) {
                break;
            }
            oneInterval = ss.querySingleState(ts, displayQuark);
        }
        entryStart = oneInterval.getStartTime();
        /* The entry end is the last non-null interval */
        oneInterval = ss.querySingleState(entryEnd - 1, displayQuark);
        while (oneInterval.getStateValue().isNull()) {
            long ts = oneInterval.getStartTime() - 1;
            if (ts < ss.getStartTime()) {
                break;
            }
            oneInterval = ss.querySingleState(ts, displayQuark);
        }
        entryEnd = Math.min(oneInterval.getEndTime() + 1, currentEnd);
    } catch (StateSystemDisposedException e) {
    }
    return new Builder(id, parentEntry.getId(), Collections.singletonList(ss.getAttributeName(quark)), entryStart, entryEnd, entryElement, ss, quark, fCompilationData);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 30 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method createRows.

@NonNull
private Collection<@NonNull ITimeGraphRowModel> createRows(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, long[] timesRequested, @NonNull Map<@NonNull String, @NonNull Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
    Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(parameters);
    if (regexesMap != null) {
        predicates.putAll(computeRegexPredicate(regexesMap));
    }
    long currentEndTime = ss.getCurrentEndTime();
    Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>(idToDisplayQuark.size());
    for (Entry<Integer, Long> entry : idToDisplayQuark.entrySet()) {
        quarkToRow.put(entry.getKey(), new TimeGraphRowModel(entry.getValue(), new ArrayList<>()));
    }
    for (ITmfStateInterval interval : ss.query2D(idToDisplayQuark.keySet(), getTimes(ss, timesRequested))) {
        if (monitor != null && monitor.isCanceled()) {
            return Collections.emptyList();
        }
        ITimeGraphRowModel row = quarkToRow.get(interval.getAttribute());
        if (row != null) {
            List<@NonNull ITimeGraphState> states = row.getStates();
            ITimeGraphState timeGraphState = getStateFromInterval(interval, currentEndTime);
            applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
        }
    }
    for (ITimeGraphRowModel model : quarkToRow.values()) {
        model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
    }
    return quarkToRow.values();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) TimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel) Predicate(java.util.function.Predicate) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) NonNull(org.eclipse.jdt.annotation.NonNull) AtomicLong(java.util.concurrent.atomic.AtomicLong) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)155 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)78 Test (org.junit.Test)56 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)52 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)41 ArrayList (java.util.ArrayList)37 NonNull (org.eclipse.jdt.annotation.NonNull)27 Nullable (org.eclipse.jdt.annotation.Nullable)20 HashMap (java.util.HashMap)19 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)16 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)15 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)14 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)12 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)12 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)12 ImmutableList (com.google.common.collect.ImmutableList)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)11 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)11