From e0b382a7dc655bcadb54545364f94d618bc7d03a Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Tue, 16 Jul 2019 15:38:39 +0300 Subject: [PATCH] generate dumps only first 3 minutes to avoid lots of garbage files GitOrigin-RevId: fbd4c461e013b4eb2bfeddd41d6845808fedae68 --- .../intellij/diagnostic/PerformanceWatcher.java | 17 ++++++++++++++--- .../intellij/diagnostic/IdeaFreezeReporter.java | 9 ++++++++- .../util/resources/misc/registry.properties | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java index 10a3b29f7e80..72da962583a0 100644 --- a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java +++ b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java @@ -161,7 +161,7 @@ public class PerformanceWatcher implements Disposable { private static boolean shouldWatch() { return !ApplicationManager.getApplication().isHeadlessEnvironment() && - Registry.intValue("performance.watcher.unresponsive.interval.ms") != 0 && + getUnresponsiveInterval() != 0 && getMaxAttempts() != 0; } @@ -211,8 +211,16 @@ public class PerformanceWatcher implements Disposable { return getSamplingInterval() * getMaxAttempts(); } + static int getUnresponsiveInterval() { + return Registry.intValue("performance.watcher.unresponsive.interval.ms"); + } + + static int getMaxDumpDuration() { + return Registry.intValue("performance.watcher.dump.duration.s") * 1000; + } + private void edtFrozen(long currentMillis) { - if (currentMillis - myLastDumpTime >= Registry.intValue("performance.watcher.unresponsive.interval.ms")) { + if (currentMillis - myLastDumpTime >= getUnresponsiveInterval()) { myLastDumpTime = currentMillis; if (myFreezeStart == 0) { myFreezeStart = myLastEdtAlive; @@ -274,7 +282,7 @@ public class PerformanceWatcher implements Disposable { myCurrentEDTEventChecker.cancel(false); } myCurrentEDTEventChecker = myExecutor - .schedule(() -> edtFrozenPrecise(start), Registry.intValue("performance.watcher.unresponsive.interval.ms"), TimeUnit.MILLISECONDS); + .schedule(() -> edtFrozenPrecise(start), getUnresponsiveInterval(), TimeUnit.MILLISECONDS); } } @@ -303,6 +311,9 @@ public class PerformanceWatcher implements Disposable { private void dumpThreads() { dumpThreads(getFreezeFolderName(myFreezeStart) + "/", false); + if (System.currentTimeMillis() - myFreezeStart > getMaxDumpDuration()) { + stopDumping(); + } } @Nullable diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.java index 2da717032e1e..d582afef0090 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.java @@ -74,9 +74,12 @@ public class IdeaFreezeReporter { } myDumpTask.cancel(); int lengthInSeconds = (int)(durationMs / 1000); + long dumpingDuration = durationMs - PerformanceWatcher.getUnresponsiveInterval(); if (lengthInSeconds > FREEZE_THRESHOLD && // check that we have at least half of the dumps required - myCurrentDumps.size() >= Math.max(3, lengthInSeconds * 500 / Registry.intValue("performance.watcher.unresponsive.interval.ms")) && + (myDumpTask.isValid(dumpingDuration) || + myCurrentDumps.size() >= + Math.max(3, Math.min(PerformanceWatcher.getMaxDumpDuration(), dumpingDuration / 2) / PerformanceWatcher.getDumpInterval())) && !ContainerUtil.isEmpty(myStacktraceCommonPart)) { int size = Math.min(myCurrentDumps.size(), 20); // report up to 20 dumps int step = myCurrentDumps.size() / size; @@ -301,6 +304,10 @@ public class IdeaFreezeReporter { } } + boolean isValid(long dumpingDuration) { + return myThreadInfos.size() >= Math.max(10, Math.min(myMaxDumps, dumpingDuration / myDumpInterval / 2)); + } + void cancel() { myFuture.cancel(false); } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 1737896dd08f..35f5ad70e349 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1524,6 +1524,8 @@ performance.watcher.unresponsive.max.attempts.before.log.description=If the prod performance.watcher.sampling.interval.ms=1000 performance.watcher.sampling.interval.ms.description=If the product is unresponsive for performance.watcher.unresponsive.max.attempts.before.log * performance.watcher.sampling.interval.ms, dump threads every performance.watcher.sampling.interval.ms +performance.watcher.dump.duration.s=180 +performance.watcher.dump.duration.s.description=If the product is unresponsive, dump threads for the specified amount of time performance.watcher.precise=true performance.watcher.precise.restartRequired=true