From a76f106746cf91aa14ccf8422c8e6508e2685359 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 28 Sep 2012 14:54:31 -0400 Subject: [PATCH 1/1] tmf: Add an ID to each state system that gets built When requesting to build a state system, we now need to specify a String ID. This ID will be returned with the "state system build completed" signal, so that a view can differentiate between many state systems that could be associated to the same trace. Change-Id: I699d46f3a3cf7300f71282f505eeb40e08cb4d1e Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/7987 --- .../headless/BasicStateSystemExample.java | 3 ++- .../StateSystemFullHistoryTest.java | 9 ++++++--- .../kernel/core/trace/CtfKernelTrace.java | 8 +++++++- .../tmf/core/statesystem/HistoryBuilder.java | 14 +++++++++---- .../signal/TmfStateSystemBuildCompleted.java | 20 +++++++++++++++++-- .../core/statesystem/StateSystemManager.java | 9 +++++++-- .../tmf/core/statistics/TmfStatistics.java | 5 ++++- 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java index 50b165e4b1..7ef729889d 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/BasicStateSystemExample.java @@ -43,7 +43,8 @@ public class BasicStateSystemExample { try { File newStateFile = new File("/tmp/helloworldctf.ht"); //$NON-NLS-1$ IStateChangeInput input = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - ITmfStateSystem ss = StateSystemManager.loadStateHistory(newStateFile, input, true); + String name = "test-ss"; //$NON-NLS-1$ + ITmfStateSystem ss = StateSystemManager.loadStateHistory(newStateFile, input, name, true); requestExample(ss); } catch (TmfTraceException e) { diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java index f3919ff608..f4aca60230 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java @@ -52,6 +52,9 @@ public class StateSystemFullHistoryTest { /* Offset in the trace + start time of the trace */ private final static long interestingTimestamp1 = 18670067372290L + 1331649577946812237L; + /* ID we give to the state system we build */ + private static final String STATE_ID = "test-ss"; + protected static String getTestFileName() { return "/tmp/statefile.ht"; //$NON-NLS-1$ } @@ -62,7 +65,7 @@ public class StateSystemFullHistoryTest { stateFileBenchmark = new File(getTestFileName() + ".benchmark"); //$NON-NLS-1$ try { input = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - ssq = StateSystemManager.loadStateHistory(stateFile, input, true); + ssq = StateSystemManager.loadStateHistory(stateFile, input, STATE_ID, true); } catch (Exception e) { e.printStackTrace(); } @@ -92,7 +95,7 @@ public class StateSystemFullHistoryTest { ITmfStateSystem ssb2; input2 = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true); + ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, STATE_ID, true); assertEquals(CtfTestFiles.startTime, ssb2.getStartTime()); assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime()); @@ -103,7 +106,7 @@ public class StateSystemFullHistoryTest { ITmfStateSystem ssb2; /* 'newStateFile' should have already been created */ - ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true); + ssb2 = StateSystemManager.loadStateHistory(stateFile, null, STATE_ID, true); assertNotNull(ssb2); assertEquals(CtfTestFiles.startTime, ssb2.getStartTime()); 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 fb4f26d0e3..c7eebfb250 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 @@ -40,6 +40,12 @@ public class CtfKernelTrace extends CtfTmfTrace { */ public final static String HISTORY_TREE_FILE_NAME = "stateHistory.ht"; //$NON-NLS-1$ + /** + * ID of the state system we will build + * @since 2.0 + * */ + public static final String STATE_ID = "org.eclipse.linuxtools.lttng2.kernel"; //$NON-NLS-1$ + /** * Default constructor */ @@ -84,6 +90,6 @@ 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, false); + this.ss = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false); } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java index 071b866fc8..92cc984630 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java @@ -47,6 +47,7 @@ public class HistoryBuilder extends TmfComponent { private final IStateChangeInput sci; private final StateSystem ss; private final IStateHistoryBackend hb; + private final String id; private boolean started = true; /* Don't handle signals until we're ready */ /** @@ -56,24 +57,29 @@ public class HistoryBuilder extends TmfComponent { * The input plugin to use. This is required. * @param backend * The backend storage to use. + * @param id + * The ID (or name) of the state system that will be built. This + * can be useful in cases where there are more than 1 state + * system per trace/experiment. * @param buildManually * Should we build this history in-band or not. True means we * will start the building ourselves and block the caller until - * construction is done. False (out-of-band) means we will - * start listening for the signal and return immediately. Another + * construction is done. False (out-of-band) means we will start + * listening for the signal and return immediately. Another * signal will be sent when finished. * @throws IOException * Is thrown if anything went wrong (usually with the storage * backend) */ public HistoryBuilder(IStateChangeInput stateChangeInput, - IStateHistoryBackend backend, boolean buildManually) + IStateHistoryBackend backend, String id, boolean buildManually) throws IOException { if (stateChangeInput == null || backend == null) { throw new IllegalArgumentException(); } sci = stateChangeInput; hb = backend; + this.id = id; ss = new StateSystem(hb, true); sci.assignTargetStateSystem(ss); @@ -189,7 +195,7 @@ public class HistoryBuilder extends TmfComponent { /* We won't broadcast the signal if the request was cancelled */ } else { /* Broadcast the signal saying the history is done building */ - doneSig = new TmfStateSystemBuildCompleted(this, sci.getTrace()); + doneSig = new TmfStateSystemBuildCompleted(this, sci.getTrace(), id); TmfSignalManager.dispatchSignal(doneSig); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfStateSystemBuildCompleted.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfStateSystemBuildCompleted.java index d94e893c7c..2f0721033c 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfStateSystemBuildCompleted.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfStateSystemBuildCompleted.java @@ -23,6 +23,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; public class TmfStateSystemBuildCompleted extends TmfSignal { private final ITmfTrace fTrace; + private final String fID; /** * Constructor @@ -31,10 +32,16 @@ public class TmfStateSystemBuildCompleted extends TmfSignal { * Object sending this signal * @param trace * The state system of which trace just finished building + * @param id + * ID associated with this state system. This can be used in the + * case of a trace containing multiple state systems, to + * differentiate between them. + * @since 2.0 */ - public TmfStateSystemBuildCompleted(Object source, ITmfTrace trace) { + public TmfStateSystemBuildCompleted(Object source, ITmfTrace trace, String id) { super(source); fTrace = trace; + fID = id; } /** @@ -44,12 +51,21 @@ public class TmfStateSystemBuildCompleted extends TmfSignal { return fTrace; } + /** + * @return The ID of the state system that just finished building + * @since 2.0 + */ + public String getID() { + return fID; + } + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { - return "[TmfStateSystemBuildCompleted (" + fTrace.toString() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ + return "[TmfStateSystemBuildCompleted (trace = " + fTrace.toString() + //$NON-NLS-1$ + ", ID = " + fID + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java index b73714ee3e..f7a62c2043 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateSystemManager.java @@ -48,6 +48,11 @@ public abstract class StateSystemManager extends TmfComponent { * The IStateChangeInput to use for building the history file. It * may be required even if we are opening an already-existing * history (ie, for partial histories). + * @param id + * The ID, or name, to give to the state system we will build. + * The signal that when be sent when the construction is finished + * will carry this ID. It has no effect if the file already + * exists. * @param buildManually * If false, the construction will wait for a signal before * starting. If true, it will build everything right now and @@ -60,7 +65,7 @@ public abstract class StateSystemManager extends TmfComponent { * @since 2.0 */ public static ITmfStateSystem loadStateHistory(File htFile, - IStateChangeInput htInput, boolean buildManually) + IStateChangeInput htInput, String id, boolean buildManually) throws TmfTraceException { ITmfStateSystem ss; IStateHistoryBackend htBackend; @@ -92,7 +97,7 @@ public abstract class StateSystemManager extends TmfComponent { try { htBackend = new ThreadedHistoryTreeBackend(htFile, htInput.getStartTime(), QUEUE_SIZE); - builder = new HistoryBuilder(htInput, htBackend, buildManually); + builder = new HistoryBuilder(htInput, htBackend, id, buildManually); } catch (IOException e) { /* * If it fails here however, it means there was a problem writing to diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatistics.java index 960b2aebb4..efcd39f175 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatistics.java @@ -41,6 +41,9 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; public class TmfStatistics implements ITmfStatistics { + /** ID for the statistics state system */ + public static final String STATE_ID = "org.eclipse.linuxtools.tmf.statistics"; //$NON-NLS-1$ + /* Filename the "statistics state history" file will have */ private static final String STATS_STATE_FILENAME = "statistics.ht"; //$NON-NLS-1$ @@ -74,7 +77,7 @@ public class TmfStatistics implements ITmfStatistics { final File htFile = new File(supplDirectory + File.separator + STATS_STATE_FILENAME); final IStateChangeInput htInput = new StatsStateProvider(trace); - this.stats = StateSystemManager.loadStateHistory(htFile, htInput, false); + this.stats = StateSystemManager.loadStateHistory(htFile, htInput, STATE_ID, false); } // ------------------------------------------------------------------------ -- 2.34.1