From a51b2b9f7cefd6ae08ba415f1c1bd3b0cdb46eca Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Mon, 19 Nov 2012 15:40:48 -0500 Subject: [PATCH] tmf: Consolidate all state systems in ITmfTrace In the initial design, a trace would have only one single state system. ITmfTrace.getStateSystem() would do the job. Then, the need for different state systems for different trace types arose. Up until now, we've used a hybrid approach, where we keep the interface method the same, but a given user/view could access a specific state system by casting the trace in the specific type. So far so good. But now, we are reaching the point where we can need to define *many* state systems for a single trace type (ie, Matthew's CPU usage view). I think we now need to centralize all of a trace's state systems in the ITmfTrace interface itself. This patch changes ITmfTrace's getStateSystem() to add the state's ID as parameter (state systems already define a unique ID, so we can reuse that one). It also adds a listStateSystems() method to list the current registered ones for this trace. The implementation in TmfTrace uses a HashMap. It's very simple, and gives a maximum amount of flexibility ; sub-classes can decide to overwrite a superclass' state history, decide to run them or not, etc. Change-Id: I6c819ad8987767015543dc54b613ec3cdc6ea50d Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/8767 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../kernel/core/trace/CtfKernelTrace.java | 16 +++----- .../ControlFlowPresentationProvider.java | 3 +- .../ui/views/controlflow/ControlFlowView.java | 8 ++-- .../ResourcesPresentationProvider.java | 17 ++++----- .../ui/views/resources/ResourcesView.java | 8 ++-- .../tests/ctfadaptor/CtfTmfTraceTest.java | 11 ------ .../core/tests/trace/TmfExperimentTest.java | 25 +++++++++++++ .../tmf/core/tests/trace/TmfTraceTest.java | 25 +++++++++++++ .../tmf/core/ctfadaptor/CtfTmfTrace.java | 12 ------ .../linuxtools/tmf/core/trace/ITmfTrace.java | 20 +++++++++- .../linuxtools/tmf/core/trace/TmfTrace.java | 37 +++++++++++++++---- 11 files changed, 121 insertions(+), 61 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java index 7f412fe775..3ce5be1d82 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java @@ -24,6 +24,7 @@ import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager; /** @@ -76,6 +77,8 @@ public class CtfKernelTrace extends CtfTmfTrace { @Override protected void buildStateSystem() throws TmfTraceException { + super.buildStateSystem(); + /* Set up the path to the history tree file we'll use */ IResource resource = this.getResource(); String supplDirectory = null; @@ -90,17 +93,8 @@ public class CtfKernelTrace extends CtfTmfTrace { final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME); final IStateChangeInput htInput = new CtfKernelStateInput(this); - this.ss = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false); - } - - @Override - public synchronized void dispose() { - /* Clean up the state system */ - if (ss != null) { - ss.dispose(); - } - super.dispose(); + ITmfStateSystem ss = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false); + fStateSystems.put(STATE_ID, ss); } - } diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java index cc5f51f153..1ab8fddef8 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java @@ -19,6 +19,7 @@ import java.util.Map; import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; +import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -104,7 +105,7 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid Map retMap = new LinkedHashMap(); if (event instanceof ControlFlowEvent) { ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); int tid = entry.getThreadId(); try { diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java index 3a04186cdf..f25f82523c 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java @@ -508,7 +508,7 @@ public class ControlFlowView extends TmfView { } if (trace instanceof CtfKernelTrace) { CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace; - ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(); + ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID); if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) { List currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$ for (int currentThreadQuark : currentThreadQuarks) { @@ -614,7 +614,7 @@ public class ControlFlowView extends TmfView { if (aTrace instanceof CtfKernelTrace) { ArrayList entryList = new ArrayList(); CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) aTrace; - ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(); + ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID); if (!ssq.waitUntilBuilt()) { return; } @@ -723,7 +723,7 @@ public class ControlFlowView extends TmfView { } private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, IProgressMonitor monitor) { - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); long start = ssq.getStartTime(); long end = ssq.getCurrentEndTime() + 1; long resolution = Math.max(1, (end - start) / fDisplayWidth); @@ -751,7 +751,7 @@ public class ControlFlowView extends TmfView { if (endTime <= startTime) { return null; } - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); List eventList = null; try { int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS); diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesPresentationProvider.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesPresentationProvider.java index 3e3012bdba..d41c737339 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesPresentationProvider.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesPresentationProvider.java @@ -20,6 +20,7 @@ import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type; +import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -165,19 +166,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider if (status == StateValues.CPU_STATUS_IRQ) { // In IRQ state get the IRQ that caused the interruption ResourcesEntry entry = (ResourcesEntry) event.getEntry(); - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); int cpu = entry.getId(); - ITmfStateSystem ss = entry.getTrace().getStateSystem(); try { List fullState = ss.queryFullState(event.getTime()); List irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$ for (int irqQuark : irqQuarks) { if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) { - ITmfStateInterval value = ssq.querySingleState(event.getTime(), irqQuark); + ITmfStateInterval value = ss.querySingleState(event.getTime(), irqQuark); if (!value.getStateValue().isNull()) { - int irq = Integer.parseInt(ssq.getAttributeName(irqQuark)); + int irq = Integer.parseInt(ss.getAttributeName(irqQuark)); retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq)); } break; @@ -195,19 +195,18 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider } else if (status == StateValues.CPU_STATUS_SOFTIRQ) { // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption ResourcesEntry entry = (ResourcesEntry) event.getEntry(); - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ss = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); int cpu = entry.getId(); - ITmfStateSystem ss = entry.getTrace().getStateSystem(); try { List fullState = ss.queryFullState(event.getTime()); List softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$ for (int softIrqQuark : softIrqQuarks) { if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) { - ITmfStateInterval value = ssq.querySingleState(event.getTime(), softIrqQuark); + ITmfStateInterval value = ss.querySingleState(event.getTime(), softIrqQuark); if (!value.getStateValue().isNull()) { - int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark)); + int softIrq = Integer.parseInt(ss.getAttributeName(softIrqQuark)); retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq)); } break; @@ -225,7 +224,7 @@ public class ResourcesPresentationProvider extends TimeGraphPresentationProvider } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL){ // In running state get the current tid ResourcesEntry entry = (ResourcesEntry) event.getEntry(); - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); try { retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.ABSOLUTE, Resolution.NANOSEC)); diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java index f411f37934..9328860ee5 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java @@ -268,7 +268,7 @@ public class ResourcesView extends TmfView { } long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth); for (TraceEntry traceEntry : fZoomEntryList) { - if (!traceEntry.fKernelTrace.getStateSystem().waitUntilBuilt()) { + if (!traceEntry.fKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID).waitUntilBuilt()) { return; } for (ITimeGraphEntry child : traceEntry.getChildren()) { @@ -497,7 +497,7 @@ public class ResourcesView extends TmfView { } if (aTrace instanceof CtfKernelTrace) { CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) aTrace; - ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(); + ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID); if (!ssq.waitUntilBuilt()) { return; } @@ -547,7 +547,7 @@ public class ResourcesView extends TmfView { return; } CtfKernelTrace ctfKernelTrace = traceEntry.getTrace(); - ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(); + ITmfStateSystem ssq = ctfKernelTrace.getStateSystem(CtfKernelTrace.STATE_ID); long startTime = ssq.getStartTime(); long endTime = ssq.getCurrentEndTime() + 1; long resolution = (endTime - startTime) / fDisplayWidth; @@ -562,7 +562,7 @@ public class ResourcesView extends TmfView { private static List getEventList(ResourcesEntry entry, long startTime, long endTime, long resolution, boolean includeNull, IProgressMonitor monitor) { - ITmfStateSystem ssq = entry.getTrace().getStateSystem(); + ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); startTime = Math.max(startTime, ssq.getStartTime()); endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1); if (endTime <= startTime) { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java index 9998a2063f..576934fbaa 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java @@ -32,7 +32,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.junit.After; import org.junit.Before; @@ -93,7 +92,6 @@ public class CtfTmfTraceTest { assertEquals(1000, result.getCacheSize()); assertEquals(0L, result.getNbEvents()); assertEquals(0L, result.getStreamingInterval()); - assertNull(result.getStateSystem()); assertNull(result.getResource()); assertEquals(1000, result.getQueueSize()); assertNull(result.getType()); @@ -283,15 +281,6 @@ public class CtfTmfTraceTest { assertNotNull(result); } - /** - * Run the IStateSystemQuerier getStateSystem() method test. - */ - @Test - public void testGetStateSystem() { - ITmfStateSystem result = fixture.getStateSystem(); - assertNull(result); - } - /** * Run the long getStreamingInterval() method test. */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index c174c0a200..34e51611c7 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Collection; import java.util.Vector; import junit.framework.TestCase; @@ -33,6 +34,8 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; +import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; @@ -170,6 +173,28 @@ public class TmfExperimentTest extends TestCase { assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile()); } + // ------------------------------------------------------------------------ + // State system and statistics methods + // ------------------------------------------------------------------------ + + public void testGetStatistics() { + /* There should not be any experiment-specific statistics */ + ITmfStatistics stats = fExperiment.getStatistics(); + assertNull(stats); + } + + public void testGetStateSystem() { + /* There should not be any experiment-specific state system */ + ITmfStateSystem ss = fExperiment.getStateSystem("something"); + assertNull(ss); + } + + public void testListStateSystem() { + Collection sss = fExperiment.listStateSystems(); + assertNotNull(sss); + assertEquals(0, sss.size()); + } + // ------------------------------------------------------------------------ // seekEvent by location // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index b104fddfde..1b957a8416 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Collection; import java.util.Vector; import junit.framework.TestCase; @@ -33,6 +34,8 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; +import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; @@ -521,6 +524,28 @@ public class TmfTraceTest extends TestCase { trace.dispose(); } + // ------------------------------------------------------------------------ + // State system and statistics methods + // ------------------------------------------------------------------------ + + public void testGetStatistics() { + /* Should be null in unit tests */ + ITmfStatistics stats = fTrace.getStatistics(); + assertNull(stats); + } + + public void testGetStateSystem() { + /* There should be no state system registered so far */ + ITmfStateSystem ss = fTrace.getStateSystem("something"); + assertNull(ss); + } + + public void testListStateSystem() { + Collection sss = fTrace.listStateSystems(); + assertNotNull(sss); + assertEquals(0, sss.size()); + } + // ------------------------------------------------------------------------ // seekEvent on location (note: does not reliably set the rank) // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index f1b6427a27..f3ce15fd65 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -19,7 +19,6 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; @@ -46,9 +45,6 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { // Fields //------------------------------------------- - /** Reference to the state system assigned to this trace */ - protected ITmfStateSystem ss = null; - /* Reference to the CTF Trace */ private CTFTrace fTrace; @@ -246,14 +242,6 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser { return event; } - /** - * @since 2.0 - */ - @Override - public ITmfStateSystem getStateSystem() { - return this.ss; - } - /** * gets the CTFtrace that this is wrapping * @return the CTF trace diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index b42a9d96fe..340cfdf948 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -13,6 +13,8 @@ package org.eclipse.linuxtools.tmf.core.trace; +import java.util.Collection; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; @@ -180,10 +182,24 @@ public interface ITmfTrace extends ITmfDataProvider { public ITmfStatistics getStatistics(); /** - * @return The state system that is associated with this trace + * Retrieve a state system that belongs to this trace + * + * @param id + * The ID of the state system to retrieve. + * @return The state system that is associated with this trace and ID, or + * 'null' if such a match doesn't exist. + * @since 2.0 + */ + public ITmfStateSystem getStateSystem(String id); + + /** + * Return the list of existing state systems registered with this trace. + * + * @return A Collection view of the available state systems. The collection + * could be empty, but should not be null. * @since 2.0 */ - public ITmfStateSystem getStateSystem(); + public Collection listStateSystems(); // ------------------------------------------------------------------------ // Trace characteristics getters diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index e59637fb1f..af8a94c98b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -14,6 +14,9 @@ package org.eclipse.linuxtools.tmf.core.trace; import java.io.File; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -102,6 +105,16 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { // The current selected range private TmfTimeRange fCurrentRange = TmfTimeRange.NULL_RANGE; + /** + * The collection of state systems that are registered with this trace. Each + * sub-class can decide to add its (one or many) state system to this map + * during their {@link #buildStateSystem()}. + * + * @since 2.0 + */ + protected final Map fStateSystems = + new HashMap(); + // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ @@ -293,7 +306,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { protected void buildStateSystem() throws TmfTraceException { /* * Nothing is done in the base implementation, please specify - * how/if to build a state system in derived classes. + * how/if to register a new state system in derived classes. */ return; } @@ -312,6 +325,12 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { if (fStatistics != null) { fStatistics.dispose(); } + + /* Clean up the state systems */ + for (ITmfStateSystem ss : fStateSystems.values()) { + ss.dispose(); + } + super.dispose(); } @@ -385,12 +404,16 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { * @since 2.0 */ @Override - public ITmfStateSystem getStateSystem() { - /* - * By default, no state system is used. Sub-classes can specify their - * own behaviour. - */ - return null; + public final ITmfStateSystem getStateSystem(String id) { + return fStateSystems.get(id); + } + + /** + * @since 2.0 + */ + @Override + public final Collection listStateSystems() { + return fStateSystems.keySet(); } // ------------------------------------------------------------------------ -- 2.34.1