From 9606d15f402f48246a91e2be12fae5faffd018f6 Mon Sep 17 00:00:00 2001 From: Liudmila Kornilova Date: Wed, 20 Mar 2024 17:31:16 +0100 Subject: [PATCH] IDEA-345401 Report cancelled health checks GitOrigin-RevId: 2380fa4f35433f12b3a7186f4a02654b48949c52 --- ...ndexableFilesFilterHealthCheckCollector.kt | 28 +++++++++++++++++-- .../ProjectIndexableFilesFilterHealthCheck.kt | 15 ++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/IndexableFilesFilterHealthCheckCollector.kt b/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/IndexableFilesFilterHealthCheckCollector.kt index 0b06f3dbab27..775181838163 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/IndexableFilesFilterHealthCheckCollector.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/IndexableFilesFilterHealthCheckCollector.kt @@ -11,7 +11,7 @@ import com.intellij.openapi.project.Project */ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollector() { private val GROUP = EventLogGroup("indexable.files.filter", - 7, + 8, "FUS", "Collects statistics of ProjectIndexableFilesFilterHealthCheck. " + "See more here: https://youtrack.jetbrains.com/articles/IJPL-A-300/indexable.files.filter") @@ -22,6 +22,7 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto private val attemptNumberInProjectField = EventFields.Int("attempt_number_in_project", "Health check attempt number in a given project. First is 1.") private val successfulAttemptNumberInProjectField = EventFields.Int("successful_attempt_number_in_project", "Finished (not-cancelled) health check attempt number in a given project. First is 1.") private val durationMsFiled = EventFields.Int("duration_ms", "Health check duration in milliseconds") + private val cancelledAttemptNumberInProjectField = EventFields.Int("cancelled_attempt_number_in_project", "Cancelled health check attempt number in a given project. First is 1.") private val nonIndexableFilesInFilterField = EventFields.Int("non_indexable_files_in_filter_count") private val indexableFilesNotInFilterField = EventFields.Int("indexable_files_not_in_filter_count") @@ -40,7 +41,16 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto "indexable_files_filter_health_check_started", filterNameField, attemptNumberInProjectField, - description = "Even which happens every time health check is started." + description = "Event which happens every time health check is started." + ) + + private val indexableFilesFilterHealthCheckCancelled = GROUP.registerVarargEvent( + "indexable_files_filter_health_check_cancelled", + description = "Event which happens every time health check is cancelled e.g. because scanning was in progress.", + filterNameField, + attemptNumberInProjectField, + cancelledAttemptNumberInProjectField, + durationMsFiled, ) fun reportIndexableFilesFilterHealthcheckStarted(project: Project, @@ -72,6 +82,20 @@ internal object IndexableFilesFilterHealthCheckCollector : CounterUsagesCollecto ) } + fun reportIndexableFilesFilterHealthcheckCancelled(project: Project, + filter: ProjectIndexableFilesFilter, + attemptNumber: Int, + cancelledAttemptNumber: Int, + durationMs: Int) { + indexableFilesFilterHealthCheckCancelled.log( + project, + filterNameField.with(getFilterName(filter)), + attemptNumberInProjectField.with(attemptNumber), + cancelledAttemptNumberInProjectField.with(cancelledAttemptNumber), + durationMsFiled.with(durationMs), + ) + } + private fun getFilterName(filter: ProjectIndexableFilesFilter): String? { return when (filter) { is CachingProjectIndexableFilesFilter -> "caching" diff --git a/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/ProjectIndexableFilesFilterHealthCheck.kt b/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/ProjectIndexableFilesFilterHealthCheck.kt index c2ba9b4c9c23..9d8d69e4e12b 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/ProjectIndexableFilesFilterHealthCheck.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/projectFilter/ProjectIndexableFilesFilterHealthCheck.kt @@ -59,6 +59,7 @@ private class ProjectIndexableFilesFilterHealthCheckStarter : ProjectActivity { class ProjectIndexableFilesFilterHealthCheck(private val project: Project, private val coroutineScope: CoroutineScope) { private val isRunning = AtomicBoolean() private val attemptsCount = AtomicInteger() + private val cancelledAttemptsCount = AtomicInteger() private val successfulAttemptsCount = AtomicInteger() fun launchHealthCheck() { @@ -99,9 +100,19 @@ class ProjectIndexableFilesFilterHealthCheck(private val project: Project, priva val startTime = System.currentTimeMillis() Observation.awaitConfiguration(project) // wait for project import IDEA-348501 - val (nonIndexableFilesInFilter, indexableFilesNotInFilter) = smartReadAction(project) { + val res = smartReadAction(project) { runHealthCheck(project, filter) - } ?: return + } + if (res == null) { + IndexableFilesFilterHealthCheckCollector.reportIndexableFilesFilterHealthcheckCancelled( + project, + filter, + attemptNumber, + cancelledAttemptsCount.incrementAndGet(), + (System.currentTimeMillis() - startTime).toInt()) + return + } + val (nonIndexableFilesInFilter, indexableFilesNotInFilter) = res nonIndexableFilesInFilter.fix(filter) indexableFilesNotInFilter.fix(filter)