From 2002c638b41ba508da46e0fc7083106c279627d0 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 15 Jan 2014 13:27:49 -0500 Subject: [PATCH] tmf: Split ITmfStateSystem.waitUntilBuilt() in separate methods Decouple the return value of waitUntilBuilt() in a new isCancelled() method, so that it can be checked independently. This is because we are planning to add a new waitUntilBuilt(long) method with a timeout, and that one will have to return a boolean to indicate if it returned due to the thing being built, or due to the timeout. We will still want to check for the cancellation state afterwards. Furthermore, it would be very confusing if both methods (with and without the timeout) returned a boolean that meant different things. Change-Id: If7a954d2368d55c99e30e31e17e39b39bca5f432 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/20677 Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse Tested-by: Hudson CI --- .../ui/views/controlflow/ControlFlowView.java | 6 +++- .../ui/views/resources/ResourcesView.java | 6 +++- .../tmf/core/statesystem/StateSystem.java | 8 +++-- .../tmf/core/statesystem/ITmfStateSystem.java | 22 ++++++++++---- .../core/statistics/TmfStateStatistics.java | 9 ++++-- .../tmf/ui/views/callstack/CallStackView.java | 29 +++++++++++++++---- 6 files changed, 62 insertions(+), 18 deletions(-) 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 3a5df77ef3..e0fb7a0c29 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 @@ -211,7 +211,11 @@ public class ControlFlowView extends AbstractTimeGraphView { ArrayList entryList = new ArrayList<>(); LttngKernelTrace ctfKernelTrace = (LttngKernelTrace) aTrace; ITmfStateSystem ssq = ctfKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID); - if (!ssq.waitUntilBuilt()) { + if (ssq == null) { + return; + } + ssq.waitUntilBuilt(); + if (ssq.isCancelled()) { return; } long start = ssq.getStartTime(); 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 ceaac40573..4746386c18 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 @@ -98,7 +98,11 @@ public class ResourcesView extends AbstractTimeGraphView { if (aTrace instanceof LttngKernelTrace) { LttngKernelTrace lttngKernelTrace = (LttngKernelTrace) aTrace; ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID); - if (!ssq.waitUntilBuilt()) { + if (ssq == null) { + return; + } + ssq.waitUntilBuilt(); + if (ssq.isCancelled()) { return; } long startTime = ssq.getStartTime(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java index 4a27539e68..b26245f95d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java @@ -101,13 +101,17 @@ public class StateSystem implements ITmfStateSystemBuilder { } @Override - public boolean waitUntilBuilt() { + public boolean isCancelled() { + return buildCancelled; + } + + @Override + public void waitUntilBuilt() { try { finishedLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } - return !buildCancelled; } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java index a5f37cc680..99cd49f964 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java @@ -47,6 +47,18 @@ public interface ITmfStateSystem { */ long getCurrentEndTime(); + /** + * Check if the construction of this state system was cancelled or not. If + * false is returned, it can mean that the building was finished + * successfully, or that it is still ongoing. You can check independently + * with {@link #waitUntilBuilt()} if it is finished or not. + * + * @return If the construction was cancelled or not. In true is returned, no + * queries should be run afterwards. + * @since 3.0 + */ + boolean isCancelled(); + /** * While it's possible to query a state history that is being built, * sometimes we might want to wait until the construction is finished before @@ -56,12 +68,12 @@ public interface ITmfStateSystem { * building. If it's already built (ie, opening a pre-existing file) this * should return immediately. * - * @return If the build was successful. If false is returned, this either - * means there was a problem during the build, or it got cancelled - * before it could finished. In that case, no queries should be run - * afterwards. + * You should always check with {@link #isCancelled()} if it is safe to + * query this state system before doing queries. + * + * @since 3.0 */ - boolean waitUntilBuilt(); + void waitUntilBuilt(); /** * Notify the state system that the trace is being closed, so it should diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java index 76ae92c2e7..1a2ddedfc1 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java @@ -214,7 +214,8 @@ public class TmfStateStatistics implements ITmfStatistics { final List list = new LinkedList<>(); final long increment = (end - start) / nb; - if (!totalsStats.waitUntilBuilt()) { + totalsStats.waitUntilBuilt(); + if (totalsStats.isCancelled()) { return list; } @@ -450,8 +451,10 @@ public class TmfStateStatistics implements ITmfStatistics { * @return If both state systems were built successfully */ private boolean waitUntilBuilt() { - boolean check1 = totalsStats.waitUntilBuilt(); - boolean check2 = typesStats.waitUntilBuilt(); + totalsStats.waitUntilBuilt(); + typesStats.waitUntilBuilt(); + boolean check1 = !totalsStats.isCancelled(); + boolean check2 = !typesStats.isCancelled(); return (check1 && check2); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java index 828ad3b572..ed716ca765 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java @@ -443,7 +443,11 @@ public class CallStackView extends TmfView { long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth); for (ThreadEntry threadEntry : fZoomEntryList) { ITmfStateSystem ss = threadEntry.fThreadTrace.getStateSystems().get(CallStackStateProvider.ID); - if (ss == null || !ss.waitUntilBuilt()) { + if (ss == null) { + continue; + } + ss.waitUntilBuilt(); + if (ss.isCancelled()) { continue; } for (ITimeGraphEntry child : threadEntry.getChildren()) { @@ -790,10 +794,13 @@ public class CallStackView extends TmfView { return; } ITmfStateSystem ss = aTrace.getStateSystems().get(CallStackStateProvider.ID); - if (ss == null || !ss.waitUntilBuilt()) { - String threadName = Messages.CallStackView_StackInfoNotAvailable + ' ' + '(' + aTrace.getName() + ')'; - ThreadEntry threadEntry = new ThreadEntry(aTrace, threadName, -1, 0, 0); - entryList.add(threadEntry); + if (ss == null) { + addUnavailableEntry(aTrace, entryList); + continue; + } + ss.waitUntilBuilt(); + if (ss.isCancelled()) { + addUnavailableEntry(aTrace, entryList); continue; } long startTime = ss.getStartTime(); @@ -839,6 +846,12 @@ public class CallStackView extends TmfView { } } + private void addUnavailableEntry(ITmfTrace trace, List list) { + String threadName = Messages.CallStackView_StackInfoNotAvailable + ' ' + '(' + trace.getName() + ')'; + ThreadEntry threadEntry = new ThreadEntry(trace, threadName, -1, 0, 0); + list.add(threadEntry); + } + private void buildStatusEvents(ITmfTrace trace, CallStackEntry entry, IProgressMonitor monitor) { ITmfStateSystem ss = entry.getTrace().getStateSystems().get(CallStackStateProvider.ID); long start = ss.getStartTime(); @@ -914,7 +927,11 @@ public class CallStackView extends TmfView { } for (ThreadEntry threadEntry : fEntryList) { ITmfStateSystem ss = threadEntry.fThreadTrace.getStateSystems().get(CallStackStateProvider.ID); - if (ss == null || !ss.waitUntilBuilt()) { + if (ss == null) { + continue; + } + ss.waitUntilBuilt(); + if (ss.isCancelled()) { continue; } long queryTime = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), time)); -- 2.34.1