From d4461ac66fa315319d96f62afe94f5825708b14c Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Tue, 10 Sep 2019 18:55:49 +0300 Subject: [PATCH] cancel dumps as early as possible GitOrigin-RevId: a40937891b1b1d316e9d6c3bf5257d92da3d8d79 --- .../com/intellij/diagnostic/PerformanceWatcher.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java index eb21393a13d0..5a5b9ca802cb 100644 --- a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java +++ b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java @@ -45,7 +45,7 @@ public final class PerformanceWatcher implements Disposable { private static final int TOLERABLE_LATENCY = 100; private static final String THREAD_DUMPS_PREFIX = "threadDumps-"; private ScheduledFuture myThread; - private SamplingTask myDumpTask; + private volatile SamplingTask myDumpTask; private final File myLogDir = new File(PathManager.getLogPath()); private List myStacktraceCommonPart; @@ -261,8 +261,9 @@ public final class PerformanceWatcher implements Disposable { } private void stopDumping() { - if (myDumpTask != null) { - myDumpTask.stop(); + SamplingTask task = myDumpTask; + if (task != null) { + task.stop(); } } @@ -295,9 +296,11 @@ public final class PerformanceWatcher implements Disposable { } public void edtEventFinished() { - if (myCurrentEDTEventChecker != null) { - if (!myCurrentEDTEventChecker.cancel(false)) { + Future currentChecker = myCurrentEDTEventChecker; + if (currentChecker != null) { + if (!currentChecker.cancel(false)) { long end = System.currentTimeMillis(); + stopDumping(); // stop sampling as early as possible try { myExecutor.submit(() -> edtResponds(end)).get(); }