From 368fa3911ca11d1451ffde6d5c9f48ef6f800e0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Tue, 14 Feb 2017 13:42:09 -0500 Subject: [PATCH] timing: Cancel previous flame graph build job MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://git.eclipse.org/r/91086 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- .../timing/ui/flamegraph/FlameGraphView.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphView.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphView.java index 0d63809ff0..06314d6071 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphView.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphView.java @@ -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(); } /** -- 2.34.1