mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[statistics] IDEA-312044 Get rid of separate background executor in LibraryUsageStatisticsProvider
GitOrigin-RevId: d10955cece16af686320b0264d8cf586e7e161c0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3965986b73
commit
fc1a9c0ea8
+13
-18
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -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<String, Any>, isState: Boolean): CompletableFuture<Void>
|
||||
fun logAsync(group: EventLogGroup, eventId: String, dataProvider: () -> Map<String, Any>?, isState: Boolean): CompletableFuture<Void>
|
||||
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<String, Any>?, isState: Boolean): CompletableFuture<Void> =
|
||||
CompletableFuture.completedFuture(null)
|
||||
override fun computeAsync(computation: (backgroundThreadExecutor: Executor) -> Unit) {}
|
||||
}
|
||||
|
||||
object EmptyEventLogFilesProvider: EventLogFilesProvider {
|
||||
|
||||
+5
-4
@@ -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<String, Any>,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user