Search in sources :

Example 1 with ITmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.

the class XmlXyDataProviderTest method assertAndGetTree.

private static Map<Long, String> assertAndGetTree(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, ITmfTrace trace, List<String> expectedStrings) {
    TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> treeResponse = xyProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), MONITOR);
    assertNotNull(treeResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
    TmfTreeModel<@NonNull ITmfTreeDataModel> treeModel = treeResponse.getModel();
    assertNotNull(treeModel);
    List<@NonNull ITmfTreeDataModel> treeEntries = treeModel.getEntries();
    Map<Long, String> map = new HashMap<>();
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        assertTrue("actual entry absent at " + i + ": " + expectedString, treeEntries.size() > i);
        String[] split = expectedString.split(",");
        ITmfTreeDataModel xmlXyEntry = treeEntries.get(i);
        assertEquals("Checking entry name at " + i, split[0], xmlXyEntry.getName());
        // Check the parent
        long parentId = xmlXyEntry.getParentId();
        if (parentId < 0) {
            assertEquals("Checking empty parent at " + i, split[1], "null");
        } else {
            String parentName = map.get(parentId);
            assertEquals("Checking parent at " + i, split[1], parentName);
        }
        map.put(xmlXyEntry.getId(), xmlXyEntry.getName());
    }
    assertEquals("Extra actual entries", expectedStrings.size(), treeEntries.size());
    return map;
}
Also used : HashMap(java.util.HashMap) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 2 with ITmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.

the class TmfTreeModelTest method initClass.

/**
 * Run once
 */
@BeforeClass
public static void initClass() {
    for (int i = 0; i < NB_COLUMNS; i++) {
        String headerText = HEADER_PREFIX + String.valueOf(i);
        String headerTooltip = TOOLTIP_PREFIX + String.valueOf(i);
        fTestHeaders.add(headerText);
        fExpectedEmptyTooltips.add("");
        fExpectedTooltips.add(headerTooltip);
        TableColumnDescriptor.Builder descBuilder = new TableColumnDescriptor.Builder();
        descBuilder.setText(headerText);
        descBuilder.setTooltip(headerTooltip);
        fTestDescriptors.add(descBuilder.build());
    }
    for (int k = 0; k < NB_ROWS; k++) {
        List<String> labels = new ArrayList<>();
        for (int i = 0; i < NB_COLUMNS; i++) {
            labels.add(LABEL_PREFIX + String.valueOf(i));
        }
        ITmfTreeDataModel dataModel = new TmfTreeDataModelStub(k, PARENT_ID, labels);
        fTestEntries.add(dataModel);
    }
}
Also used : ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModelStub(org.eclipse.tracecompass.tmf.tests.stubs.model.tree.TmfTreeDataModelStub) ArrayList(java.util.ArrayList) TableColumnDescriptor(org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) BeforeClass(org.junit.BeforeClass)

Example 3 with ITmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.

the class AbstractSelectTreeViewer2 method modelToTree.

/**
 * Algorithm to convert a model (List of {@link TmfTreeDataModel}) to the tree.
 *
 * @param start
 *            queried start time
 * @param end
 *            queried end time
 * @param model
 *            model to convert
 * @return the resulting {@link TmfTreeViewerEntry}.
 */
protected ITmfTreeViewerEntry modelToTree(long start, long end, List<ITmfTreeDataModel> model) {
    TmfTreeViewerEntry root = new TmfTreeViewerEntry(StringUtils.EMPTY);
    Map<Long, TmfTreeViewerEntry> map = new HashMap<>();
    map.put(-1L, root);
    for (ITmfTreeDataModel entry : model) {
        TmfGenericTreeEntry<ITmfTreeDataModel> viewerEntry = new TmfGenericTreeEntry<>(entry);
        map.put(entry.getId(), viewerEntry);
        TmfTreeViewerEntry parent = map.get(entry.getParentId());
        if (parent != null && !parent.getChildren().contains(viewerEntry)) {
            parent.addChild(viewerEntry);
        }
    }
    return root;
}
Also used : ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) HashMap(java.util.HashMap)

Example 4 with ITmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.

the class AbstractSelectTreeViewer2 method updateContent.

