Search in sources :

Example 26 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class IAnalysisDataContainer method getQuarkAbsoluteAndAdd.

/**
 * Basic quark-retrieving method. Pass an attribute in parameter as an array of
 * strings, the matching quark will be returned. If the attribute does not
 * exist, it will add the quark to the state system if the context allows it.
 * Otherwise a negative value will be returned.
 *
 * See {@link ITmfStateSystemBuilder#getQuarkAbsoluteAndAdd(String...)}
 *
 * @param path
 *            Full path to the attribute
 * @return The quark for this attribute
 */
default int getQuarkAbsoluteAndAdd(String... path) {
    ITmfStateSystem stateSystem = getStateSystem();
    int quark = stateSystem.optQuarkAbsolute(path);
    if (quark == ITmfStateSystem.INVALID_ATTRIBUTE && !isReadOnlyContainer() && (stateSystem instanceof ITmfStateSystemBuilder)) {
        quark = ((ITmfStateSystemBuilder) stateSystem).getQuarkAbsoluteAndAdd(path);
    }
    return quark;
}
Also used : ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 27 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method create.

/**
 * {@link XmlTimeGraphDataProvider} create method
 *
 * @param trace
 *            the trace for which the provider will return data
 * @param viewElement
 *            the XML view {@link Element}.
 * @return the relevant {@link XmlTimeGraphDataProvider}
 */
public static XmlTimeGraphDataProvider create(@NonNull ITmfTrace trace, Element viewElement) {
    Set<@NonNull String> analysisIds = TmfXmlUtils.getViewAnalysisIds(viewElement);
    List<Element> entries = TmfXmlUtils.getChildElements(viewElement, TmfXmlStrings.ENTRY_ELEMENT);
    Set<@NonNull ITmfAnalysisModuleWithStateSystems> stateSystemModules = new HashSet<>();
    if (analysisIds.isEmpty()) {
        /*
             * No analysis specified, take all state system analysis modules
             */
        Iterables.addAll(stateSystemModules, TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class));
    } else {
        for (String moduleId : analysisIds) {
            // Get the module for the current trace only. The caller will take care of
            // generating composite providers with experiments
            IAnalysisModule module = trace.getAnalysisModule(moduleId);
            if (module instanceof ITmfAnalysisModuleWithStateSystems) {
                stateSystemModules.add((ITmfAnalysisModuleWithStateSystems) module);
            }
        }
    }
    List<ITmfStateSystem> sss = new ArrayList<>();
    for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) {
        if (module.schedule().isOK() && module.waitForInitialization()) {
            module.getStateSystems().forEach(sss::add);
        }
    }
    return (sss.isEmpty() ? null : new XmlTimeGraphDataProvider(trace, sss, entries));
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) ITmfAnalysisModuleWithStateSystems(org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems) HashSet(java.util.HashSet) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 28 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<@NonNull XmlTimeGraphEntryModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    @NonNull List<@NonNull XmlTimeGraphEntryModel> entryList = new ArrayList<>();
    boolean isComplete = true;
    String traceName = String.valueOf(getTrace().getName());
    for (ITmfStateSystem ss : fSs) {
        isComplete &= ss.waitUntilBuilt(0);
        /* Don't query empty state system */
        if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
            long start = ss.getStartTime();
            long end = ss.getCurrentEndTime();
            long id = fBaseQuarkToId.row(ss).computeIfAbsent(ITmfStateSystem.ROOT_ATTRIBUTE, s -> sfAtomicId.getAndIncrement());
            Builder ssEntry = new Builder(id, -1, Collections.singletonList(traceName), start, end, null, ss, ITmfStateSystem.ROOT_ATTRIBUTE, fCompilationData);
            entryList.add(ssEntry.build());
            for (Element entry : fEntries) {
                buildEntry(ss, entry, ssEntry, -1, StringUtils.EMPTY, end, entryList);
            }
        }
    }
    Status status = isComplete ? Status.COMPLETED : Status.RUNNING;
    String msg = isComplete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
    return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), entryList), status, msg);
}
Also used : Status(org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status) Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 29 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
    // 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 new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    for (Long id : filter.getSelectedItems()) {
        Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
        if (pair != null) {
            table.put(pair.getFirst(), pair.getSecond(), id);
        }
    }
    List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
    try {
        for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
            Collection<@NonNull ITimeGraphRowModel> rows = createRows(ssEntry.getKey(), ssEntry.getValue(), filter.getTimesRequested(), fetchParameters, monitor);
            allRows.addAll(rows);
        }
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 30 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class XmlXYDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    DataDrivenStateSystemPath display = fDisplay;
    XmlXYEntry entry = fXmlEntry;
    ITmfStateSystem ss = entry.getStateSystem();
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long[] xValues = filter.getTimesRequested();
    Map<Integer, IYModel> map = initSeries(fetchParameters);
    if (map.isEmpty()) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    long currentEnd = ss.getCurrentEndTime();
    try {
        for (int i = 0; i < xValues.length; i++) {
            if (monitor != null && monitor.isCanceled()) {
                return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
            }
            long time = xValues[i];
            if (time > currentEnd) {
                break;
            } else if (ss.getStartTime() <= time) {
                List<@NonNull ITmfStateInterval> full = ss.queryFullState(time);
                for (Entry<Integer, IYModel> series : map.entrySet()) {
                    int attributeQuark = display.getQuark(series.getKey(), entry);
                    if (attributeQuark >= 0 && attributeQuark < full.size()) {
                        Object value = full.get(attributeQuark).getValue();
                        series.getValue().getData()[i] = extractValue(value);
                    }
                }
            }
        }
        // Update the series value if delta is requested
        for (Entry<Integer, IYModel> series : map.entrySet()) {
            if (entry.getType().equals(DisplayType.DELTA)) {
                getSeriesDelta(series.getValue().getData());
            }
        }
    } catch (StateSystemDisposedException e) {
        return TmfXyResponseFactory.createFailedResponse(e.getMessage());
    }
    boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
    return TmfXyResponseFactory.create(TITLE, xValues, map.values(), complete);
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)137 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)52 Test (org.junit.Test)52 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)51 NonNull (org.eclipse.jdt.annotation.NonNull)32 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)30 Nullable (org.eclipse.jdt.annotation.Nullable)26 ArrayList (java.util.ArrayList)25 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)23 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)22 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)22 HashMap (java.util.HashMap)18 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)16 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)16 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 List (java.util.List)9 QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)9 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)9