tmf: Split ITmfStateSystem.waitUntilBuilt() in separate methods
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 15 Jan 2014 18:27:49 +0000 (13:27 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 16 Jan 2014 03:20:43 +0000 (22:20 -0500)
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 <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/20677
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Hudson CI
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java

index 3a5df77ef306faf1f3725a543192d080ac67bc45..e0fb7a0c29bf6dd74b751af59110e1ec50081a88 100644 (file)
@@ -211,7 +211,11 @@ public class ControlFlowView extends AbstractTimeGraphView {
                 ArrayList<ControlFlowEntry> 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();
index ceaac40573fad8a1475202f9af3c8f6a4fd7ae3b..4746386c1810e6bef9b62988ae48115dbe315f8d 100644 (file)
@@ -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();
index 4a27539e688f383e5b2366d885404f31bcccd989..b26245f95d5092f200aa1dfcfbd6e51a187936aa 100644 (file)
@@ -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
index a5f37cc6804014edd63bdffd6edd94cff205ee57..99cd49f964363898ab78c1f09f4cbba046b2b3cb 100644 (file)
@@ -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
index 76ae92c2e7ce1bc1c1e63e2b58cb0d4de6f329fe..1a2ddedfc1d66484d9dd64f25bf9859f36c7193f 100644 (file)
@@ -214,7 +214,8 @@ public class TmfStateStatistics implements ITmfStatistics {
         final List<Long> 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);
     }
 
index 828ad3b572addd4d7accca3667ba5c245f6857a8..ed716ca76524d7587f05c3586117c6c79b64bbdf 100644 (file)
@@ -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<ThreadEntry> 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));
This page took 0.031444 seconds and 5 git commands to generate.