@Override
protected void updateContent(long start, long end, boolean isSelection) {
    try (FlowScopeLog scope = new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME).setCategory(fLogCategory).build()) {
        ITmfTrace trace = getTrace();
        if (trace == null) {
            return;
        }
        Job thread = new Job(UPDATE_CONTENT_JOB_NAME) {

            @Override
            public IStatus run(IProgressMonitor monitor) {
                try (FlowScopeLog runScope = // $NON-NLS-1$
                new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME + " run").setParentScope(scope).build()) {
                    ITmfTreeDataProvider<@NonNull ITmfTreeDataModel> provider = getProvider(trace);
                    if (provider == null) {
                        return Status.OK_STATUS;
                    }
                    Map<String, Object> parameters = getParameters(start, end, isSelection);
                    if (parameters.isEmpty()) {
                        return Status.OK_STATUS;
                    }
                    boolean isComplete = false;
                    double factor = 1.0;
                    do {
                        TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> response;
                        try (FlowScopeLog iterScope = // $NON-NLS-1$
                        new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME + " query").setParentScope(scope).build()) {
                            response = provider.fetchTree(parameters, monitor);
                            TmfTreeModel<@NonNull ITmfTreeDataModel> model = response.getModel();
                            if (model != null) {
                                updateTree(trace, start, end, model.getEntries());
                            }
                        }
                        ITmfResponse.Status status = response.getStatus();
                        if (status == ITmfResponse.Status.COMPLETED) {
                            /* Model is complete, no need to request again the data provider */
                            isComplete = true;
                        } else if (status == ITmfResponse.Status.FAILED || status == ITmfResponse.Status.CANCELLED) {
                            /* Error occurred, return */
                            isComplete = true;
                        } else {
                            /**
                             * Status is RUNNING. Sleeping current thread to wait before request data
                             * provider again
                             */
                            try {
                                Thread.sleep((long) (BUILD_UPDATE_TIMEOUT * factor));
                                factor = Math.min(20, factor + 1);
                            } catch (InterruptedException e) {
                                /**
                                 * InterruptedException is throw by Thread.Sleep and we should retry querying
                                 * the data provider
                                 */
                                runScope.addData(FAILED_TO_SLEEP_PREFIX + getName(), e);
                                Thread.currentThread().interrupt();
                                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, FAILED_TO_SLEEP_PREFIX + getName());
                            }
                        }
                    } while (!isComplete);
                    return Status.OK_STATUS;
                }
            }
        };
        thread.setSystem(true);
        thread.schedule();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ITmfResponse(org.eclipse.tracecompass.tmf.core.response.ITmfResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) Job(org.eclipse.core.runtime.jobs.Job)

Example 5 with ITmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.

the class StateSystemPresentationProvider method getStateTableIndex.

@Override
public int getStateTableIndex(ITimeEvent event) {
    if (event instanceof TimeEvent) {
        TimeEvent timeEvent = (TimeEvent) event;
        Object value = timeEvent.getLabel();
        if (value != null) {
            return Math.floorMod(value.hashCode(), NUM_COLORS);
        }
        ITimeGraphEntry entry = event.getEntry();
        if (entry != null) {
            ITmfTreeDataModel model = ((TimeGraphEntry) entry).getEntryModel();
            if (model instanceof StateSystemEntryModel || model instanceof ModuleEntryModel) {
                // tooltip
                return INVISIBLE;
            }
        }
        // grey
        return NUM_COLORS;
    }
    return INVISIBLE;
}
Also used : ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) ModuleEntryModel(org.eclipse.tracecompass.internal.tmf.core.statesystem.provider.StateSystemDataProvider.ModuleEntryModel) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) StateSystemEntryModel(org.eclipse.tracecompass.internal.tmf.core.statesystem.provider.StateSystemDataProvider.StateSystemEntryModel) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)

Aggregations

ITmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel)20 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)9 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)8 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)7 ArrayList (java.util.ArrayList)4 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)4 Test (org.junit.Test)4 ISelection (org.eclipse.jface.viewers.ISelection)3 ResourcesEntryModel (org.eclipse.tracecompass.internal.analysis.os.linux.core.resourcesstatus.ResourcesEntryModel)3 ModuleEntryModel (org.eclipse.tracecompass.internal.tmf.core.statesystem.provider.StateSystemDataProvider.ModuleEntryModel)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 ITmfTreeXYDataProvider (org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider)3 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)3 ITmfAnalysisModuleWithStateSystems (org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems)3 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)3 TimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent)3 Element (org.w3c.dom.Element)3 HashMap (java.util.HashMap)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Nullable (org.eclipse.jdt.annotation.Nullable)2