From 855a1bfb5c9237ca0a4b009681734254aebd6567 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 18 May 2012 14:06:21 -0400 Subject: [PATCH] tmf: Use TMF signals to trigger the state history building Instead of sending an event request on its own, the history builder will now listen to the TMF signals to control the sending and cancelling of the event requests. This allows us to benefit from the coalescing, which makes sure we don't read the trace more often than we need to. Signed-off-by: Alexandre Montplaisir --- .../StateSystemFullHistoryTest.java | 4 +- .../StateSystemFullThreadedHistoryTest.java | 4 +- .../kernel/core/trace/CtfKernelTrace.java | 1 - .../tmf/core/statesystem/HistoryBuilder.java | 103 +++++++++++++----- 4 files changed, 80 insertions(+), 32 deletions(-) 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 a5f8b825df..ccfb8bd65a 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 @@ -68,7 +68,7 @@ public class StateSystemFullHistoryTest { } catch (Exception e) { e.printStackTrace(); } - builder.run(); + builder.startBuilding(null); ssb = builder.getStateSystemBuilder(); } @@ -99,7 +99,7 @@ public class StateSystemFullHistoryTest { zeinput = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); zehp = new HistoryTreeBackend(stateFileBenchmark, zeinput.getStartTime()); zebuilder = new HistoryBuilder(zeinput, zehp); - zebuilder.run(); + zebuilder.startBuilding(null); assertEquals(CtfTestFiles.startTime, zehp.getStartTime()); assertEquals(CtfTestFiles.endTime, zehp.getEndTime()); diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullThreadedHistoryTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullThreadedHistoryTest.java index 1a39a95212..9a79d37098 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullThreadedHistoryTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullThreadedHistoryTest.java @@ -50,7 +50,7 @@ public class StateSystemFullThreadedHistoryTest extends } catch (Exception e) { e.printStackTrace(); } - builder.run(); + builder.startBuilding(null); ssb = builder.getStateSystemBuilder(); } @@ -66,7 +66,7 @@ public class StateSystemFullThreadedHistoryTest extends zehp = new ThreadedHistoryTreeBackend(stateFileBenchmark, zeinput.getStartTime(), 2000); zebuilder = new HistoryBuilder(zeinput, zehp); - zebuilder.run(); + zebuilder.startBuilding(null); } catch (Exception e) { e.printStackTrace(); } 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 79b6936b36..dc98c11b6f 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 @@ -111,6 +111,5 @@ public class CtfKernelTrace extends CtfTmfTrace { } this.ss = builder.getStateSystemQuerier(); - builder.run(); /* Start the construction of the history */ } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/HistoryBuilder.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/HistoryBuilder.java index 15e373f921..ae0678dfda 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/HistoryBuilder.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/HistoryBuilder.java @@ -13,14 +13,21 @@ package org.eclipse.linuxtools.tmf.core.statesystem; import java.io.IOException; +import java.util.concurrent.Semaphore; import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateHistorySystem; +import org.eclipse.linuxtools.tmf.core.component.TmfComponent; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; +import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; /** * This is the high-level wrapper around the State History and its input and @@ -33,7 +40,12 @@ import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; * @author alexmont * */ -public class HistoryBuilder implements Runnable { +public class HistoryBuilder extends TmfComponent { + + private static final Semaphore hbSem = new Semaphore(1); + + private ITmfEventRequest currentRequest = null; + private boolean isRunning = false; private final IStateChangeInput sci; private final StateHistorySystem shs; @@ -56,7 +68,6 @@ public class HistoryBuilder implements Runnable { if (stateChangeInput == null || backend == null) { throw new IllegalArgumentException(); } - sci = stateChangeInput; hb = backend; shs = new StateHistorySystem(hb, true); @@ -81,21 +92,6 @@ public class HistoryBuilder implements Runnable { return new StateHistorySystem(hb, false); } - @Override - public void run() { - /* Send a TMF request for all the events in the trace */ - final ITmfEventRequest request; - request = new StateSystemBuildRequest(this); - - /* Submit the request and wait for completion */ - sci.getTrace().sendRequest(request); - try { - request.waitForCompletion(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - /** * Return a read/write reference to the state system object that was * created. @@ -116,18 +112,70 @@ public class HistoryBuilder implements Runnable { return shs; } + // ------------------------------------------------------------------------ + // Signal handlers + // ------------------------------------------------------------------------ + + /** + * Signal handler to start building the configured state history. + * + * This could also be called by anyone to trigger the building of the + * history without using any TMF signals. Simply pass 'null' as a parameter + * then. + * + * @param signal The signal that triggered the build + */ + @TmfSignalHandler + public void startBuilding(final TmfExperimentRangeUpdatedSignal signal) { + /* Start the construction of the history if it's not started yet */ + if (!this.isRunning) { + hbSem.acquireUninterruptibly(); + currentRequest = new StateSystemBuildRequest(this); + isRunning = true; + sci.getTrace().sendRequest(currentRequest); + } + } + /** - * @name Methods reserved for the request object below + * Signal handler to cancel any currently running requests. It will delete + * any incomplete file that might have been created. + * + * This could also be called by anyone to cancel the current request without + * using any TMF signals. Simply pass 'null' as a parameter then. + * + * @param signal */ + @TmfSignalHandler + public void cancelCurrentBuild(final TmfExperimentSelectedSignal signal) { + /* + * We've switched experiments (or re-opened the current one), so stop + * whatever request is currently running. + */ + if (this.isRunning && currentRequest != null) { + currentRequest.cancel(); + } + } + + // ------------------------------------------------------------------------ + // Methods reserved for the request object below + // ------------------------------------------------------------------------ + /** Get the input plugin object */ IStateChangeInput getInputPlugin() { return sci; } - /** Tell the backend to cleanup if the request is cancelled */ - void cleanup() { - hb.removeFiles(); + /** Shutdown this builder object when the request is over */ + void finish(boolean deleteFile) { + sci.dispose(); + if (deleteFile) { + hb.removeFiles(); + } + currentRequest = null; + isRunning = false; + TmfSignalManager.deregister(this); + hbSem.release(); } } @@ -158,18 +206,19 @@ class StateSystemBuildRequest extends TmfEventRequest { @Override public void handleSuccess() { - // + super.handleSuccess(); + builder.finish(false); } @Override public void handleCancel() { - sci.dispose(); - builder.cleanup(); + super.handleCancel(); + builder.finish(true); } @Override - public void handleCompleted() { - super.handleCompleted(); - sci.dispose(); + public void handleFailure() { + super.handleFailure(); + builder.finish(true); } } \ No newline at end of file -- 2.34.1