timing: Cancel previous flame graph build job
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 14 Feb 2017 18:42:09 +0000 (13:42 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Mon, 20 Feb 2017 19:47:51 +0000 (14:47 -0500)
Fixes bug 512195

The flame graph view was previously waiting for the previous job to
finish, waiting to acquire the lock, often in the UI thread. Now the
previous job is cancelled before acquiring the view's lock.

Change-Id: I36562822628e93560eefd26fc89cbf02d9469557
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/91086
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphView.java

index 0d63809ff0d20c3bcaf66f5389b17da2a8f33712..06314d6071be410d7c17a96713af36373dd59694 100644 (file)
@@ -90,14 +90,17 @@ public class FlameGraphView extends TmfView {
     private ITmfTrace fTrace;
 
     private final @NonNull MenuManager fEventMenuManager = new MenuManager();
-    private Action fSortByNameAction;
-    private Action fSortByIdAction;
     /**
      * A plain old semaphore is used since different threads will be competing
      * for the same resource.
      */
+
     private final Semaphore fLock = new Semaphore(1);
 
+    private Action fSortByNameAction;
+    private Action fSortByIdAction;
+    private Job fJob;
+
     /**
      * Constructor
      */
@@ -191,6 +194,10 @@ public class FlameGraphView extends TmfView {
          *
          * 4- on a clean execution
          */
+        Job job = fJob;
+        if (job != null) {
+            job.cancel();
+        }
         try {
             fLock.acquire();
         } catch (InterruptedException e) {
@@ -204,24 +211,28 @@ public class FlameGraphView extends TmfView {
         }
         fTimeGraphViewer.setInput(callGraphAnalysis.getSegmentStore());
         callGraphAnalysis.schedule();
-        Job j = new Job(Messages.CallGraphAnalysis_Execution) {
+        job = new Job(Messages.CallGraphAnalysis_Execution) {
 
             @Override
             protected IStatus run(IProgressMonitor monitor) {
-                if (monitor.isCanceled()) {
+                try {
+                    if (monitor.isCanceled()) {
+                        return Status.CANCEL_STATUS;
+                    }
+                    callGraphAnalysis.waitForCompletion(monitor);
+                    Display.getDefault().asyncExec(() -> {
+                        fTimeGraphViewer.setInput(callGraphAnalysis.getThreadNodes());
+                        fTimeGraphViewer.resetStartFinishTime();
+                    });
+                    return Status.OK_STATUS;
+                } finally {
+                    fJob = null;
                     fLock.release();
-                    return Status.CANCEL_STATUS;
                 }
-                callGraphAnalysis.waitForCompletion(monitor);
-                Display.getDefault().asyncExec(() -> {
-                    fTimeGraphViewer.setInput(callGraphAnalysis.getThreadNodes());
-                    fTimeGraphViewer.resetStartFinishTime();
-                    fLock.release();
-                });
-                return Status.OK_STATUS;
             }
         };
-        j.schedule();
+        fJob = job;
+        job.schedule();
     }
 
     /**
This page took 0.027384 seconds and 5 git commands to generate.