From fc1a9c0ea877250df78eef10e43f698fa4f68bd0 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Tue, 31 Jan 2023 17:18:02 +0100 Subject: [PATCH] [statistics] IDEA-312044 Get rid of separate background executor in LibraryUsageStatisticsProvider GitOrigin-RevId: d10955cece16af686320b0264d8cf586e7e161c0 --- .../LibraryUsageStatisticsProvider.kt | 31 ++++++++----------- .../eventLog/StatisticsEventLogger.kt | 3 ++ .../eventLog/StatisticsFileEventLogger.kt | 9 +++--- .../statistic/TestStatisticsEventLogger.kt | 4 +++ 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/java/java-impl/src/com/intellij/internal/statistic/libraryUsage/LibraryUsageStatisticsProvider.kt b/java/java-impl/src/com/intellij/internal/statistic/libraryUsage/LibraryUsageStatisticsProvider.kt index 11f6b1a00734..cdcc0fdd1e2d 100644 --- a/java/java-impl/src/com/intellij/internal/statistic/libraryUsage/LibraryUsageStatisticsProvider.kt +++ b/java/java-impl/src/com/intellij/internal/statistic/libraryUsage/LibraryUsageStatisticsProvider.kt @@ -2,6 +2,7 @@ package com.intellij.internal.statistic.libraryUsage import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer.DaemonListener +import com.intellij.internal.statistic.eventLog.StatisticsEventLogProviderUtil import com.intellij.internal.statistic.libraryJar.findJarVersion import com.intellij.internal.statistic.utils.StatisticsUploadAssistant import com.intellij.openapi.application.ApplicationManager @@ -15,10 +16,8 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiManager -import com.intellij.util.concurrency.AppExecutorUtil import org.jetbrains.annotations.TestOnly import java.util.concurrent.Callable -import java.util.concurrent.ExecutorService internal class LibraryUsageStatisticsProvider(private val project: Project) : DaemonListener { @@ -38,16 +37,19 @@ internal class LibraryUsageStatisticsProvider(private val project: Project) : Da if (processedFilesService.isVisited(vFile)) continue - ReadAction.nonBlocking(Callable { processFile(vFile) }) - .finishOnUiThread(ModalityState.any()) { - if (it != null && processedFilesService.visit(vFile)) { - LibraryUsageStatisticsStorageService.getInstance(project).increaseUsages(it) - } + StatisticsEventLogProviderUtil.getEventLogProvider("FUS").logger + .computeAsync { backgroundExecutor -> + ReadAction.nonBlocking(Callable { processFile(vFile) }) + .finishOnUiThread(ModalityState.any()) { + if (it != null && processedFilesService.visit(vFile)) { + LibraryUsageStatisticsStorageService.getInstance(project).increaseUsages(it) + } + } + .inSmartMode(project) + .expireWith(processedFilesService) + .coalesceBy(vFile, processedFilesService) + .submit(backgroundExecutor) } - .inSmartMode(project) - .expireWith(processedFilesService) - .coalesceBy(vFile, processedFilesService) - .submit(boundedExecutor) } } @@ -95,12 +97,5 @@ internal class LibraryUsageStatisticsProvider(private val project: Project) : Da !isUnitTestMode && !isHeadlessEnvironment && StatisticsUploadAssistant.isSendAllowed() } } - - private val boundedExecutor: ExecutorService by lazy { - AppExecutorUtil.createBoundedApplicationPoolExecutor( - /* name = */ "LibraryUsageStatisticsProvider", - /* maxThreads = */ 1, - ) - } } } diff --git a/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt b/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt index 2b1e9d1ccd58..d786150188dc 100644 --- a/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt +++ b/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt @@ -12,6 +12,7 @@ import org.jetbrains.annotations.ApiStatus import java.io.File import java.util.* import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor import java.util.concurrent.TimeUnit interface StatisticsEventLogger { @@ -32,6 +33,7 @@ interface StatisticsEventLogger { fun logAsync(group: EventLogGroup, eventId: String, data: Map, isState: Boolean): CompletableFuture fun logAsync(group: EventLogGroup, eventId: String, dataProvider: () -> Map?, isState: Boolean): CompletableFuture + fun computeAsync(computation: (backgroundThreadExecutor: Executor) -> Unit) fun getActiveLogFile(): EventLogFile? fun getLogFilesProvider(): EventLogFilesProvider fun cleanup() @@ -158,6 +160,7 @@ internal class EmptyStatisticsEventLogger : StatisticsEventLogger { CompletableFuture.completedFuture(null) override fun logAsync(group: EventLogGroup, eventId: String, dataProvider: () -> Map?, isState: Boolean): CompletableFuture = CompletableFuture.completedFuture(null) + override fun computeAsync(computation: (backgroundThreadExecutor: Executor) -> Unit) {} } object EmptyEventLogFilesProvider: EventLogFilesProvider { diff --git a/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt b/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt index 250ffacc5c22..9b379829125e 100644 --- a/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt +++ b/platform/statistics/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt @@ -10,10 +10,7 @@ import com.intellij.util.concurrency.AppExecutorUtil import com.jetbrains.fus.reporting.model.lion3.LogEvent import com.jetbrains.fus.reporting.model.lion3.LogEventAction import com.jetbrains.fus.reporting.model.lion3.LogEventGroup -import java.util.concurrent.CompletableFuture -import java.util.concurrent.RejectedExecutionException -import java.util.concurrent.ScheduledFuture -import java.util.concurrent.TimeUnit +import java.util.concurrent.* open class StatisticsFileEventLogger(private val recorderId: String, private val sessionId: String, @@ -67,6 +64,10 @@ open class StatisticsFileEventLogger(private val recorderId: String, } } + override fun computeAsync(computation: (backgroundThreadExecutor: Executor) -> Unit) { + computation(logExecutor) + } + override fun logAsync(group: EventLogGroup, eventId: String, data: Map, diff --git a/platform/statistics/test/com/intellij/internal/statistic/TestStatisticsEventLogger.kt b/platform/statistics/test/com/intellij/internal/statistic/TestStatisticsEventLogger.kt index 5f577aa52e97..195cb6be9975 100644 --- a/platform/statistics/test/com/intellij/internal/statistic/TestStatisticsEventLogger.kt +++ b/platform/statistics/test/com/intellij/internal/statistic/TestStatisticsEventLogger.kt @@ -4,6 +4,7 @@ package com.intellij.internal.statistic import com.intellij.internal.statistic.eventLog.* import com.jetbrains.fus.reporting.model.lion3.LogEvent import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor class TestStatisticsEventLogger(private val session: String = "testSession", private val build: String = "999.999", @@ -28,6 +29,9 @@ class TestStatisticsEventLogger(private val session: String = "testSession", return logAsync(group, eventId, data, isState) } + override fun computeAsync(computation: (backgroundThreadExecutor: Executor) -> Unit) { + } + override fun getActiveLogFile(): EventLogFile? = null override fun getLogFilesProvider(): EventLogFilesProvider = EmptyEventLogFilesProvider