Search in sources :

Example 11 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class XmlTimeGraphView method buildEntryList.

// ------------------------------------------------------------------------
// Internal
// ------------------------------------------------------------------------
@Override
protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
    /*
         * Get the view element from the XML file. If the element can't be found,
         * return.
         */
    Element viewElement = fViewInfo.getViewElement(TmfXmlStrings.TIME_GRAPH_VIEW);
    if (viewElement == null) {
        return;
    }
    // Empty the additional state values
    fStringValueMap.clear();
    ITimeGraphPresentationProvider pres = this.getPresentationProvider();
    if (pres instanceof XmlPresentationProvider) {
        /*
             * TODO: Each entry of a line could have their own states/color. That will
             * require an update to the presentation provider
             */
        ((XmlPresentationProvider) pres).loadNewStates(viewElement);
        Display.getDefault().asyncExec(() -> {
            TimeGraphViewer timeGraphViewer = getTimeGraphViewer();
            if (timeGraphViewer.getTimeGraphControl().isDisposed()) {
                return;
            }
            timeGraphViewer.getTimeGraphControl().colorSettingsChanged(timeGraphViewer.getTimeGraphProvider().getStateTable());
        });
    }
    String title = fViewInfo.getViewTitle(viewElement);
    setViewTitle(title != null ? title : Messages.XmlTimeGraphView_DefaultTitle);
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    boolean complete = false;
    ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> provider = XmlDataProviderManager.getInstance().getTimeGraphProvider(trace, viewElement);
    if (provider == null) {
        return;
    }
    while (!complete && !subMonitor.isCanceled()) {
        TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), subMonitor);
        if (response.getStatus() == ITmfResponse.Status.FAILED) {
            // $NON-NLS-1$
            Activator.logError("XML Time Graph Data Provider failed: " + response.getStatusMessage());
            return;
        } else if (response.getStatus() == ITmfResponse.Status.CANCELLED) {
            return;
        }
        complete = response.getStatus() == ITmfResponse.Status.COMPLETED;
        TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
        if (model != null) {
            synchronized (fEntries) {
                /*
                     * Ensure that all the entries exist and are up to date.
                     */
                for (TimeGraphEntryModel entry : model.getEntries()) {
                    TimeGraphEntry tgEntry = fEntries.get(provider, entry.getId());
                    if (tgEntry == null) {
                        if (entry.getParentId() == -1) {
                            tgEntry = new TraceEntry(entry, trace, provider);
                            addToEntryList(parentTrace, Collections.singletonList(tgEntry));
                        } else {
                            tgEntry = new TimeGraphEntry(entry);
                        }
                        fEntries.put(provider, entry.getId(), tgEntry);
                    } else {
                        tgEntry.updateModel(entry);
                    }
                    if (entry.getParentId() == -1) {
                        setStartTime(Long.min(getStartTime(), entry.getStartTime()));
                        setEndTime(Long.max(getEndTime(), entry.getEndTime()));
                    }
                }
            }
            /*
                 * set the correct child / parent relation
                 */
            for (TimeGraphEntry child : fEntries.row(provider).values()) {
                TimeGraphEntry parent = fEntries.get(provider, child.getEntryModel().getParentId());
                if (parent != null) {
                    parent.addChild(child);
                }
            }
            long start = getStartTime();
            long end = getEndTime();
            final long resolution = Long.max(1, (end - start) / getDisplayWidth());
            zoomEntries(fEntries.row(provider).values(), start, end, resolution, subMonitor);
        }
        if (parentTrace.equals(getTrace())) {
            refresh();
        }
        subMonitor.worked(1);
        if (!complete) {
            try {
                Thread.sleep(BUILD_UPDATE_TIMEOUT);
            } catch (InterruptedException e) {
                // $NON-NLS-1$
                Activator.logError("Failed to wait for data provider", e);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) SubMonitor(org.eclipse.core.runtime.SubMonitor) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) ITimeGraphPresentationProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphViewer(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 12 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class XmlDataProviderManagerTest method testExperiment.

/**
 * Test getting the XML data provider for an experiment, with an analysis that
 * applies to an experiment
 */
@Test
public void testExperiment() {
    ITmfTrace trace = null;
    ITmfTrace trace2 = null;
    ITmfTrace experiment = null;
    try {
        // Initialize the trace and module
        trace = XmlUtilsTest.initializeTrace(TEST_TRACE);
        trace2 = XmlUtilsTest.initializeTrace(TEST_TRACE2);
        ITmfTrace[] traces = { trace, trace2 };
        experiment = new TmfExperiment(ITmfEvent.class, "Xml Experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
        TmfTraceOpenedSignal signal = new TmfTraceOpenedSignal(this, experiment, null);
        ((TmfTrace) trace).traceOpened(signal);
        ((TmfTrace) trace2).traceOpened(signal);
        ((TmfTrace) experiment).traceOpened(signal);
        // The data provider manager uses opened traces from the manager
        TmfTraceManager.getInstance().traceOpened(signal);
        Iterable<@NonNull DataDrivenAnalysisModule> modules = TmfTraceUtils.getAnalysisModulesOfClass(experiment, DataDrivenAnalysisModule.class);
        modules.forEach(module -> {
            module.schedule();
            assertTrue(module.waitForCompletion());
        });
        // Get the view element from the file
        Element viewElement = TmfXmlUtils.getElementInFile(TmfXmlTestFiles.EXPERIMENT.getPath().toOSString(), TmfXmlStrings.TIME_GRAPH_VIEW, EXPERIMENT_VIEW_ID);
        assertNotNull(viewElement);
        ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> timeGraphProvider = XmlDataProviderManager.getInstance().getTimeGraphProvider(experiment, viewElement);
        assertNotNull(timeGraphProvider);
        assertFalse(timeGraphProvider instanceof TmfTimeGraphCompositeDataProvider);
    } finally {
        if (trace != null) {
            trace.dispose();
        }
        if (trace2 != null) {
            trace2.dispose();
        }
        if (experiment != null) {
            experiment.dispose();
            TmfTraceManager.getInstance().traceClosed(new TmfTraceClosedSignal(this, experiment));
        }
    }
}
Also used : Element(org.w3c.dom.Element) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTimeGraphCompositeDataProvider(org.eclipse.tracecompass.internal.tmf.core.model.timegraph.TmfTimeGraphCompositeDataProvider) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) Test(org.junit.Test)

Example 13 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class XmlTimeGraphDataProviderTest method testNoParentDisplay.

/**
 * Test getting the XML data provider for one trace, with an analysis that
 * applies to a trace
 *
 * @throws IOException
 *             Exception thrown by analyses
 */
@Test
public void testNoParentDisplay() throws IOException {
    ITmfTrace trace = getTrace();
    assertNotNull(trace);
    try {
        runModule(trace);
        // Get the view element from the file
        Element viewElement = TmfXmlUtils.getElementInFile(TmfXmlTestFiles.DATA_PROVIDER_SIMPLE_FILE.getPath().toOSString(), TmfXmlStrings.TIME_GRAPH_VIEW, TIME_GRAPH_VIEW_ID2);
        assertNotNull(viewElement);
        ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> timeGraphProvider = XmlDataProviderManager.getInstance().getTimeGraphProvider(trace, viewElement);
        assertNotNull(timeGraphProvider);
        List<String> expectedStrings = Files.readAllLines(Paths.get("test_traces/simple_dataprovider/expectedTimeGraphTree"));
        Map<Long, String> tree = assertAndGetTree(timeGraphProvider, trace, expectedStrings);
        expectedStrings = Files.readAllLines(Paths.get("test_traces/simple_dataprovider/expectedTimeGraphRows"));
        // The CPU entry does not have entries
        expectedStrings.remove(0);
        assertRows(timeGraphProvider, tree, expectedStrings);
    } finally {
        trace.dispose();
        TmfTraceManager.getInstance().traceClosed(new TmfTraceClosedSignal(this, trace));
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Element(org.w3c.dom.Element) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) Test(org.junit.Test)

Example 14 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class XmlTimeGraphDataProviderTest method testFactory.

/**
 * Test the {@link DataDrivenTimeGraphProviderFactory} class
 */
@Test
public void testFactory() {
    ITmfTrace trace = getTrace();
    assertNotNull(trace);
    try {
        runModule(trace);
        // Get the view element from the file
        Element viewElement = TmfXmlUtils.getElementInFile(TmfXmlTestFiles.DATA_PROVIDER_SIMPLE_FILE.getPath().toOSString(), TmfXmlStrings.TIME_GRAPH_VIEW, TIME_GRAPH_VIEW_ID);
        assertNotNull(viewElement);
        TmfXmlTimeGraphViewCu tgViewCu = TmfXmlTimeGraphViewCu.compile(new AnalysisCompilationData(), viewElement);
        assertNotNull(tgViewCu);
        DataDrivenTimeGraphProviderFactory timeGraphFactory = tgViewCu.generate();
        // Test the factory with a simple trace
        ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> provider = timeGraphFactory.create(trace);
        assertNotNull(provider);
        assertEquals(DataDrivenTimeGraphDataProvider.ID, provider.getId());
        // Test the factory with an ID and state system
        ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, ANALYSIS_ID);
        assertNotNull(module);
        Iterable<@NonNull ITmfStateSystem> stateSystems = module.getStateSystems();
        assertNotNull(stateSystems);
        provider = DataDrivenTimeGraphProviderFactory.create(trace, Objects.requireNonNull(Lists.newArrayList(stateSystems)), getEntries(new AnalysisCompilationData(), viewElement), getvalues(viewElement), ANALYSIS_ID);
        assertNotNull(provider);
        assertEquals(ANALYSIS_ID, provider.getId());
    } finally {
        trace.dispose();
        TmfTraceManager.getInstance().traceClosed(new TmfTraceClosedSignal(this, trace));
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) DataDrivenTimeGraphProviderFactory(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.output.DataDrivenTimeGraphProviderFactory) Element(org.w3c.dom.Element) TmfXmlTimeGraphViewCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlTimeGraphViewCu) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) AnalysisCompilationData(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ITmfAnalysisModuleWithStateSystems(org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 15 with TimeGraphEntryModel

use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel in project tracecompass by tracecompass.

the class XmlTimeGraphDataProviderTest method assertAndGetTree.

private static Map<Long, String> assertAndGetTree(ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> timeGraphProvider, ITmfTrace trace, List<String> expectedStrings) {
    TmfModelResponse<@NonNull TmfTreeModel<@NonNull TimeGraphEntryModel>> treeResponse = timeGraphProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), MONITOR);
    assertNotNull(treeResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
    TmfTreeModel<@NonNull TimeGraphEntryModel> treeModel = treeResponse.getModel();
    assertNotNull(treeModel);
    List<@NonNull TimeGraphEntryModel> xmlEntries = treeModel.getEntries();
    Collections.sort(xmlEntries, Comparator.comparingLong(TimeGraphEntryModel::getId));
    Map<Long, String> map = new HashMap<>();
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        assertTrue("actual entry present at " + i + ": " + expectedString, xmlEntries.size() > i);
        String[] split = expectedString.split(",");
        TimeGraphEntryModel xmlTgEntry = xmlEntries.get(i);
        assertEquals("Checking entry name at " + i, split[0], xmlTgEntry.getName());
        assertEquals("Checking entry start time at " + i, Long.parseLong(split[1]), xmlTgEntry.getStartTime());
        assertEquals("Checking entry end time at " + i, Long.parseLong(split[2]), xmlTgEntry.getEndTime());
        // Check the parent
        long parentId = xmlTgEntry.getParentId();
        if (parentId < 0) {
            assertEquals("Checking empty parent at " + i, split[3], "null");
        } else {
            String parentName = map.get(parentId);
            assertEquals("Checking parent at " + i, split[3], parentName);
        }
        map.put(xmlTgEntry.getId(), xmlTgEntry.getName());
    }
    assertEquals("Extra actual entries", expectedStrings.size(), xmlEntries.size());
    return map;
}
Also used : HashMap(java.util.HashMap) NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) 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)

Aggregations

TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)29 NonNull (org.eclipse.jdt.annotation.NonNull)16 ArrayList (java.util.ArrayList)12 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)11 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)10 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)10 ITimeGraphDataProvider (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider)8 Element (org.w3c.dom.Element)8 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)7 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)7 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 List (java.util.List)6 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)6 Collection (java.util.Collection)5 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)5 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)5 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)5 Status (org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status)4