From 86e2b170554441682020f3aae5d1339a89c4bf61 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 23 Jul 2019 14:56:24 +0300 Subject: [PATCH] show task title as a thread name for long-running tasks for easier-to-read threaddumps GitOrigin-RevId: 4ad918f549c5c481b3d4236974a8f0d23a35cc2f --- .../progress/impl/CoreProgressManager.java | 3 ++- .../application/impl/ApplicationImpl.java | 4 ++-- .../openapi/project/CacheUpdateRunner.java | 21 +++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/progress/impl/CoreProgressManager.java b/platform/core-impl/src/com/intellij/openapi/progress/impl/CoreProgressManager.java index 9db62b242327..69c341d916e7 100644 --- a/platform/core-impl/src/com/intellij/openapi/progress/impl/CoreProgressManager.java +++ b/platform/core-impl/src/com/intellij/openapi/progress/impl/CoreProgressManager.java @@ -18,6 +18,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.ex.ProgressIndicatorEx; +import com.intellij.util.ConcurrencyUtil; import com.intellij.util.ExceptionUtil; import com.intellij.util.ObjectUtils; import com.intellij.util.concurrency.AppExecutorUtil; @@ -405,7 +406,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable { final long start = System.currentTimeMillis(); try { - runProcess(process, progressIndicator); + ConcurrencyUtil.runUnderThreadName(task.getTitle(), ()-> runProcess(process, progressIndicator)); } catch (ProcessCanceledException e) { processCanceled = true; diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 4500980a9291..482cda6b880e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -550,7 +550,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App final AtomicBoolean threadStarted = new AtomicBoolean(); //noinspection SSBasedInspection SwingUtilities.invokeLater(() -> { - executeOnPooledThread(() -> { + executeOnPooledThread(ConcurrencyUtil.underThreadNameRunnable(progressTitle, () -> { try { ProgressManager.getInstance().runProcess(process, progress); } @@ -562,7 +562,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App progress.cancel(); throw e; } - }); + })); threadStarted.set(true); }); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java index ab36960f084d..f065a6051730 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java @@ -18,6 +18,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ConcurrencyUtil; import com.intellij.util.Consumer; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -114,16 +115,16 @@ public class CacheUpdateRunner { try { int threadsCount = indexingThreadCount(); if (threadsCount == 1 || application.isWriteAccessAllowed()) { - Runnable process = new MyRunnable(innerIndicator, suspendableIndicator, queue, isFinished, progressUpdater, project, fileProcessor); + Runnable process = createRunnable(project, queue, progressUpdater, suspendableIndicator, innerIndicator, isFinished, fileProcessor); ProgressManager.getInstance().runProcess(process, innerIndicator); } else { AtomicBoolean[] finishedRefs = new AtomicBoolean[threadsCount]; Future[] futures = new Future[threadsCount]; for (int i = 0; i < threadsCount; i++) { - AtomicBoolean ref = new AtomicBoolean(); - finishedRefs[i] = ref; - Runnable process = new MyRunnable(innerIndicator, suspendableIndicator, queue, ref, progressUpdater, project, fileProcessor); + AtomicBoolean localFinished = new AtomicBoolean(); + finishedRefs[i] = localFinished; + Runnable process = createRunnable(project, queue, progressUpdater, suspendableIndicator, innerIndicator, localFinished, fileProcessor); futures[i] = application.executeOnPooledThread(process); } isFinished.set(waitForAll(finishedRefs, futures)); @@ -136,6 +137,18 @@ public class CacheUpdateRunner { return isFinished.get(); } + @NotNull + private static Runnable createRunnable(@NotNull Project project, + @NotNull FileContentQueue queue, + @NotNull ProgressUpdater progressUpdater, + @NotNull ProgressIndicator suspendableIndicator, + @NotNull ProgressIndicatorBase innerIndicator, + @NotNull AtomicBoolean isFinished, + @NotNull Consumer fileProcessor) { + return ConcurrencyUtil.underThreadNameRunnable("Indexing", + new MyRunnable(innerIndicator, suspendableIndicator, queue, isFinished, progressUpdater, project, fileProcessor)); + } + public static int indexingThreadCount() { int threadsCount = Registry.intValue("caches.indexerThreadsCount"); if (threadsCount <= 0) {